getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
566 stars 203 forks source link

Make span eligible for `Requests` #3334

Closed bitsandfoxes closed 1 day ago

bitsandfoxes commented 2 weeks ago

https://docs.sentry.io/product/performance/requests/#span-eligibility

Review

SentryHttpMessageHandler / SentryGraphQLHttpMessageHandler

OpenTelemetry instrumentation

jamescrosswell commented 2 weeks ago

@bitsandfoxes added some details to the issue description.

jamescrosswell commented 6 days ago

So it turns out this scenario isn't actually possible in .NET:

❌ If the request is to a relative URL (e.g., "GET /data.json"), the server.address span data value should be set to the server address (e.g., "my.service.io").

The only way to use Relative URLs with HttpClient is like this:

using var client = new HttpClient(sentryHandler);
client.BaseAddress = new Uri("http://localhost");
var uri = new Uri("/hello", UriKind.Relative);
await client.GetAsync(uri);

The call to await client.GetAsync(uri) will throw an exception if you're using a Uri with UriKind.Relative and you haven't set the HttpClient.BaseAddress. On the other hand, if you provide the base address, this gets combined with the relative url to create an absolute Uri.

No matter which way you do it then, by the time we see the Uri in the SentryMessageHandler, it will be an absolute URI.

I've opted to always set the server.address span data, which I think is what's happening when the spans are instrumented with OpenTelemetry.