Instrument libraries
Use official OpenTelemetry instrumentation packages to trace supported libraries. Initialize the instrumentations before loading your application code or the libraries they instrument. For example, to trace database queries made withpg, install @opentelemetry/instrumentation and @opentelemetry/instrumentation-pg:
instrumentation.mjs
Existing OpenTelemetry setup
Apitally works alongside your existing OpenTelemetry instrumentation and exporters. If your application registers its own tracer provider, addApitallySpanProcessor to the list of span processors. For example, with NodeSDK:
Create custom spans
For custom operations that are not covered by library instrumentation, you can create spans using the helpers provided by the SDK. These are thin wrappers around the standard OpenTelemetry API, which you can also use directly.instrument() function wrapper
Use instrument() to automatically create a span for a function. It works with both synchronous and asynchronous functions:
span() helper
Use span() to trace code blocks within a function:
Capture handled exceptions
Apitally includes exceptions in request traces to help you diagnose server errors. Exceptions that propagate through your web framework are captured automatically. If your application catches an exception and handles it without rethrowing it, callcaptureException() to include it in the current request trace.