Skip to main content
openinference-instrumentation-annotation adds annotation-driven tracing to any Java application. Annotate your methods with @Chain, @LLM, @Tool, @Agent, or @Span and a ByteBuddy agent intercepts each call at class load to produce OpenInference spans backed by OpenTelemetry. Use it when you’ve built an agent or pipeline by hand and want OpenInference semantics without a framework-specific instrumentor.

Prerequisites

  • Java 17+ (-parameters compiler flag enabled, so the agent can read parameter names — see Install)
  • An Arize AX account (sign up)
  • An OPENAI_API_KEY from the OpenAI Platform

Launch Arize

  1. Sign in to your Arize AX account.
  2. From Space Settings, copy your Space ID and API Key. You will set them as ARIZE_SPACE_ID and ARIZE_API_KEY below.

Install

Add the dependencies to build.gradle:
The annotation artifact uses standard hyphenated namingopeninference-instrumentation-annotation — unlike openinference-instrumentation-springAI which retains camelCase on Maven Central.

Configure credentials

Setup tracing

The annotation instrumentor needs three things at startup: the ByteBuddy agent installed before any annotated class is loaded, an OITracer wrapping an OpenTelemetry tracer, and that OITracer registered with the OpenInferenceAgent so the intercepted methods know where to emit spans.

Available annotations

Parameters are automatically captured as input.value and the return value as output.value. Use @ExcludeFromSpan on a parameter to drop it from the input attribute, and @SpanMapping to map a parameter or field to a specific OpenInference semantic-convention attribute.

Run Annotations

Annotate your service methods with the span kind that fits each step, then run it. The agent intercepts at class load — there’s nothing further to wire up beyond the annotations themselves.
Calling service.answer("Why is the ocean salty? Answer in two sentences.") produces a nested trace:
Build and run:

Expected output

Verify in Arize

  1. Open your Arize AX space and select project annotation-tracing-example.
  2. You should see a new trace within ~30–60 seconds (Arize’s Java OTLP ingest is slightly slower than the Python path) with the four-span hierarchy shown above. Click the root qa-agent span to inspect captured inputs and outputs.
  3. If no traces appear, see Troubleshooting.

Check from the skill, CLI, or SDK

Confirm spans are actually reaching your Arize AX project. Use whichever fits your workflow — the skill and CLI work for any framework; the SDK check is shown for each language.
Install the Arize Skills plugin and let your coding agent check for you:
Then prompt your agent:
Use the arize-trace skill to export and analyze recent traces from my project. Confirm spans are arriving, and summarize any errors or latency issues.

Troubleshooting

  • No spans, but OpenInferenceAgentInstaller.install() ran. The ByteBuddy agent only rewrites classes loaded after it installs. Make sure install() is the first statement in main, and that you don’t reference any annotated class (directly or transitively via imports) before that line. The example above defers QAService loading until after install() by only naming QAService inside main.
  • Parameters appear as arg0, arg1, … in span attributes. The compiler stripped parameter names. Add compileJava { options.compilerArgs += '-parameters' } to your build.gradle (already in the Install snippet), or fall back to @SpanMapping(parameter = "arg0", ...) to reference the generated names.
  • No traces in Arize. Confirm ARIZE_SPACE_ID and ARIZE_API_KEY are set in the same shell that runs gradle run. To confirm spans are being produced locally before troubleshooting export, add SimpleSpanProcessor.create(LoggingSpanExporter.create()) as an extra processor — it prints every span to stderr.
  • 401 from OpenAI. Verify OPENAI_API_KEY is set and has access to gpt-5.5. Swap "gpt-5.5" in the openAiChatCompletion body for a model your key can call.
  • Spans dropped at JVM exit. BatchSpanProcessor exports asynchronously. Always tracerProvider.forceFlush().join(...) and tracerProvider.shutdown().join(...) before main returns.
  • Lost spans across thread boundaries. The ByteBuddy agent wraps each annotated method on the calling thread. OpenTelemetry context does not automatically follow execution across CompletableFuture, ExecutorService, reactive frameworks (Reactor, RxJava, Mutiny), or coroutines. Propagate context explicitly with io.opentelemetry.context.Context.current().wrap(...) when handing work to another thread, or fall back to the programmatic span API where you control span lifetimes directly.
  • Hiding sensitive fields. Pass a TraceConfig when constructing the OITracer to suppress inputs / outputs / tool parameters: new OITracer(provider.get("..."), TraceConfig.builder().hideInputs(true).hideOutputs(true).build()).

Resources

Annotation Instrumentor README

OpenInference Annotation Instrumentor (Maven Central)

OpenInference Annotation Source

ByteBuddy (the underlying class-loading agent)