Skip to main content
To instrument your application to send traces to ABV, you can use instrumentation methods for fine-grained control
  1. Context manager: startActiveObservation
  2. Wrapper: observe
  3. Manual: startObservation
These components are interoperable.

Setup

To get started with the ABV TypeScript SDK you need to install the SDK and initialize the client.

Instrumentation

You can add custom instrumentations to your application via
  • the observe wrapper
  • startActiveObservation context managers
  • manually managing the observation lifecycle and its nesting with the startObservation function
For an end-to-end example, see the JS Instrumentation Cookbook.

Context management with callbacks

To simplify nesting and context management, you can use startActiveObservation. These functions take a callback and automatically manage the observation’s lifecycle and the OpenTelemetry context. Any observation created inside the callback will automatically be nested under the active observation, and the observation will be ended when the callback finishes. This is the recommended approach for most use cases as it prevents context leakage and ensures observations are properly ended.

observe wrapper

The observe wrapper is a powerful tool for tracing existing functions without modifying their internal logic. It acts as a decorator that automatically creates a span or generation around the function call. You can use the updateActiveObservation function to add attributes to the observation from within the wrapped function.
You can configure the observe wrapper by passing an options object as the second argument:

Manual observations

The core tracing function (startObservation) gives you full control over creating observations. You can pass the asType option to specify the type of observation to create. When you call one of these functions, the new observation is automatically linked as a child of the currently active operation in the OpenTelemetry context. However, it does not make this new observation the active one. This means any further operations you trace will still be linked to the original parent, not the one you just created. To create nested observations manually, use the methods on the returned object (e.g., parentSpan.startObservation(...)).

Updating Traces

Often, you might not have all the information about a trace (like a userId or sessionId) when you start it. The SDK lets you add or update trace-level attributes at any point during its execution.

.updateTrace() on an observation

When you create an observation manually with startObservation, the returned object has an .updateTrace() method. You can call this at any time before the root span ends to apply attributes to the entire trace.

updateActiveTrace()

When you’re inside a callback from startActiveObservation, or a function wrapped with observe, you might not have a direct reference to an observation object. In these cases, use the updateActiveTrace() function. It automatically finds the currently active trace in the context and applies the new attributes.