Add reasoning, continuation, compaction, prompt attributes, and retrieval top_k - #614
Add reasoning, continuation, compaction, prompt attributes, and retrieval top_k#614lmolkova wants to merge 5 commits into
Conversation
Pull request dashboard statusWaiting on maintainers · refreshed 2026-09-05 01:26 UTC Merge when ready. Status above doesn't look right?
|
There was a problem hiding this comment.
🟡 Changes recommended
Request attributes must be available when spans start so head samplers can inspect them.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Aligns inference and retrieval telemetry attributes with GenAI semantic conventions.
Changes:
- Adds reasoning, continuation, compaction, and prompt attributes.
- Migrates retrieval
top_kto an integer attribute. - Adds tests and changelog entries.
File summaries
| File | Description |
|---|---|
util/opentelemetry-util-genai/tests/test_utils.py |
Tests new inference attributes. |
util/opentelemetry-util-genai/tests/test_handler_retrieval.py |
Tests integer retrieval top_k. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_retrieval_invocation.py |
Updates retrieval top_k telemetry. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py |
Implements new inference attributes. |
util/opentelemetry-util-genai/.changelog/614.changed |
Documents the retrieval attribute change. |
util/opentelemetry-util-genai/.changelog/614.added |
Documents the new inference attributes. |
Review details
Suppressed comments (3)
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py:303
gen_ai.prompt.variable.*is opt-in content and may contain sensitive data, but this loop records it regardless of the configured content-capture mode. In the defaultNO_CONTENTmode, the new test now exportsAliceanyway;EVENT_ONLYalso leaks the values onto the span. Gate these attributes independently for span versus event output, as_get_message_attributes(for_span=...)does, and test the disabled modes.
if self.prompt_variables:
for k, v in self.prompt_variables.items():
attrs[f"{_GEN_AI_PROMPT_VARIABLE_PREFIX}{k}"] = str(v)
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py:140
InferenceInvocationis exported fromopentelemetry.util.genai.invocation, so this introducesAnyinto a public field even though every accepted value is only passed tostr(). UseMapping[str, object]instead (and remove theAnyimport after updating both declarations) to preserve the accepted shapes without disabling type checking.
self.prompt_variables: Mapping[str, Any] | None = None
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py:415
LLMInvocationremains publicly exposed throughopentelemetry.util.genai.types, so this second public declaration also leaksAny. UseMapping[str, object]here as well and remove the now-unusedAnyimport.
prompt_variables: Mapping[str, Any] | None = None
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
a65b127 to
fa78469
Compare
39f59a3 to
5fd24ef
Compare
What does this change do?
Adds support for reasoning level, continuation, conversation compaction, and prompt template attributes to
InferenceInvocation, and updatesRetrievalInvocationto record integergen_ai.retrieval.top_k.Attributes added/updated
gen_ai.request.reasoning.level: Request reasoning effort/level.gen_ai.request.previous_response.id: Previous response ID for continuation requests.gen_ai.conversation.compacted: Flag indicating conversation history was compacted.gen_ai.prompt.name: Prompt template identifier.gen_ai.prompt.version: Prompt template version.gen_ai.prompt.variable.<key>: Prompt template input variables.gen_ai.retrieval.top_k: Integer top-k documents requested (replacesgen_ai.request.top_kon retrieval spans).Why?
Catches up with GenAI semantic conventions updates:
gen_ai.request.top_k(float) with dedicated integergen_ai.retrieval.top_kon retrieval spans.gen_ai.request.reasoning.levelfor reasoning models.gen_ai.request.previous_response.idfor multi-turn continuations.gen_ai.conversation.compactedfor compacted context.name,version, and dynamicvariable.<key>attributes).