Skip to content

Commit efdf50b

Browse files
Merge branch 'main' into feat/4255/bump-sdk-version
2 parents 557dc48 + a73789a commit efdf50b

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
uses: ./.github/actions/environment
3636

3737
- name: Initialize CodeQL
38-
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # pin@v2
38+
uses: github/codeql-action/init@fca7ace96b7d713c7035871441bd52efbe39e27e # pin@v2
3939
with:
4040
languages: csharp
4141

@@ -49,6 +49,6 @@ jobs:
4949
run: dotnet build Sentry-CI-CodeQL.slnf --no-restore --nologo
5050

5151
- name: Perform CodeQL Analysis
52-
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # pin@v2
52+
uses: github/codeql-action/analyze@fca7ace96b7d713c7035871441bd52efbe39e27e # pin@v2
5353
with:
5454
category: '/language:csharp'

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- The HTTP instrumentation uses the span created for the outgoing request in the sentry-trace header, fixing the parent-child relationship between client and server ([#4264](https://github.com/getsentry/sentry-dotnet/pull/4264))
8+
59
### Dependencies
610

711
- Bump the version of the .NET SDK that we use from 9.0.203 to 9.0.300 ([#4259](https://github.com/getsentry/sentry-dotnet/pull/4259))
812
- Note that this also required we bump various Java dependencies (since version 9.0.300 of the Android workload requires newer versions of the these)
913
- See https://docs.sentry.io/platforms/dotnet/troubleshooting/#detected-package-version-outside-of-dependency-constraint if you see NU1605, NU1608 and/or NU1107 warnings after upgrading
14+
- Bump Native SDK from v0.8.5 to v0.9.0 ([#4260](https://github.com/getsentry/sentry-dotnet/pull/4260))
15+
- [changelog](https://github.com/getsentry/sentry-native/blob/master/CHANGELOG.md#090)
16+
- [diff](https://github.com/getsentry/sentry-native/compare/0.8.5...0.9.0)
1017

1118
## 5.10.0
1219

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<VersionPrefix>5.10.0</VersionPrefix>
4+
<VersionPrefix>5.11.0-alpha.1</VersionPrefix>
55
<LangVersion>13</LangVersion>
66
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

src/Sentry/SentryMessageHandler.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected override async Task<HttpResponseMessage> SendAsync(
8686
var span = ProcessRequest(request, method, url);
8787
try
8888
{
89-
PropagateTraceHeaders(request, url);
89+
PropagateTraceHeaders(request, url, span);
9090
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
9191
HandleResponse(response, span, method, url);
9292
return response;
@@ -108,7 +108,7 @@ protected override HttpResponseMessage Send(HttpRequestMessage request, Cancella
108108
var span = ProcessRequest(request, method, url);
109109
try
110110
{
111-
PropagateTraceHeaders(request, url);
111+
PropagateTraceHeaders(request, url, span);
112112
var response = base.Send(request, cancellationToken);
113113
HandleResponse(response, span, method, url);
114114
return response;
@@ -121,7 +121,7 @@ protected override HttpResponseMessage Send(HttpRequestMessage request, Cancella
121121
}
122122
#endif
123123

124-
private void PropagateTraceHeaders(HttpRequestMessage request, string url)
124+
private void PropagateTraceHeaders(HttpRequestMessage request, string url, ISpan? parentSpan)
125125
{
126126
// Assign a default inner handler for convenience the first time this is used.
127127
// We can't do this in a constructor, or it will throw when used with HttpMessageHandlerBuilderFilter.
@@ -135,15 +135,17 @@ private void PropagateTraceHeaders(HttpRequestMessage request, string url)
135135

136136
if (_options?.TracePropagationTargets.MatchesSubstringOrRegex(url) is true or null)
137137
{
138-
AddSentryTraceHeader(request);
138+
AddSentryTraceHeader(request, parentSpan);
139139
AddBaggageHeader(request);
140140
}
141141
}
142142

143-
private void AddSentryTraceHeader(HttpRequestMessage request)
143+
private void AddSentryTraceHeader(HttpRequestMessage request, ISpan? parentSpan)
144144
{
145145
// Set trace header if it hasn't already been set
146-
if (!request.Headers.Contains(SentryTraceHeader.HttpHeaderName) && _hub.GetTraceHeader() is { } traceHeader)
146+
if (!request.Headers.Contains(SentryTraceHeader.HttpHeaderName) &&
147+
// Use the span created by this integration as parent, instead of its own parent
148+
(parentSpan?.GetTraceHeader() ?? _hub.GetTraceHeader()) is { } traceHeader)
147149
{
148150
request.Headers.Add(SentryTraceHeader.HttpHeaderName, traceHeader.ToString());
149151
}

test/Sentry.Tests/SentryHttpMessageHandlerTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,40 @@ public async Task SendAsync_SentryTraceHeaderNotSet_SetsHeader_ByDefault()
3333
string.Concat(h.Value) == "75302ac48a024bde9a3b3734a82e36c8-1000000000000000-0");
3434
}
3535

36+
[Fact]
37+
public async Task SendAsync_SentryTraceHeaderNotSet_SetsHeader_ToCorrectParent()
38+
{
39+
// Arrange
40+
var hub = Substitute.For<IHub>();
41+
42+
const string rootTraceHeader = "75302ac48a024bde9a3b3734a82e36c8-1000000000000000-1";
43+
hub.GetTraceHeader().ReturnsForAnyArgs(
44+
SentryTraceHeader.Parse(rootTraceHeader));
45+
var parentSpan = Substitute.For<ISpan>();
46+
parentSpan.GetTraceHeader().ReturnsForAnyArgs(
47+
SentryTraceHeader.Parse(rootTraceHeader));
48+
hub.GetSpan().ReturnsForAnyArgs(parentSpan);
49+
const string httpSpanTraceHeader = "75302ac48a024bde9a3b3734a82e36c8-2000000000000000-1";
50+
var httpSpan = Substitute.For<ISpan>();
51+
httpSpan.GetTraceHeader().ReturnsForAnyArgs(
52+
SentryTraceHeader.Parse(httpSpanTraceHeader));
53+
parentSpan.StartChild(Arg.Any<string>()).ReturnsForAnyArgs(httpSpan);
54+
55+
using var innerHandler = new RecordingHttpMessageHandler(new FakeHttpMessageHandler());
56+
using var sentryHandler = new SentryHttpMessageHandler(innerHandler, hub);
57+
using var client = new HttpClient(sentryHandler);
58+
59+
// Act
60+
await client.GetAsync("https://localhost/");
61+
62+
using var request = innerHandler.GetRequests().Single();
63+
64+
// Assert
65+
request.Headers.Should().Contain(h =>
66+
h.Key == "sentry-trace" &&
67+
string.Concat(h.Value) == httpSpanTraceHeader);
68+
}
69+
3670
[Fact]
3771
public async Task SendAsync_SentryTraceHeaderNotSet_SetsHeader_WhenUrlMatchesPropagationOptions()
3872
{

0 commit comments

Comments
 (0)