Fix OTLP Metrics Exporter error when attributes is `nil`
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.
I'm still hitting this error when attributes is nil. I see that this issue was closed but the offending line of code is still there in the main as of current main HEAD, 0bee6a3e0b6a38cdd564c49dcd1323d56b2e61e7. I'm wondering if this was closed erroneously and should be reopened.
Hi @akahn, thanks for bringing this to our attention. In #1683, we believed we had fixed the problem by setting the default value of attributes for the instruments to an empty hash, but it seems like there's a deeper issue. I'll reopen!
Are you hitting the problem with histograms specifically? Have you seen this with other instruments?
👋 This issue has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this issue will be closed eventually by the stale bot.