open-telemetry / open-telemetry/opentelemetry-ruby
Fix OTLP Metrics Exporter error when attributes is `nil`
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 606
- Forks
- 301
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 42
Description
During testing, I've run into issues with OTLP export when an instrument is recorded without attributes.
For example, when record is called on a histogram without attributes: histogram.record(123)
This error is logged:
E, [2024-08-01T13:41:56.081704 #86303] ERROR -- : OpenTelemetry error: unexpected error in OTLP::MetricsExporter#encode - undefined method map' for nil`
Which comes from this LOC because hdp.attributes is nil.
I haven't been able to track down a specific line in the spec that explains whether attributes must be present, but my hunch is that they're optional.
After this discussion, @xuan-cao-swi and I think the best approach would be to update update the default value of the attributes argument on the record methods to be an empty hash.
Looking at the code, it seems like histogram and up_down_counter need to be fixed, but there may be other areas that need updates as well.
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 exporter/otlp-metrics/lib/opentelemetry/exporter/otlp/metrics_exporter.rb line 274 and trace the histogram and up_down_counter record methods mentioned in the issue. Reproduce the histogram.record(123) case, inspect other record methods for the same default, and verify OTLP export no longer logs the nil map error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100