System.Diagnostics.Activity API, which is the same API that OpenTelemetry for .NET is built on. This means OpenTelemetry is not required, but any existing OpenTelemetry instrumentation will work seamlessly.
Enable tracing
To enable tracing, setCaptureTraces to true in your request logging configuration:
Instrument libraries
HttpClient and some other .NET libraries include built-in Activity instrumentation, so they generate spans automatically without any additional setup.
Other libraries require OpenTelemetry instrumentation packages. For example:
| Library | Instrumentation package |
|---|---|
| Entity Framework Core | OpenTelemetry.Instrumentation.EntityFrameworkCore |
| SqlClient | OpenTelemetry.Instrumentation.SqlClient |
| Npgsql | Npgsql.OpenTelemetry |
| StackExchange.Redis | OpenTelemetry.Instrumentation.StackExchangeRedis |
Create custom spans
For custom operations that aren’t covered by library instrumentation, you can create spans manually using theSystem.Diagnostics API.
First, create an ActivitySource for your application (typically as a static field):
StartActivity to create spans: