GitHub - Arize-ai/arize-otel-python
Github
arize-otel package provides a lightweight wrapper around OpenTelemetry primitives with Arize AX-aware defaults and options. It is meant to be a very lightweight convenience package to set up OpenTelemetry for tracing LLM applications and send the traces to Arize AX.
Read here for more on how tracing works.
Installation
Installarize-otel using pip
Quickstart
Thearize.otel module provides a high-level register function to configure OpenTelemetry tracing by returning a TracerProvider. The register function can also configure headers and whether or not to process spans one by one or by batch.
The following examples showcase how to use register to setup OpenTelemetry in order to send traces to a collector. However, this is NOT the same as instrumenting your application. For instance, you can use any of our OpenInference AutoInstrumentators. Assuming we use the OpenAI AutoInstrumentation, we need to run instrument() after using register:
register function:
Send traces to Arize AX
To send traces to Arize AX you need to authenticate via the Space ID and API Key. You can find them in the Settings page in the Arize AX platform. In addition, you’ll need to specify the project name, a unique name to identify your project in the Arize AX platform.Arize AX GRPC + HTTPS Endpoints
Arize AX has two different endpoints which can be set using the following: The default behavior is to utilize GRPC which ishttps://otlp.arize.com/v1
https://otlp.arize.com/v1/traces
Arize AX EU Endpoint
If you are located in the European Union, you’ll need to specify the correspondingEndpoint (the default endpoint is Endpoint.ARIZE):
Send traces to Custom Endpoint
Sending traces to a collector on a custom endpoint is simple, you just need to provide the endpoint as a string. In addition, it is worth noting that the default is to use aGRPCSpanExporter. If you’d like to use a HTTPSpanExporter instead, specify the transport as shown below:
Specify exporter type
If you’re using endpoints from theEndpoint enum, you do not need to do this, since we know what exporter to use. However, if you’re using a custom endpoint, it is worth noting that the default is to use a GRPCSpanExporter. If you’d like to use a HTTPSpanExporter instead, specify the transport as shown below:
Note that there can be a silent failure if the transport type and endpoint’s expected transport format are mismatched.
Turn off batch processing of spans
We default to using BatchSpanProcessor from OpenTelemetry because it is non-blocking in case telemetry goes down. In contrast, “SimpleSpanProcessor processes spans as they are created.” This can be helpful in development. You can useSimpleSpanProcessor with the option use_batch_processor=False.
Debug
As you’re setting up your tracing, it is helpful to print to console the spans created. You can achieve this by settinglog_to_console=True.
Route traces to multiple spaces and projects
If a single application needs to send traces to different Arize AX spaces or projects, useregister_with_routing. This is useful for multi-tenant applications, shared platforms, or services that need to route traces by team, customer, or environment at request time.
Unlike register, you do not configure a single space_id or project_name up front. Instead, you set routing values dynamically with set_routing_context, and all child spans created within that context inherit those values automatically.
with set_routing_context(...) block are routed to the specified Arize AX space and project. This includes spans created by auto-instrumentors such as OpenAI, LangChain, and LlamaIndex.
Both
space_id and project_name are required for routing. If either value is missing, spans in that context are not sent to Arize AX.Using Environment Variables
The register function will read from environment variables if the arguments are not passed:Using OTel Primitives
For more granular tracing configuration, these wrappers can be used as drop-in replacements for OTel primitives:endpoint keyword argument can be passed to either a TracerProvider, SimpleSpanProcessor or BatchSpanProcessor in order to automatically infer which SpanExporter to use to simplify setup.
Specifying the endpoint directly