Skip to content
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

Dynamic Sampling Context propagates correctly for HttpClient spans #3208

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Dynamic Sampling Context not propagated correctly for HttpClient spans ([#3208](https://github.com/getsentry/sentry-dotnet/pull/3208))

## 4.2.0

### Features
Expand Down
3 changes: 2 additions & 1 deletion src/Sentry/Internal/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ public SentryTraceHeader GetTraceHeader()

public BaggageHeader GetBaggage()
{
if (GetSpan() is TransactionTracer { DynamicSamplingContext: { IsEmpty: false } dsc })
var span = GetSpan();
if (span?.GetTransaction() is TransactionTracer { DynamicSamplingContext: { IsEmpty: false } dsc })
{
return dsc.ToBaggageHeader();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/SentryMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ protected override async Task<HttpResponseMessage> SendAsync(
var method = request.Method.Method.ToUpperInvariant();
var url = request.RequestUri?.ToString() ?? string.Empty;

PropagateTraceHeaders(request, url);
var span = ProcessRequest(request, method, url);
try
{
PropagateTraceHeaders(request, url);
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
HandleResponse(response, span, method, url);
return response;
Expand All @@ -104,10 +104,10 @@ protected override HttpResponseMessage Send(HttpRequestMessage request, Cancella
var method = request.Method.Method.ToUpperInvariant();
var url = request.RequestUri?.ToString() ?? string.Empty;

PropagateTraceHeaders(request, url);
var span = ProcessRequest(request, method, url);
try
{
PropagateTraceHeaders(request, url);
var response = base.Send(request, cancellationToken);
HandleResponse(response, span, method, url);
return response;
Expand Down
Loading