Setup
Install packages.env file in your project root and a package like dotenv to load the variables.
.env
instrumentation.ts file that initializes the OpenTelemetry NodeSDK and registers the ABVSpanProcessor.
instrumentation.ts
instrumentation.ts file to use dotenv package to load the variables.
Additional parameters are provided to get trace visible in the UI immediately.
instrumentation.ts
instrumentation.ts file at the top of your application.
index.ts
Masking
To prevent sensitive data from being sent to ABV, you can provide amask function to the ABVSpanProcessor. This function will be applied to the input, output, and metadata of every observation.
The function receives an object { data }, where data is the stringified JSON of the attribute’s value. It should return the masked data.
instrumentation_masked.ts
Filtering Spans
You can provide a predicate functionshouldExportSpan to the ABVSpanProcessor to decide on a per-span basis whether it should be exported to ABV.
instrumentation.ts
instrumentation.ts
If you would like to exclude ABV spans from being sent to third-party observability backends configured in your OpenTelemetry setup, see the documentation on isolating the ABV tracer provider.
Sampling
ABV respects OpenTelemetry’s sampling decisions. You can configure a sampler in your OTEL SDK to control which traces are sent to ABV. This is useful for managing costs and reducing noise in high-volume applications. Here is an example of how to configure aTraceIdRatioBasedSampler to send only 20% of traces:
instrumentation.ts
Managing trace and observation IDs
In ABV, every trace and observation has a unique identifier. Understanding their format and how to set them is useful for integrating with other systems.- Trace IDs are 32-character lowercase hexadecimal strings, representing 16 bytes of data
- Observation IDs (also known as Span IDs in OpenTelemetry) are 16-character lowercase hexadecimal strings, representing 8 bytes
parentSpanContext option in tracing methods.
When starting a new trace by setting a traceId, you must also provide an arbitrary parent-spanId for the parent observation. The parent span ID value is irrelevant as long as it is a valid 16-hexchar string as the span does not actually exist but is only used for trace ID inheritance of the created observation.
You can create valid, deterministic trace IDs from a seed string using createTraceId. This is useful for correlating ABV traces with IDs from external systems, like a support ticket ID.
getActiveTraceId function:
Logging
You can configure the global SDK logger to control the verbosity of log output. This is useful for debugging. In code:DEBUG, INFO, WARN, and ERROR.
Via environment variable:
You can also set the log level using the ABV_LOG_LEVEL environment variable.
.env
Serverless environments
In short-lived environments such as serverless functions (e.g., Vercel Functions, AWS Lambda), you must explicitly flush the traces before the process exits or the runtime environment is frozen.Generic Serverless function
Export the processor from your OTEL SDK setup file in order to flush it later.instrumentation.ts
forceFlush() on the span processor before the function exits.
handler.ts
Vercel Cloud Functions
Export the processor from yourinstrumentation.ts file in order to flush it later.
instrumentation.ts
after utility to schedule a flush after the request has completed.
route.ts
Isolated tracer provider
The ABV JS SDK uses the global OpenTelemetry TracerProvider to attach its span processor and create tracers that emit spans. This means that if you have an existing OpenTelemetry setup with another destination configured for your spans (e.g., Datadog), you will see ABV spans in those third-party observability backends as well. If you’d like to avoid sending ABV spans to third-party observability backends in your existing OpenTelemetry setup, you will need to use an isolated OpenTelemetry TracerProvider that is separate from the global one.If you would like to simply limit the spans that are sent to ABV and you have no third-party observability backend where you’d like to exclude ABV spans from, see filtering spans instead.
Multi-project Setup
You can configure the SDK to send traces to multiple ABV projects. This is useful for multi-tenant applications or for sending traces to different environments. Simply register multipleABVSpanProcessor instances, each with its own credentials.
instrumentation.ts
shouldExportSpan filter for each processor to control which traces go to which project.