-
-
Notifications
You must be signed in to change notification settings - Fork 226
feat: Add support for w3c trace parent headers for outgoing requests #4661
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
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aaaf007
feat: Add support for w3c trace parent headers for outgoing requests
markushi 0a0945a
Add changelog
markushi ad20f7e
Verify & bindable options
bitsandfoxes ff02acb
Add more tests
markushi 1d25c56
Update src/Sentry/SentryOptions.cs
markushi 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
Next
Next commit
feat: Add support for w3c trace parent headers for outgoing requests
- Loading branch information
commit aaaf007e38242daa30e90708431b7fd67197b872
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -995,6 +995,18 @@ public IList<StringOrRegex> TracePropagationTargets | |
| set => _tracePropagationTargets = value.WithConfigBinding(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Whether to send W3C Trace Context traceparent headers in outgoing HTTP requests for distributed tracing. | ||
| /// When enabled, the SDK will send the <c>traceparent</c> header in addition to the <c>sentry-trace</c> header | ||
| /// for requests matching <see cref="TracePropagationTargets"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The default value is <c>false</c>. Set to <c>true</c> to enable W3C Trace Context propagation | ||
| /// for interoperability with services that support OpenTelemetry standards. | ||
| /// </remarks> | ||
| /// <seealso href="https://develop.sentry.dev/sdk/telemetry/traces/#propagatetraceparent"/> | ||
|
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 should probably document this in a more "SDK User" friendly format... I added #4663 as a follow up for this. |
||
| public bool PropagateTraceparent { get; set; } = false; | ||
markushi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| internal ITransactionProfilerFactory? TransactionProfilerFactory { get; set; } | ||
|
|
||
| private StackTraceMode? _stackTraceMode; | ||
|
|
||
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,39 @@ | ||
| namespace Sentry; | ||
|
|
||
| /// <summary> | ||
| /// W3C Trace Context traceparent header. | ||
| /// </summary> | ||
| public class W3CTraceparentHeader | ||
| { | ||
| internal const string HttpHeaderName = "traceparent"; | ||
jamescrosswell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Trace ID. | ||
| /// </summary> | ||
| public SentryId TraceId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Span ID. | ||
| /// </summary> | ||
| public SpanId SpanId { get; } | ||
|
|
||
| /// <summary> | ||
| /// Whether the trace is sampled. | ||
| /// </summary> | ||
| public bool? IsSampled { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes an instance of <see cref="W3CTraceparentHeader"/>. | ||
| /// </summary> | ||
| public W3CTraceparentHeader(SentryId traceId, SpanId spanId, bool? isSampled) | ||
| { | ||
| TraceId = traceId; | ||
| SpanId = spanId; | ||
| IsSampled = isSampled; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override string ToString() => IsSampled is { } isSampled | ||
| ? $"00-{TraceId}-{SpanId}-{(isSampled ? "01" : "00")}" | ||
| : $"00-{TraceId}-{SpanId}-00"; | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| namespace Sentry.Tests.Protocol; | ||
|
|
||
| public class W3CTraceparentHeaderTests | ||
| { | ||
| [Fact] | ||
| public void ToString_WithSampledTrue_Works() | ||
| { | ||
| // Arrange | ||
| var traceId = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"); | ||
| var spanId = SpanId.Parse("1000000000000000"); | ||
| var header = new W3CTraceparentHeader(traceId, spanId, true); | ||
|
|
||
| // Act | ||
| var result = header.ToString(); | ||
|
|
||
| // Assert | ||
| result.Should().Be("00-75302ac48a024bde9a3b3734a82e36c8-1000000000000000-01"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToString_WithSampledFalse_Works() | ||
| { | ||
| // Arrange | ||
| var traceId = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"); | ||
| var spanId = SpanId.Parse("1000000000000000"); | ||
| var header = new W3CTraceparentHeader(traceId, spanId, false); | ||
|
|
||
| // Act | ||
| var result = header.ToString(); | ||
|
|
||
| // Assert | ||
| result.Should().Be("00-75302ac48a024bde9a3b3734a82e36c8-1000000000000000-00"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToString_WithoutSampled_DefaultsToFalse() | ||
| { | ||
| // Arrange | ||
| var traceId = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"); | ||
| var spanId = SpanId.Parse("1000000000000000"); | ||
| var header = new W3CTraceparentHeader(traceId, spanId, null); | ||
|
|
||
| // Act | ||
| var result = header.ToString(); | ||
|
|
||
| // Assert | ||
| result.Should().Be("00-75302ac48a024bde9a3b3734a82e36c8-1000000000000000-00"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_StoresProperties() | ||
| { | ||
| // Arrange | ||
| var traceId = SentryId.Parse("75302ac48a024bde9a3b3734a82e36c8"); | ||
| var spanId = SpanId.Parse("1000000000000000"); | ||
| var isSampled = true; | ||
|
|
||
| // Act | ||
| var header = new W3CTraceparentHeader(traceId, spanId, isSampled); | ||
|
|
||
| // Assert | ||
| header.TraceId.Should().Be(traceId); | ||
| header.SpanId.Should().Be(spanId); | ||
| header.IsSampled.Should().Be(isSampled); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void HttpHeaderName_IsCorrect() | ||
| { | ||
| // Act & Assert | ||
| W3CTraceparentHeader.HttpHeaderName.Should().Be("traceparent"); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.