Repository navigation
fix(telemetry): avoid duplicate span export under auto-instrumentation wrapper - #404
Draft
jeanscherf wants to merge 1 commit into
Draft
jeanscherf wants to merge 1 commit into
jeanscherf wants to merge 1 commit into
Conversation
…n wrapper When an OTel auto-instrumentation agent (for example the OpenTelemetry Operator's inject-python) is active, it installs a TracerProvider that already exports spans via OTLP. auto_instrument() then adds the SDK's own Traceloop exporter to the same provider, so every span is exported twice. The log and metric providers already refuse a second exporter in this situation; the trace path did not. Drop the wrapper's span exporter when the SDK exporter is present, consolidating on the SDK exporter (which also applies GenAI attribute normalization). No-op when the SDK exporter is absent or no wrapper is present, so once the auto-instrumentation layer is retired this leaves the SDK exporter as the only one. Adds unit tests for both branches.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When an OpenTelemetry auto-instrumentation agent (for example the OTel Operator's
inject-python) is active, it installs aTracerProviderthat already exports spans via OTLP.auto_instrument()then adds the SDK's own Traceloop span exporter to that same provider, so every span is exported twice. The log and metric providers already avoid adding a second exporter when a provider is pre-installed; the trace path did not.This adds
_drop_wrapper_span_exporter_if_sdk_exports()(called fromauto_instrument()right after the existing resource-attr merge). When the pre-installed provider carries thetelemetry.auto.versionmarker and both the wrapper's exporter and the SDK's Traceloop exporter are present, it removes the wrapper's exporting span processor and keeps the SDK's (which also applies GenAI attribute normalization). It is a no-op when the SDK exporter is absent or no wrapper is present.Related Issue
No linked public issue (found during internal observability work).
Type of Change
How to Test
TracerProvider(resource markertelemetry.auto.version), callauto_instrument()and confirm the active provider ends with a single exporting span processor (the SDK's), not two.pytest tests/core/unit/telemetry/test_auto_instrument.py -k DropWrapper.auto_instrument()leaves the SDK exporter in place.Checklist
Additional Notes
Draft, pending two decisions:
auto_instrument()goes from two exporting processors to one; pure-SDK path stays at one). Not yet validated on a deployed service.Implementation note: the guard reads
TracerProvider._active_span_processorbecause the OTel SDK exposes no public API to remove a span processor; this mirrors the existing_merge_resource_attrs_into_active_provider_if_wrapper_installedhelper, which already mutates provider internals.Recommend running
/review-prand/security-reviewon this PR before marking it ready.