feat: Add GenAI agent/tool/retrieval semantic conventions to instrumentation-api-incubator #19124
Conversation
Introduce comprehensive GenAI semantic-convention support: add new extractor and getter types for agents, tools, and retrieval (GenAiAgent*/GenAiTool*/GenAiRetrieval*), plus a GenAiOperationAttributesGetter for common operation attributes. Update GenAiAttributesExtractor/GenAiAttributesGetter to emit provider name (migrating from deprecated getSystem), conversation id, output type, and conditional request.choice.count handling; and change span-name logic to use an operation target (used by various span types). Add SpanNameExtractors for agents and tools and add unit tests for span naming and the new extractors. Update existing instrumentations (AWS Bedrock and OpenAI chat/embedding) to implement getProviderName while delegating getSystem for compatibility.
…d add retrieval top_k. Make gen_ai.provider.name the primary API and deprecate the legacy getSystem anchor (getSystem now defaults to getProviderName). Add support for gen_ai.retrieval.top_k: introduce a Long getTopK in GenAiRetrievalAttributesGetter and emit GEN_AI_RETRIEVAL_TOP_K in the retrieval attributes extractor (with necessary import and key). Remove two specialized span name extractor classes (GenAiAgentSpanNameExtractor, GenAiToolSpanNameExtractor) and update tests to use the unified GenAiSpanNameExtractor, inline expected attribute keys (avoiding deprecated GenAiIncubatingAttributes), and mock agent/tool getters with CALLS_REAL_METHODS where appropriate. Also remove redundant getSystem overrides from several provider-specific getters (Bedrock, OpenAI chat/embedding) since getProviderName is now the abstract/primary method.
There was a problem hiding this comment.
Pull request overview
This PR extends GenAI support in instrumentation-api-incubator to cover the new agent, tool, and retrieval operation types from the emerging semantic-conventions-genai spec, building on the direction of #15268. It introduces a shared GenAiOperationAttributesGetter parent interface exposing getOperationName/getOperationTarget, which GenAiSpanNameExtractor now uses to build <operation_name> <target> span names uniformly across GenAI span types. It also adds new getter/extractor pairs for agent, tool, and retrieval spans, extends the inference extractor with additional attributes, and renames the provider getter from getSystem to getProviderName (keeping a deprecated getSystem default for migration).
Changes:
- New
GenAiOperationAttributesGetterparent interface plus agent/tool/retrieval getter+extractor pairs, withGenAiSpanNameExtractorretargeted to the parent interface (intentional binary-incompatible alpha API change). - Extends
GenAiAttributesGetter/GenAiAttributesExtractorwithgen_ai.provider.name,gen_ai.conversation.id,gen_ai.output.type, andgen_ai.request.choice.count(only emitted when not1). - Renames
getSystem→getProviderNameacross the interface and Bedrock/OpenAI implementations, retaining a deprecatedgetSystemdefault.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
.../genai/GenAiOperationAttributesGetter.java |
New shared parent interface with getOperationName/getOperationTarget. |
.../genai/GenAiAttributesGetter.java |
Extends parent interface; adds getProviderName, deprecates getSystem, adds choice-count/output-type/conversation-id defaults. |
.../genai/GenAiAttributesExtractor.java |
Emits new inference attributes; conditional choice-count emission. |
.../genai/GenAiSpanNameExtractor.java |
Builds span name from getOperationTarget; expanded javadoc (retrieval bullet is incomplete). |
.../genai/GenAiAgentAttributesGetter.java / ...Extractor.java |
New agent getter/extractor for create_agent/invoke_agent. |
.../genai/GenAiToolAttributesGetter.java / ...Extractor.java |
New tool getter/extractor for execute_tool. |
.../genai/GenAiRetrievalAttributesGetter.java / ...Extractor.java |
New retrieval getter/extractor with opt-in query-text capture (no test added). |
.../genai/GenAiAgentAttributesExtractorTest.java, GenAiToolAttributesExtractorTest.java, GenAiSpanNameExtractorTest.java |
New unit tests for agent, tool, and span-name behavior. |
.../awssdk/v2_2/internal/BedrockRuntimeAttributesGetter.java |
Renamed getSystem → getProviderName. |
.../openai/v1_1/ChatAttributesGetter.java, EmbeddingAttributesGetter.java |
Renamed getSystem → getProviderName. |
Pull request dashboard statusStatus last refreshed: 2026-07-26 20:39:06 UTC.
This automated status or its linked feedback items may be incorrect. If something looks wrong, please report it with the result you expected. |
Add comprehensive test suite for GenAiRetrievalAttributesExtractor covering attribute extraction with and without query text, and handling of null values. Update span naming documentation to clarify that retrieval operations include the data source ID when available as per copilot feedback.
|
|
||
| /** Returns the value of {@code gen_ai.agent.name}. */ | ||
| @Nullable | ||
| String getAgentName(REQUEST request); |
There was a problem hiding this comment.
#15268 used getName. Both db and http getters also add Db and Http respectively to the method names so adding Agent here aligns with them. An alternative would be getGenAiAgentName but that might be too much.
There was a problem hiding this comment.
Yeah I spent ton of time trying to come up with a good name and landed on this one as it adds more clarity. I am not keen on getName as it's not intuitive.
There was a problem hiding this comment.
I am fine with renaming it to getGenAiAgentName if you feel it's more readable and clear.
Summary
Extends GenAI support in
instrumentation-api-incubatorwith operation types from the newhttps://github.com/open-telemetry/semantic-conventions-genai repo, following the direction of #15268.
Adds
GenAiOperationAttributesGetter, a shared parent interface exposinggetOperationNameand getOperationTarget.GenAiSpanNameExtractornow uses this interface to build<operation_name>span names across GenAI span types. The getter is the single source of truth for the operation name, keeping span names aligned withgen_ai.operation.name. Targets follow the spec: request model for inference,gen_ai.agent.namefor create/invoke agent,gen_ai.tool.nameforexecute_tool, andgen_ai.data_source.id` for retrieval.Adds getter/extractor pairs for agent, tool, and retrieval spans:
gen_ai.agent.id,gen_ai.agent.name,gen_ai.agent.description,gen_ai.agent.versiongen_ai.tool.name,gen_ai.tool.description,gen_ai.tool.type,gen_ai.tool.call.idgen_ai.data_source.id, withgen_ai.retrieval.query.textbehind an explicitcaptureMessageContentopt-in because it may contain sensitive dataAdds inference attributes to the existing extractor:
gen_ai.provider.name,gen_ai.conversation.id,gen_ai.output.type, andgen_ai.request.choice.count(only emitted when the value is not
1, per semconv guidance).Renames the provider getter from
getSystemtogetProviderName.getProviderNameis now theabstract member, and
getSystemremains as a deprecated default delegating to it for themigration period. Bedrock and OpenAI chat/embeddings implementations are updated.
Notes for reviewers
// copied from GenAiIncubatingAttributes, matching the existing convention in this module. We avoid a production dependency onopentelemetry-semconv-incubating; a future PR can switch to the separate GenAI Java semconv artifact once it is published. I am going to work with @trask and update the dependency when a jar is published from the new genai semconv repository.GenAiAttributesGettermust implementgetProviderName, andGenAiSpanNameExtractor.createhas a binary-incompatible signature change because it now accepts the parent interface.gen_ai.provider.name; the surrounding instrumentor is expected to attach provider identity, matching Migrate generative AI semantic conventions to OTel 1.37.0 #15268.Out of scope
invoke_workflowoperationsValue<?>-typed opt-in content attributes such asgen_ai.input.messagesandgen_ai.retrieval.documentsGenAiInstrumenterFactoryconvenience buildersemconv-genaiJava artifactCC: @trask @Cirilla-zmh