Activity API or instrumentation libraries will be captured.
Instrument libraries
HttpClient calls and libraries that create spans using their own ActivitySource, such as Npgsql, are captured automatically without any additional setup.
Other libraries require OpenTelemetry instrumentation packages. For example, to trace database queries made with Microsoft.Data.SqlClient, install OpenTelemetry.Extensions.Hosting and OpenTelemetry.Instrumentation.SqlClient:
Program.cs file:
Program.cs
Existing OpenTelemetry setup
Apitally works alongside your existing OpenTelemetry instrumentation and exporters. If your application registers a tracer provider viaAddOpenTelemetry().WithTracing(...), Apitally automatically adds its span processor to it.
Apitally then captures only the activities your tracer provider is configured for, so register your own sources with AddSource() and add instrumentations such as AddHttpClientInstrumentation() as needed. Your tracer provider’s sampler also affects which request logs and traces Apitally captures.
If you build a tracer provider separately with Sdk.CreateTracerProviderBuilder(), add the ASP.NET Core instrumentation and the apitally.otel source to it, and register it with dependency injection so the SDK can find it:
Create custom spans
For custom operations that are not covered by library instrumentation, you can create spans using theStartActivity() method of the IApitally service. It is a thin wrapper around the standard .NET ActivitySource API, which you can also use directly.
StartActivity() method
Use StartActivity() to trace code blocks within a request handler. The span ends when the returned activity is disposed:
ActivitySource. If your application registers its own tracer provider, add the source to it with AddSource().
Capture handled exceptions
Apitally includes exceptions in request traces to help you diagnose server errors. Exceptions that propagate through ASP.NET Core are captured automatically. If your application catches an exception and handles it without rethrowing it, callCaptureException() on the IApitally service to include it in the current request trace.