This documentation has an index for AI agents at /llms.txt. A Markdown version of this page is available at https://explorer.opentelemetry.io/java-agent/instrumentation/openai-java-1.1.md.

OpenAI Java SDK

OpenTelemetry Java agent instrumentation

This instrumentation enables Gen AI client spans and metrics for the OpenAI Java SDK.

  • Name: openai-java-1.1
  • Scope: io.opentelemetry.openai-java-1.1
  • Target versions: com.openai:openai-java:[1.1.0,3)
  • Library: https://github.com/openai/openai-java

Telemetry

When default

Metrics

MetricInstrumentTypeUnitDescription
gen_ai.client.operation.durationhistogramHISTOGRAMsGenAI operation duration.
gen_ai.client.token.usagehistogramHISTOGRAM{token}Measures number of input and output tokens used.
MetricAttributes
gen_ai.client.operation.durationgen_ai.operation.name (STRING), gen_ai.provider.name (STRING), gen_ai.request.model (STRING), gen_ai.response.model (STRING)
gen_ai.client.token.usagegen_ai.operation.name (STRING), gen_ai.provider.name (STRING), gen_ai.request.model (STRING), gen_ai.response.model (STRING), gen_ai.token.type (STRING)

Spans

Span kindAttributes
CLIENTgen_ai.operation.name (STRING), gen_ai.provider.name (STRING), gen_ai.request.encoding_formats (STRING_ARRAY), gen_ai.request.frequency_penalty (DOUBLE), gen_ai.request.max_tokens (LONG), gen_ai.request.model (STRING), gen_ai.request.presence_penalty (DOUBLE), gen_ai.request.seed (LONG), gen_ai.request.stop_sequences (STRING_ARRAY), gen_ai.request.stream (BOOLEAN), gen_ai.request.temperature (DOUBLE), gen_ai.request.top_p (DOUBLE), gen_ai.response.finish_reasons (STRING_ARRAY), gen_ai.response.id (STRING), gen_ai.response.model (STRING), gen_ai.usage.cache_read.input_tokens (LONG), gen_ai.usage.input_tokens (LONG), gen_ai.usage.output_tokens (LONG), gen_ai.usage.reasoning.output_tokens (LONG)

When otel.semconv.exception.signal.preview=logs

Metrics

MetricInstrumentTypeUnitDescription
gen_ai.client.operation.durationhistogramHISTOGRAMsGenAI operation duration.
gen_ai.client.token.usagehistogramHISTOGRAM{token}Measures number of input and output tokens used.
MetricAttributes
gen_ai.client.operation.durationgen_ai.operation.name (STRING), gen_ai.provider.name (STRING), gen_ai.request.model (STRING), gen_ai.response.model (STRING)
gen_ai.client.token.usagegen_ai.operation.name (STRING), gen_ai.provider.name (STRING), gen_ai.request.model (STRING), gen_ai.response.model (STRING), gen_ai.token.type (STRING)

Spans

Span kindAttributes
CLIENTgen_ai.operation.name (STRING), gen_ai.provider.name (STRING), gen_ai.request.encoding_formats (STRING_ARRAY), gen_ai.request.frequency_penalty (DOUBLE), gen_ai.request.max_tokens (LONG), gen_ai.request.model (STRING), gen_ai.request.presence_penalty (DOUBLE), gen_ai.request.seed (LONG), gen_ai.request.stop_sequences (STRING_ARRAY), gen_ai.request.stream (BOOLEAN), gen_ai.request.temperature (DOUBLE), gen_ai.request.top_p (DOUBLE), gen_ai.response.finish_reasons (STRING_ARRAY), gen_ai.response.id (STRING), gen_ai.response.model (STRING), gen_ai.usage.cache_read.input_tokens (LONG), gen_ai.usage.input_tokens (LONG), gen_ai.usage.output_tokens (LONG), gen_ai.usage.reasoning.output_tokens (LONG)

Configuration

OptionTypeDefaultDescription
otel.instrumentation.genai.capture-message-contentbooleanfalseEnables including the full content of user and assistant messages in emitted log events. Note that full content can have data privacy and size concerns, and care should be taken when enabling this.

Data

  • JSON (latest): /data/javaagent/instrumentations/openai-java-1.1/latest.json
  • JSON (pinned): /data/javaagent/instrumentations/openai-java-1.1/openai-java-1.1-1e60800098d0.json
  • Explore: /java-agent/instrumentation/openai-java-1.1