opentelemetry-go
opentelemetry-go copied to clipboard
[POC] Make scope attributes as identifying for Tracer, Meter, Logger
Spike for https://github.com/open-telemetry/opentelemetry-specification/pull/4161 (and https://github.com/open-telemetry/opentelemetry-go/issues/3368)
API changes:
- Add
Attributes attribute.Setfield toinstrumentation.Scope,logtest.ScopeRecords
Behavioral changes:
- The
Tracer,Meter,Loggerreturned by the providers now handle scope attribute; the value is assigned by the SDK and it is seen as one of the identifying fields - OTLP ans STDOUT exporters set the instrumentation scope attributes
Remarks:
Zipkin exporter DOES NOT set the instrumentation scope attributes as it is not required by the spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md. This may be a bug or missing feature in the spec.
Prometheus exporter is REQUIRED to set the instrumentation scope attributes on the otel_scope_info metric: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/prometheus.md and https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md#instrumentation-scope-1:
Scope attributes MUST also be added as labels following the rules described in the Metric Attributes section below.
I have not implemented this this as I do not feel it is needed for this PoC. It would probably require updating the createScopeInfoMetric implementation:
https://github.com/open-telemetry/opentelemetry-go/blob/97ee172f1f9af2abb8db7f17567ecdf23779103d/exporters/prometheus/exporter.go#L353-L357
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 84.6%. Comparing base (
078b2dd) to head (ea5fbd9). Report is 243 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #5806 +/- ##
=====================================
Coverage 84.6% 84.6%
=====================================
Files 272 272
Lines 22839 22858 +19
=====================================
+ Hits 19325 19344 +19
Misses 3170 3170
Partials 344 344
@open-telemetry/go-maintainers, can you make a rough review if it looks like a good way to implement https://github.com/open-telemetry/opentelemetry-specification/pull/4161? This PR is done in a PoC manner and it lacks unit tests - I just added few more assertions to validate the implementation.
I plan to make https://github.com/open-telemetry/opentelemetry-specification/pull/4161 as "ready to merge" tomorrow.
This looks in line with our prior attempt: https://github.com/open-telemetry/opentelemetry-go/pull/3131
Looks reasonable to me. Prometheus exporter is only supposed to add those attributes to the otel_scope_info metric, btw.
Prometheus exporter is only supposed to add those attributes to the otel_scope_info metric, btw.
I think this is what I described. If not then please update my description ๐
This look nice. Does it impact the benchmarks for tracer/meter/logger retrieval?
This look nice. Does it impact the benchmarks for tracer/meter/logger retrieval?
It does (because there is a bigger memory footprint) but IMO not significantly. E.g.
pkg: go.opentelemetry.io/otel/sdk/log
cpu: Intel(R) Core(TM) i9-10885H CPU @ 2.40GHz
โ old.txt โ new.txt โ
โ sec/op โ sec/op vs base โ
LoggerProviderLogger-16 639.8n ยฑ 14% 738.4n ยฑ 9% +15.42% (p=0.009 n=10)
โ old.txt โ new.txt โ
โ B/op โ B/op vs base โ
LoggerProviderLogger-16 349.0 ยฑ 19% 463.0 ยฑ 26% +32.66% (p=0.009 n=10)
โ old.txt โ new.txt โ
โ allocs/op โ allocs/op vs base โ
LoggerProviderLogger-16 1.000 ยฑ 0% 1.000 ยฑ 0% ~ (p=1.000 n=10) ยน
Looks reasonable to me. Prometheus exporter is only supposed to add those attributes to the otel_scope_info metric, btw.
@dashpole, PTAL ea10e400c