We have full support for OpenTelemetry simplified instrumentation code that sets up tracing automatically.The 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.
The arize.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:
Copy
Ask AI
from arize.otel import register# Setup OTel via our convenience functiontracer_provider = register( # See details in examples below...)# Instrument your application using OpenInference AutoInstrumentatorsfrom openinference.instrumentation.openai import OpenAIInstrumentorOpenAIInstrumentor().instrument(tracer_provider=tracer_provider)
The above code snippet will yield a fully setup and instrumented application. It is worth noting that this is completely optional. The usage of this package is for convenience only, you can set up OpenTelemetry and send traces to Arize AX without installing this or any other package from Arize.In the following sections we have examples on how to use the register function:
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 has two different endpoints which can be set using the following:The default behavior is to utilize GRPC which is https://otlp.arize.com/v1
Copy
Ask AI
from arize.otel import register, Endpointtracer_provider = register( endpoint=Endpoint.ARIZE, #this is the default value if not specified space_id = "your-arize-space-id", api_key = "your-arize-api-key", project_name = "your-model-id",)
The Arize AX HTTPS endpoint is https://otlp.arize.com/v1/traces
Copy
Ask AI
from arize.otel import register, Endpoint, Transporttracer_provider = register( endpoint= "https://otlp.arize.com/v1/traces" #this is the HTTPS endpoint space_id = "your-arize-space-id", api_key = "your-arize-api-key", project_name = "your-model-id", transport = Transport.HTTP,)
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 a GRPCSpanExporter. If you’d like to use a HTTPSpanExporter instead, specify the transport as shown below:
Copy
Ask AI
from arize.otel import registertracer_provider = register( endpoint = "https://my-custom-endpoint" # any other options...)
If you’re using endpoints from the Endpoint 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:
Copy
Ask AI
from arize.otel import register, Transporttracer_provider = register( endpoint = "https://my-custom-endpoint" transport = Transport.HTTP, # any other options...)
Note that there can be a silent failure if the transport type and endpoint’s expected transport format are mismatched.
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 use SimpleSpanProcessor with the option use_batch_processor=False.
Copy
Ask AI
from arize.otel import registertracer_provider = register( # other options... batch=False)
The register function will read from environment variables if the arguments are not passed:
Copy
Ask AI
from arize.otel import registertracer_provider = register( space_id = ... # Will be read from ARIZE_SPACE_ID env var api_key = ... # Will be read from ARIZE_API_KEY env var project_name = ... # Will be read from ARIZE_PROJECT_NAME env var endpoint = ... # Will be read from ARIZE_COLLECTOR_ENDPOINT env var, defaults to Endpoint.Arize)
In the event of conflict, if an environment variable is set but a different argument is passed, the argument passed will take precedence and the environment variable will be ignored.
For more granular tracing configuration, these wrappers can be used as drop-in replacements for OTel primitives:
Copy
Ask AI
from opentelemetry import trace as trace_apifrom arize.otel import HTTPSpanExporter, TracerProvider, SimpleSpanProcessortracer_provider = TracerProvider()span_exporter = HTTPSpanExporter(endpoint=...)span_processor = SimpleSpanProcessor(span_exporter=span_exporter)tracer_provider.add_span_processor(span_processor)trace_api.set_tracer_provider(tracer_provider)
Wrappers have Arize AX-aware defaults to greatly simplify the OTel configuration process. A special 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
Copy
Ask AI
from opentelemetry import trace as trace_apifrom arize.otel import TracerProvidertracer_provider = TracerProvider(endpoint="https://your-desired-endpoint.com")trace_api.set_tracer_provider(tracer_provider)