Repository navigation
fix(metrics): omit span_id when no span is active - #2403
Merged
Merged
Conversation
Metrics took their span ID from the scope's trace context, which falls back to the propagation context when no span is active. That span ID is random and belongs to no span, so the metric pointed at a span that does not exist. Only set the span ID when a span is active or an external propagation context provides one, and leave it out of the envelope item otherwise. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Litarnus
force-pushed
the
fix/metric-span-id-without-active-span
branch
from
November 19, 2026 15:34
54a8af4 to
dbd3d4a
Compare
2 tasks done
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
A metric recorded without an active span carried a
span_idthat belongs to no span.MetricsAggregatorread it from the scope's trace context, which falls back to the propagation context's random span ID when no span is active.Metrics now only get a
span_idwhen a span is active or an external propagation context provides one. Otherwisespan_idis left out of the envelope item. The trace ID is unchanged.This matches the metrics spec (
span_idis optional and is the span that was active when the metric was emitted) and what sentry-python and sentry-javascript do.Behaviour change:
Metric::getSpanId()now returns?SpanId. Abefore_send_metriccallback that calls it without a span active getsnullinstead of a synthetic ID.In the serialized item
span_idnow comes afterattributes; key order has no meaning for ingestion.Issues
None.
🤖 Generated with Claude Code