Manual Instrumentation

Fully customize your traces with manual instrumentation.

We recommend starting with one of our supported integrations if available. If one is not available, Arize AX is OTEL compliant and can manually instrument your traces. Traces should be instrumented in the OpenInference Semantic Conventions for the best experience.

1

Installation

Ensure you have OpenInference and OpenTelemetry installed:

pip install openinference opentelemetry-api opentelemetry-sdk arize-otel
2

Get API Key & Space ID

Go to Settings -> API keys to create your API key and to get the Space ID of your current space.

3

Set Up Tracer Provider

Set up your tracer provider using the Arize register function.

import opentelemetry
from arize.otel import register

# Setup the tracer provider
tracer_provider = register(
    space_id = "YOUR_SPACE_ID", 
    api_key = "YOUR_API_KEY",
    project_name = "YOUR_PROJECT_NAME", 
)

tracer = tracer_provider.get_tracer(__name__)
4

Use Tracer to Create Spans

There are multiple ways to start using your tracer object, either as a decorator, beneficial for tracing an entire function, or as a context manager (to trace a specific block).

@tracer.chain
def run_agent(user_input: str) -> str:
    # This span is kind=CHAIN by default, captures input & output
    response = call_llm(user_input)
    return response

def call_llm(prompt: str) -> str:
    with tracer.start_as_current_span("llm-completion") as span:
        span.set_attribute("openinference.span.kind", "LLM")
        span.set_attribute("input.value", prompt)
        span.set_attribute("llm.model_name", "gpt-3.5-turbo")
        
        result = external_llm_client.chat(prompt)
        
        span.set_attribute("output.value", result)
        span.set_status(Status(StatusCode.OK))
        return result

How to Instrument Individual Spans

When instrumenting your application, beyond just the tracer/chain span, you should choose the appropriate span kind for each step your application may take. You can define each of them using the attribute openinference.span.kind.

Check out our guide on Spans to see all the different span types you can configure and how to.

FAQs:

Q: Do I have to use an SDK that supports OpenInference? A: No; you can use any OpenTelemetry-compatible tracer. But if you instrument using the OpenInference schema (span kinds + attributes) you’ll get better integration (analytics, visualisation) in Arize AX and across tools.

Q: I don't think I'm doing this correctly. It looks off. A: Depending on how it looks off: We expect that spans follow the OpenInference semantic conventions for best experience. That means every span should set the openinference.span.kind attribute (e.g., LLM, TOOL, CHAIN) and include the recommended attributes for that kind (for example: input.value, output.value, llm.model_name). You may also add your own custom attributes alongside those.

Q: What if I’m capturing sensitive data (PII) in spans or attributes? A: When using manual instrumentation, if you include sensitive or PII data as span attributes, you must handle masking, redaction, or encryption as appropriate. Arize AX supports attribute-level redaction and you should follow your organisation’s compliance policies.

Q: Can I combine auto-instrumentation and manual instrumentation? A: Yes! Many users enable auto-instrumentation for the bulk of spans, then add manual spans where they need extra detail (custom tool calls, business logic, domain-specific flows). Make sure when you add manual spans you still follow the OpenInference schema so traces remain consistent.

Last updated

Was this helpful?