Masking Sensitive Data
Install packagemask function during client initialization. This function will be applied to all relevant data before it’s sent to ABV.
The mask function should accept data as a keyword argument and return the masked data. The returned data must be JSON-serializable.
Logging
The ABV SDK uses Python’s standardlogging module. The main logger is named "abv".
To enable detailed debug logging, you can either:
- Set the
debug=Trueparameter when initializing theABVclient. - Set the
ABV_DEBUG="True"environment variable. - Configure the
"abv"logger manually:
abv logger is logging.WARNING.
Sampling
You can configure the SDK to sample traces by setting thesample_rate parameter during client initialization (or via the ABV_SAMPLE_RATE environment variable). This value should be a float between 0.0 (sample 0% of traces) and 1.0 (sample 100% of traces).
If a trace is not sampled, none of its observations (spans, generations) or associated scores will be sent to ABV.
Filtering by Instrumentation Scope
You can configure the SDK to filter out spans from specific instrumentation libraries by using theblocked_instrumentation_scopes parameter. This is useful when you want to exclude infrastructure spans while keeping your LLM and application spans.
metadata.scope.name). Use this to identify which scopes you want to filter.
Isolated TracerProvider
You can configure a separate OpenTelemetry TracerProvider for use with ABV. This creates isolation between ABV tracing and your other observability systems. Benefits of isolation:- ABV spans won’t be sent to your other observability backends (e.g., Datadog, Jaeger, Zipkin)
- Third-party library spans won’t be sent to ABV
- Independent configuration and sampling rates
Using ThreadPoolExecutors or ProcessPoolExecutors
The observe decorator uses Python’scontextvars to store the current trace context and ensures that the observations are correctly associated with the current execution context. However, when using Python’s ThreadPoolExecutors and ProcessPoolExecutors and when spawning threads from inside a trace (i.e. the executor is run inside a decorated function) the decorator will not work correctly as the contextvars are not correctly copied to the new threads or processes. There is an existing issue in Python’s standard library and a great explanation in the fastapi repo that discusses this limitation.
The recommended workaround is to pass the parent observation id and the trace ID as a keyword argument to each multithreaded execution, thus re-establishing the link to the parent span or trace:
Distributed tracing
To maintain the trace context across service / process boundaries, please rely on the OpenTelemetry native context propagation across service / process boundaries as much as possible. Using thetrace_context argument to ‘force’ the parent child relationship may lead to unexpected trace updates as the resulting span will be treated as a root span server side.
- If you are using multiprocessing, see here for details on how to propagate the OpenTelemetry context.
- If you are using Pydantic Logfire, please set
distributed_tracingtoTrue.
Multi-Project Setup (Experimental)
The ABV Python SDK supports routing traces to different projects within the same application by using multiple api keys. This works because the ABV SDK adds a specific span attribute containing the api key to all spans it generates. How it works:- Span Attributes: The ABV SDK adds a specific span attribute containing the api key to spans it creates
- Multiple Processors: Multiple span processors are registered onto the global tracer provider, each with their respective exporters bound to a specific api key
- Filtering: Within each span processor, spans are filtered based on the presence and value of the api key attribute
- These spans cannot be routed to a specific project
- They are processed by all span processors and sent to all projects
- All projects will receive these third-party spans
api_key parameter be passed to all ABV SDK executions across all integrations to ensure proper routing, and third-party spans will appear in all projects.
Initialization
To set up multiple projects, initialize separate ABV clients for each project:Integration Usage
For all integrations in multi-project setups, you must specify theapi_key parameter to ensure traces are routed to the correct project.
Observe Decorator:
Pass abv_api_key as a keyword argument to the top-most observed function (not the decorator). Nested decorated functions will automatically pick up the api key from the execution context they are currently into. Also, calls to get_client will be also aware of the current abv_api_key in the decorated function execution context, so passing the abv_api_key here again is not necessary.
- Every ABV SDK execution across all integrations must include the appropriate api key parameter
- Missing api key parameters may result in traces being routed to the default project or lost
- Third-party OpenTelemetry spans (from HTTP clients, databases, etc.) will appear in all projects since they lack the ABV api key attribute
Passing completion_start_time for TTFT tracking
If you are using the Python SDK to manually create generations, you can pass thecompletion_start_time parameter. This allows abv to calculate the time to first token (TTFT) for you.