Skip to content

Commit

Permalink
Dynamic Sampling Context propagates correctly for HttpClient spans (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell authored Mar 12, 2024
1 parent 626d807 commit 0ee3904
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit 0ee3904

Please sign in to comment.