-
-
Notifications
You must be signed in to change notification settings - Fork 294
ref(dart): instrumentation span for http dio #3493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
buenaflor
merged 12 commits into
ref/instrumentation-span
from
ref/instrumentation-span-http-dio
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dd612e5
ref(tracing-instrumentation): migrate http and dio to instrumentation…
buenaflor 4b0a62a
ref(dio): migrate SentryTransformer to instrumentation span
buenaflor 956c25f
ref(tracing): rename applyToInstrumentationSpan to applyToSpan
buenaflor e7d7e2c
chore(tests): add mock_span import to lifecycle tests
buenaflor c86419c
feat(tests): add MockSpan class for testing Sentry spans
buenaflor 40e5c6a
ref(tracing): remove commented code for extracting ISentrySpan
buenaflor 2f2de02
ref(tracing): enhance tracing header handling with InstrumentationSpan
buenaflor a59cde3
ref(tracing): rename addTracingHeadersFromInstrumentationSpan to addT…
buenaflor 38071ec
ref(baggage): remove logging callback from SentryBaggage
buenaflor 3ea6032
Update
buenaflor 165f883
ref(baggage): simplify toBaggage method by removing logging callback
buenaflor 3abbfff
Update
buenaflor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,11 @@ SentryTraceHeader generateSentryTraceHeader( | |
| return SentryTraceHeader(traceId, spanId, sampled: sampled); | ||
| } | ||
|
|
||
| void addTracingHeadersToHttpHeader(Map<String, dynamic> headers, Hub hub, | ||
| {ISentrySpan? span}) { | ||
| void addTracingHeadersToHttpHeader( | ||
| Map<String, dynamic> headers, | ||
| Hub hub, { | ||
| InstrumentationSpan? span, | ||
| }) { | ||
| if (span != null) { | ||
| if (hub.options.propagateTraceparent) { | ||
| addW3CHeaderFromSpan(span, headers); | ||
|
|
@@ -17,14 +20,13 @@ void addTracingHeadersToHttpHeader(Map<String, dynamic> headers, Hub hub, | |
| addBaggageHeaderFromSpan( | ||
| span, | ||
| headers, | ||
| log: hub.options.log, | ||
| ); | ||
| } else { | ||
| if (hub.options.propagateTraceparent) { | ||
| addW3CHeaderFromScope(hub.scope, headers); | ||
| } | ||
| addSentryTraceHeaderFromScope(hub.scope, headers); | ||
| addBaggageHeaderFromScope(hub.scope, headers, log: hub.options.log); | ||
| addBaggageHeaderFromScope(hub.scope, headers); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -35,7 +37,7 @@ void addSentryTraceHeaderFromScope(Scope scope, Map<String, dynamic> headers) { | |
| } | ||
|
|
||
| void addSentryTraceHeaderFromSpan( | ||
| ISentrySpan span, Map<String, dynamic> headers) { | ||
| InstrumentationSpan span, Map<String, dynamic> headers) { | ||
| final traceHeader = span.toSentryTrace(); | ||
| headers[traceHeader.name] = traceHeader.value; | ||
| } | ||
|
|
@@ -45,7 +47,8 @@ void addSentryTraceHeader( | |
| headers[traceHeader.name] = traceHeader.value; | ||
| } | ||
|
|
||
| void addW3CHeaderFromSpan(ISentrySpan span, Map<String, dynamic> headers) { | ||
| void addW3CHeaderFromSpan( | ||
| InstrumentationSpan span, Map<String, dynamic> headers) { | ||
| final traceHeader = span.toSentryTrace(); | ||
| _addW3CHeaderFromSentryTrace(traceHeader, headers); | ||
| } | ||
|
|
@@ -67,42 +70,30 @@ String formatAsW3CHeader(SentryTraceHeader traceHeader) { | |
| return '00-${traceHeader.traceId}-${traceHeader.spanId}-$sampledBit'; | ||
| } | ||
|
|
||
| void addBaggageHeaderFromScope( | ||
| Scope scope, | ||
| Map<String, dynamic> headers, { | ||
| SdkLogCallback? log, | ||
| }) { | ||
| void addBaggageHeaderFromScope(Scope scope, Map<String, dynamic> headers) { | ||
| final baggageHeader = scope.propagationContext.toBaggageHeader(); | ||
| if (baggageHeader != null) { | ||
| addBaggageHeader(baggageHeader, headers, log: log); | ||
| addBaggageHeader(baggageHeader, headers); | ||
| } | ||
| } | ||
|
|
||
| void addBaggageHeaderFromSpan( | ||
| ISentrySpan span, | ||
| Map<String, dynamic> headers, { | ||
| SdkLogCallback? log, | ||
| }) { | ||
| InstrumentationSpan span, Map<String, dynamic> headers) { | ||
| final baggage = span.toBaggageHeader(); | ||
| if (baggage != null) { | ||
| addBaggageHeader(baggage, headers, log: log); | ||
| addBaggageHeader(baggage, headers); | ||
| } | ||
| } | ||
|
|
||
| void addBaggageHeader( | ||
| SentryBaggageHeader baggage, | ||
| Map<String, dynamic> headers, { | ||
| SdkLogCallback? log, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need tha passed log anymore? What was it used for, are we now missing log infos? |
||
| }) { | ||
| SentryBaggageHeader baggage, Map<String, dynamic> headers) { | ||
| final currentValue = headers[baggage.name] as String? ?? ''; | ||
|
|
||
| final currentBaggage = SentryBaggage.fromHeader( | ||
| currentValue, | ||
| log: log, | ||
| ); | ||
| final sentryBaggage = SentryBaggage.fromHeader( | ||
| baggage.value, | ||
| log: log, | ||
| ); | ||
|
|
||
| // overwrite sentry's keys https://develop.sentry.dev/sdk/performance/dynamic-sampling-context/#baggage | ||
|
|
@@ -114,7 +105,7 @@ void addBaggageHeader( | |
| ...sentryBaggage.keyValues, | ||
| }; | ||
|
|
||
| final newBaggage = SentryBaggage(mergedBaggage, log: log); | ||
| final newBaggage = SentryBaggage(mergedBaggage); | ||
|
|
||
| headers[baggage.name] = newBaggage.toHeaderString(); | ||
| } | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import 'package:mockito/mockito.dart'; | ||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| class MockSpan extends Mock implements SentrySpan { | ||
| final SentrySpanContext _context = SentrySpanContext(operation: 'test'); | ||
| @override | ||
| SentrySpanContext get context => _context; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, using static internal logger, ignore my other comment.