Included Instrumentation

Propagating a trace

Sentry SDK provides a custom HTTP handler, SentryHttpMessageHandler. This handler can be used inside HttpClient to automatically propagate traces and create spans to track outgoing requests.

To use it, create an instance of HttpClient by passing an instance of SentryHttpMessageHandler as a constructor parameter:

Copied
var httpHandler = new SentryHttpMessageHandler();
var httpClient = new HttpClient(httpHandler);

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

Upon sending a request to https://example.com, the instrumented HTTP client will:

  • Populate the sentry-trace header on the request. This allows peer service to start a transaction by linking it to the current (assuming it's also instrumented with Sentry).
  • Start a span named GET https://example.com which will track the corresponding HTTP operation on the current transaction.

Additionally, SentryHttpMessageHandler also inherits from DelegatingHandler which allows you to chain it together with other handlers. For example:

Copied
var innerHttpHandler = new HttpClientHandler();
var sentryHttpHandler = new SentryHttpMessageHandler(innerHttpHandler);
var httpClient = new HttpClient(sentryHttpHandler);
You can edit this page on GitHub.