Skip to main content
When tracing is enabled, the Apitally SDK captures OpenTelemetry spans 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.

Enable tracing

To enable tracing, set captureTraces to true in your request logging configuration:

Set up OpenTelemetry

To capture spans from libraries like HTTP clients and database drivers, you need to set up OpenTelemetry instrumentation. First, install the required packages:
Then create an instrumentation.ts file (or instrumentation.mjs for JavaScript) that initializes the OpenTelemetry SDK with the ApitallySpanProcessor and auto-instrumentations:
instrumentation.ts / instrumentation.mjs
No trace exporter is required. The ApitallySpanProcessor collects spans and attaches them to request logs instead.
Finally, run your application with the --import flag to load the instrumentation before your application code:
See the official OpenTelemetry guide for Node.js for more details.

Create custom spans

For custom operations that aren’t covered by library instrumentation, you can create spans manually using the startActiveSpan method from the standard OpenTelemetry API.