sentry-dotnet icon indicating copy to clipboard operation
sentry-dotnet copied to clipboard

SentryHttpMessageHandler on MAUI not propagating traces for HttpClient requests

Open drowe5 opened this issue 1 year ago • 3 comments

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

7.0.49

OS

iOS

SDK Version

3.41.3

Self-Hosted Sentry Version

No response

Steps to Reproduce

  1. Create a MAUI app using .NET 7.0 and Sentry.Maui 3.41.3
  2. Configure Sentry as needed in MauiProgram.cs (in CreateMauiApp())
  3. Write a function as described on the Automatic Instrumentation page
var httpHandler = new SentryHttpMessageHandler();
var httpClient = new HttpClient(httpHandler);

var response = await httpClient.GetStringAsync("https://example.com");

4.Run the application in iOS Simulator on Mac (M1) running Sonoma 14.0

Expected Result

The transaction will show up in the on the web (presumably under either Performance or Discover) sections.

Actual Result

Transaction is not visible anywhere on the web (though other manually created Transactions as described in Custom Instrumentation do appear as expected.)

drowe5 avatar Dec 01 '23 02:12 drowe5

Thanks for raising this. Let me give this a try.

bitsandfoxes avatar Dec 04 '23 11:12 bitsandfoxes

Sorry for the delay but I can reproduce this locally. Interestingly, the SDK does set the traceheader as expected but I suspect the underlying native SDK is overwriting it.

bitsandfoxes avatar Dec 07 '23 14:12 bitsandfoxes

Relies on https://github.com/getsentry/sentry-cocoa/issues/3490

bitsandfoxes avatar Dec 11 '23 15:12 bitsandfoxes

I can reproduce this. It seems to be due to this logic in the SentryHttpMessageHandler: https://github.com/getsentry/sentry-dotnet/blob/043cb5f8b5e177bbc0b644e1706d2e8c7360488a/src/Sentry/SentryHttpMessageHandler.cs#L66-L69

So a span only gets created by SentryHttpMessageHandler if there is already an active transaction set on the scope.

jamescrosswell avatar May 10 '24 08:05 jamescrosswell