Skip to main content
When tracing is enabled, the Apitally SDK captures Activities during request handling and attaches them to request logs. This allows you to see exactly what happened during each request, including database queries, HTTP calls to external services, and custom operations. The SDK uses the native 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, set CaptureTraces to true in your request logging configuration:
builder.Services.AddApitally(options =>
{
    options.ClientId = "your-client-id";
    options.Env = "dev";
    options.RequestLogging.Enabled = true;
    options.RequestLogging.CaptureTraces = true;
});

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: See the OpenTelemetry registry for more instrumentation packages.

Create custom spans

For custom operations that aren’t covered by library instrumentation, you can create spans manually using the System.Diagnostics API. First, create an ActivitySource for your application (typically as a static field):
using System.Diagnostics;

public static class Telemetry
{
    public static readonly ActivitySource Source = new("MyApp");
}
Then use StartActivity to create spans:
public async Task ProcessOrderAsync(int orderId)
{
    using var activity = Telemetry.Source.StartActivity("ProcessOrder");
    activity?.SetTag("order.id", orderId);

    // ...
}