open-telemetry / open-telemetry/opentelemetry-ruby
Unexpected behavior for log record attributes with symbols for keys
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 606
- Forks
- 301
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 42
Description
When a log record attribute has a Symbol for a key, the following OpenTelemetry error log message is output:
ERROR -- : OpenTelemetry error: invalid log record attribute key type Symbol on record: 'Thuja plicata with symbol attribute key'
Where Thuja plicata is the log body, and :cedar is the attribute key.
The expectation is that all attribute keys are Strings. This is the same as the expectation for attributes on stable Ruby OTel signals, like Spans/SpanEvents for Traces.
Despite this warning, the attribute is passed along to the exporter anyway, and it is successfully sent over OTLP.
For example (source):
OpenTelemetry Ruby logger SDK
# Use your Logger to emit a log record
logger.on_emit(
timestamp: Time.now,
severity_text: 'INFO',
body: 'Thuja plicata with symbol attribute key',
attributes: { cedar: true },
)
Shell output from running the code above
[4:10](https://cloud-native.slack.com/archives/C01NWKKMKMY/p1734307839893059?thread_ts=1734228402.085199&cid=C01NWKKMKMY)
$ pwd
/Users/wsmoak/Projects/opentelemetry-ruby/examples/logs_sdk
wsmoak logs_sdk $ ruby logs_otlp.rb
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/..
E, [2024-12-15T19:10:02.812695 #81798] ERROR -- : OpenTelemetry error: invalid log record attribute key type Symbol on record: 'Thuja plicata with symbol attribute key'
Collector output from running the code above
$ cat collector-output.txt | grep -3 Thuja
--
Timestamp: 2024-12-16 00:10:02.81267 +0000 UTC
SeverityText: INFO
SeverityNumber: Unspecified(0)
Body: Str(Thuja plicata with symbol attribute key)
Attributes:
-> cedar: Bool(true)
Trace ID:
Questions / Next Steps
- Why are symbols forbidden as keys on trace-related attributes?
- Should this reasoning extend to logs?
- If the reasoning should extend to logs, update the code to reject attributes with symbols as keys and update the error message to state that strings are required
- If the reasoning should not extend to logs, remove the error message
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Logger SDK's logger.on_emit entry point and review how log record attributes are validated before export, comparing the stated behavior with stable Ruby OTel signal attributes. Resolve whether symbol keys should be rejected for logs; done means either rejecting them with an error that states strings are required, or removing the warning if symbols are valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100