Repository navigation
Description
Context & Rationale
SpanHandle.record_llm_metrics (telemetry/tracer.py:436-471) says it records "standard OpenTelemetry GenAI attributes" (:450), but it names no convention and nothing checks it. At ef21785, src/ holds 36 distinct gen_ai.* string literals: 34 attribute keys and two span names, gen_ai.chat (ai/client/unified.py:683) and gen_ai.stream (:783). Emitters:
ai/client/unified.py:64-103,360-375,455,485-494,556-558,682-690,759,782-810,850ai/client/structured.py:238-243ai/direct.py:105,150,195,228telemetry/tracer.py:451-471
The GenAI conventions now live in open-telemetry/semantic-conventions-genai. It has no tagged release (0 tags on 2026-10-01; HEAD b31e9e8, 2026-09-30). Its model/gen-ai/registry.yaml defines 79 attribute keys, and model/gen-ai/metrics.yaml defines metric names under the same prefix, such as gen_ai.client.operation.duration (:21). Its model/manifest.yaml depends on core semantic-conventions v1.44.0, which defines server.address and server.port. Our 34 keys compare to the registry as follows:
- 8 are current:
operation.name,request.model,request.temperature,request.top_p,response.finish_reasons,response.model,usage.input_tokensandusage.output_tokens. - 3 were renamed:
gen_ai.systemis nowgen_ai.provider.name, andgen_ai.usage.prompt_tokensandgen_ai.usage.completion_tokensare nowinput_tokensandoutput_tokens. - 23 are private keys in the convention's namespace, such as
gen_ai.request.priority,gen_ai.ttft_secondsandgen_ai.usage.cost_usd. gen_ai.provider.nameis never emitted (grep -rn gen_ai.provider.name src: 0). The inference span requires it (spans.yaml:171,gen_ai.inference.client, and:260-262).
The installed opentelemetry-semantic-conventions 0.65b0 is not a usable oracle. It comes in through opentelemetry-sdk and is not declared in pyproject.toml. It defines 11 of our 34 keys and marks all 11 deprecated: 3 renamed and 8 "moved to the GenAI repository". It is also behind the GenAI repository. For example, it still lists gen_ai.usage.cache_creation.input_tokens, which the GenAI registry now names gen_ai.usage.cache_write.input_tokens (registry.yaml:308).
Weaver v0.26.1 is the version the GenAI repository pins (versions.env). weaver registry resolve is deprecated there ("use 'weaver registry generate' or 'weaver registry package' instead", docs/usage.md:60-61). weaver registry package needs the registry's manifest.yaml and writes resolved.yaml and manifest.yaml to its output directory (src/registry/package.rs:146-147). PyYAML is already a pinned dependency (pyproject.toml:21).
Some keys are written twice, and some values are wrong:
- Old and new token keys are written together (
tracer.py:457-462,unified.py:92-97). Two token-rate keys are also written together (tracer.py:469-471,unified.py:70-75). gen_ai.server.addressholds thebackend_infodisplay string, such asollama (localhost:11434), not a host (unified.py:87)._extract_server_from_backend_info(unified.py:55-61) returns the text inside the parentheses. That is a netloc such aslocalhost:11434, so the port still has to be split off. On the stream path it readsself.backend_info(:831), which lists every configured Ollama host, comma-joined (:255).gen_ai.response.modelholdsbackend_infoon the wrapper span (unified.py:487) or the literal"cache"(:556). The inference span already writesres.model(:91), which comes from the provider's reply (ollama.py:380,claude.py:117,openai.py:150).- Every LLM span is INTERNAL, the
trace_spandefault (tracer.py:1377). The convention's inference span is CLIENT, andtracer.py:132-137already supportsclient. record_llm_metricshas no caller insrc/. Onlytests/test_telemetry.py:268-302,579-598call it, and:295-302pin the renamed and private keys as "GenAI standard attributes".- The chat-path test stub (
tests/test_ai_request_priority.py:185) returns no token counts and abackend_infowith no port, so today no test sees usage keys or a port on an LLM span.
Logfire: instrument_pydantic_ai() (telemetry/logfire.py:217) turns on pydantic-ai's instrumentation. Pydantic-ai writes gen_ai.provider.name and still writes gen_ai.system beside it (pydantic-ai 2.35.0, _instrumentation.py:287-288). Its spans are bridged into the same internal span buffer as our own spans (LogfireOTelBridgeProcessor, logfire.py:39-86). Nothing calls the pydantic-ai paths (ai/direct.py) at runtime yet (see #606), so the clash between the two vocabularies is latent, not live.
Nothing outside tests reads these keys. grep -rn gen_ai k8s docs/TELEMETRY.md finds nothing. docs/ROADMAP.md and the task files for #588, #590, #598, #599 and #606 mention them only as planning text. Tests read them in tests/test_telemetry.py and tests/test_ai_request_priority.py:202. tests/test_pydantic_ai_result.py:65-66 reads pydantic-ai's own RunUsage keys, which this item does not change. Hand-written mappings like _ATTRIBUTE_NORMALIZATION (tracer.py:668-689, no GenAI entries) are how the keys drifted. vibes hit the same defect (observations/systems/19-self-consistency-is-not-conformance.md): every collector accepted its private vocabulary in a valid envelope, and no GenAI-aware backend could chart it. vibes fixed it with a snapshot pinned to a commit (tools/semconv_snapshot.py).
Scope & Deliverables
Deliverable: one PR that does three things. It pins the GenAI conventions, checks every gen_ai.* literal in src/ against them inside the gate, and renames the emitters so the check passes.
- Snapshot.
src/devops_cli/telemetry/semconv_genai.json, committed. It holds:source: the repo, a 40-hex commit and the weaver version;attributes: every non-deprecated attribute key in the resolved registry. That is thegen_ai.*keys plus the core keys the registry references, such asserver.address. The reducer does not filter by prefix;metrics: every non-deprecated metric name;spans: each span type's kind and required attributes.
Lists are sorted. Only this reduced table is committed, never raw weaver output.
- Refresh.
devops telemetry semconv refresh --commit <sha>runsweaver registry package --v2 -r https://github.com/open-telemetry/semantic-conventions-genai.git@<sha>[model] -o <tmp>. It reads<tmp>/resolved.yamlwith PyYAML, reduces it and rewrites the snapshot. The weaver call uses an argument list and a bounded timeout. It writes nothing and exits non-zero whenweaveris not on PATH, when--commitis not a 40-hex SHA, or when weaver fails or times out. A person runs it; the gate never does. - Check. A test in the gate reads the raw text of
src/devops_cli/**/*.py, comments and docstrings included. It finds quoted strings that start withgen_ai.. It fails, namingfile:line, on any that is not a current attribute key or metric name in the snapshot, and on any f-string that starts withgen_ai.(a dynamic key). - Rename, with no key written twice. Apply the table below.
- Delete
record_llm_metrics. _set_response_span_attributes(unified.py:84, called at:427) becomes the only writer ofgen_ai.usage.*,gen_ai.response.modelandgen_ai.response.finish_reasons, and it writes them only onai.llm.dispatch. On the stream span,_record_first_token(:752-760) writesgen_ai.response.time_to_first_chunk._record_chat_telemetry(:485) keeps onlyllm.cached,llm.wall_secondsandllm.processing_secondson its wrapper span, so a request's usage is counted once.
- Delete
- Inference spans. Create
ai.llm.dispatch(unified.py:377) and the stream span withkind="client".- Both carry
gen_ai.operation.name="chat",gen_ai.provider.nameandgen_ai.request.model. server.addressis the host part of the netloc.server.portis set when the netloc has a port. Neither is set when the backend lists several hosts or iscache.- The stream span also carries
gen_ai.request.stream=trueandgen_ai.response.time_to_first_chunk.
- Both carry
- Docs.
- Add a short "LLM span attributes" section to
docs/TELEMETRY.md. It names the pinned commit, thellm.*prefix for private keys and the refresh command. - Add a CHANGELOG entry that lists every old key and its new name, so people can update external queries.
- Rewrite the task file
docs/agent/tasks/task-588-*.mdto match this body. It still says v0.2.24 and two PRs.
- Add a short "LLM span attributes" section to
Rename table (proposed):
| Today | Becomes |
|---|---|
gen_ai.system |
gen_ai.provider.name: claude becomes anthropic; other provider ids are unchanged |
gen_ai.usage.prompt_tokens, gen_ai.usage.completion_tokens |
removed; only gen_ai.usage.input_tokens and gen_ai.usage.output_tokens remain |
gen_ai.usage.total_tokens |
removed (it is input plus output) |
gen_ai.server.address (holds backend_info) |
server.address (host) and server.port (int), split from the netloc that _extract_server_from_backend_info returns, for example with urllib.parse.urlsplit("//" + netloc) |
gen_ai.response.model = backend_info or "cache" |
gen_ai.response.model = res.model when known, otherwise unset |
gen_ai.ttft_seconds, gen_ai.time_to_first_token_ms |
gen_ai.response.time_to_first_chunk (seconds) |
gen_ai.tokens_per_second, gen_ai.token_rate_tok_per_sec |
llm.tokens_per_second |
gen_ai.wall_seconds, gen_ai.processing_seconds |
llm.wall_seconds, llm.processing_seconds (already used, unified.py:79-81) |
gen_ai.duration_seconds |
removed with record_llm_metrics |
gen_ai.server.served_by |
llm.served_by |
gen_ai.usage.cost_usd |
llm.usage.cost_usd |
gen_ai.cached |
llm.cached |
gen_ai.request.priority |
llm.request.priority |
gen_ai.request.enable_thinking, gen_ai.enable_thinking |
llm.request.enable_thinking |
gen_ai.request.message_count, gen_ai.messages_count |
llm.request.message_count |
gen_ai.request.system_prompt_length |
llm.request.system_prompt_length |
gen_ai.prompt_preview, gen_ai.response_preview |
llm.prompt_preview, llm.response_preview |
gen_ai.thinking |
llm.response.thinking |
gen_ai.sanitize |
llm.stream.sanitize |
gen_ai.stream_chunks_count |
llm.stream.chunk_count |
span gen_ai.chat, span gen_ai.stream |
ai.llm.chat, ai.llm.stream |
Acceptance criteria:
- Snapshot shape.
source.repoisopen-telemetry/semantic-conventions-genai,source.commitis 40 hex characters andsource.weaveris set.attributesincludesgen_ai.provider.name,gen_ai.response.time_to_first_chunkandserver.address, and excludesgen_ai.system.metricsincludesgen_ai.client.operation.duration.spans["gen_ai.inference.client"]has kindclient, and its required list includesgen_ai.operation.nameandgen_ai.provider.name. Verified by a unit test with tuple assertions. - Reducer. It is fed a trimmed
resolved.yamlthat the PR author produced once withweaver registry package --v2(weaver v0.26.1), committed undertests/fixtures/. The fixture holds at least one deprecated attribute and one deprecated metric. The reducer drops both, returns sorted output and gives identical bytes on two runs. Verified by a unit test that starts no subprocess and makes no network call. - Refusal. In each of these cases,
refreshexits non-zero with a message naming the cause and leaves the snapshot unchanged:shutil.which("weaver")is monkeypatched to returnNone;--commit mainis passed;- a stubbed weaver run fails;
- a stubbed weaver run times out.
Verified by CLI-runner unit tests.
- Check. The scan test passes on the PR. Given a
tmp_pathsource, it fails and namesfile:linefor each of"gen_ai.system",f"gen_ai.{x}"and a comment# was "gen_ai.system". It passes for"gen_ai.client.operation.duration". Verified by unit tests. The scan oversrc/takes under 1 s, measured withpytest --durations. - Inference spans. Both tests capture the OTLP payload by patching
_send_payload, astests/test_ai_request_priority.py:168-170does, and assert with tuples.- Chat. Drive
LLMClient.chatwith_ollama_messagesstubbed (as intests/test_ai_request_priority.py:166-202) to returnLLMResponse("OK", backend_info="ollama (example.com:11434)", model="test-model", prompt_tokens=12, completion_tokens=3, total_tokens=15). Assert thatai.llm.dispatchisSPAN_KIND_CLIENTand carries every attribute the snapshot lists as required forgen_ai.inference.client. Assert that its (server.address,server.port,gen_ai.usage.input_tokens,gen_ai.usage.output_tokens,gen_ai.response.model) equal ("example.com", 11434, 12, 3,"test-model"). Assert thatai.llm.chatisSPAN_KIND_INTERNALand has no key that starts withgen_ai.usage.orgen_ai.response.. - Stream. Drive
chat_messages_streamwith_dispatch_streamstubbed and one Ollama URL,http://example.com:11434. Assert thatai.llm.streamisSPAN_KIND_CLIENT, carries every required attribute, has (server.address,server.port) equal to ("example.com", 11434), hasgen_ai.request.streamset to true and hasgen_ai.response.time_to_first_chunkas a float. With two Ollama URLs configured, assert thatserver.addressandserver.portare absent.
- Chat. Drive
- Removed code.
grep -rn record_llm_metrics src testsfinds nothing.tests/test_telemetry.py:268-302,579-598are deleted or rewritten against_set_response_span_attributes, andtests/test_ai_request_priority.py:202assertsllm.request.priority. These test changes land in the same commit as the code. Verified by grep anduv run devops ci. - Gate.
uv run devops cipasses. That includesdocs checkwith the CLI reference regenerated fordevops telemetry semconv refresh. The new tests add under 1 s in total, measured withpytest --durations. - Person-run check (needs network and weaver v0.26.1 on PATH). Run
uv run devops telemetry semconv refresh --commit "$(jq -r .source.commit src/devops_cli/telemetry/semconv_genai.json)", thengit diff --exit-code src/devops_cli/telemetry/semconv_genai.json. It shows no change. - Docs.
docs/TELEMETRY.mdhas the new section, the CHANGELOG lists each old key and its new name, and the task file matches this body. Checked in review.
Key questions:
- What is the oracle? The GenAI repository at a pinned commit, resolved by weaver. Not the installed package: it marks every key it has as deprecated, and it is behind the GenAI repository (
cache_creationversuscache_write). (proposed) - Which weaver command?
weaver registry package --v2, readingresolved.yamlfrom its output directory.weaver registry resolve, which the earlier draft named, is deprecated (weaver PR feat(release): v0.2.27 #1255;docs/usage.md:60-61at v0.26.1). If weaver cannot fetch a bare SHA through.git@<sha>[model], use the GitHub archive URL for that SHA, which weaver also accepts. (proposed) - Weaver on PATH only, or also the
otel/weaverimage? PATH only, refusing otherwise with the release URL. Refresh is rare and run by a person, and one way of running it is simpler to test. Upstream pins v0.26.1 (versions.env), and the snapshot records the version used. (proposed) - Which commit to pin first? GenAI repository HEAD when the PR is built (
b31e9e8on 2026-09-30), not vibes' older8ffdf568. (proposed) - A separate
devops civerify step, or a pytest test? A pytest test. A new step would start the CLI, which costs about 5 to 6 s CPU cold on this checkout (devops telemetry --help), against the 5-minute budget. A regex over the 484 source files takes about 0.06 s, or under 0.6 s including interpreter start. Parsing every file withasttook 1.5 to 7.4 s across runs under load, so the test uses a regex. (proposed) - Should the snapshot carry renamed-key hints? No. The check needs only membership in the current key set. "Moved" keys are current in the GenAI repository, so they pass without a special rule, and renamed keys fail. vibes found that 58 of 60 upstream deprecations say
reason: uncategorized, so hints would need prose parsing. The rename table above covers today's keys. (proposed) - Write usage through pydantic-ai's
RunUsage.opentelemetry_attributes()? No, for three reasons. It writesgen_ai.usage.cache_creation.input_tokens(pydantic-ai 2.35.0,usage.py:228), which the GenAI registry no longer defines. It drops zero counts. And keys written inside a dependency are invisible to thesrc/scan. Write the two token keys directly. (proposed) - Where do the private keys go? Under
llm.*, the prefix this code already uses for private timing keys (unified.py:67,77,79,81). OTel defines nollmnamespace; 0.65b0 has nollm.*attribute. (proposed) - Adopt the convention's
{operation} {model}span name? No. Keep fixed names outsidegen_ai.; the operation travels ingen_ai.operation.nameand the CLIENT kind. Fixed names keep lookups such astests/test_ai_request_priority.py:196stable. Only the two spans that make the request are inference spans. The wrapper spans (ai.llm.chat,ai.client.chat_structuredandpydantic_ai.direct.*) stay INTERNAL and do not setgen_ai.operation.name, so each call is counted once. (proposed) - Which
gen_ai.provider.namevalues? Mapclaudetoanthropic. That is the convention's well-known value (registry.yaml:29-32), it is what pydantic-ai writes, and the convention refines the inference span for it (anthropic.inference.client, a span refinement atspans.yaml:842). Passollama,openai,gateway,copilotandgithub_copilotthrough unchanged; the convention allows custom values. The existingproviderattribute (unified.py:369) keeps our own id. (proposed) - Wire up
record_llm_metricsor delete it? Delete it. It has no caller, and before 1.0 the codebase keeps no shims. This also settles the same sub-task in feat(ai): ollama model residency per-pod model budget, keep-alive, ms/token #598. (proposed) - Fix
gen_ai.response.finish_reasons, which is hard-coded to["stop"](unified.py:101), here? No. feat(ai): finish reasons and stream completeness for model replies #599 (v0.2.25) reads real finish reasons. The key itself is current, so the check passes. (proposed) - Declare
opentelemetry-semantic-conventionsinpyproject.toml? No. Nothing imports it, andserver.addressandserver.portare written as literals. (proposed) - Do GenAI metrics (
gen_ai.client.token.usage,gen_ai.client.operation.duration) belong here? No; this item covers span attributes only. The snapshot does list the convention's metric names, so a metric named from it passes the check. feat(ai): ollama model residency per-pod model budget, keep-alive, ms/token #598 adds a time-per-output-token histogram named from the convention. (proposed) - Who reads the old keys? Nothing outside tests:
k8s/,docs/TELEMETRY.mdand the dashboards have 0 hits. External saved queries in Jaeger or Logfire will break, and the CHANGELOG entry lists every rename. (proposed) - Do comments and docstrings count in the scan? Yes. The regex reads raw text, and old names belong only in the CHANGELOG. This keeps the scan to one rule with no exemptions. (proposed)
- What if the netloc has no port, as for
api.anthropic.com? Leaveserver.portunset.backend_infodrops the URL scheme, so a default port would be a guess. The convention makesserver.portconditionally required whenserver.addressis set, so this is a known gap for default-port endpoints; carrying the scheme inbackend_infois out of scope. (proposed)
Constraint:
- The check has no allowlist, prefix exemption or "known violations" list. A hand-written table is how these keys drifted.
- An old key is never kept beside its replacement.
- Tests never touch the network and never run weaver. Only a person runs refresh.
- The weaver call uses an argument list and a bounded timeout (
AGENTS.md:43). - New tests use structural tuple assertions (until test(cli): retire the tuple-assert mandate and detect opaque tuple asserts and presence-only tests #851 settles that) and add at most 1 s to the gate.
Strategic Alignment
- Milestone: v0.2.25
- Depends on: none.
- Related:
- feat(ai): finish reasons and stream completeness for model replies #599 (v0.2.25) edits the same functions (
_set_response_span_attributesand the stream span). Either can land first. If this item lands first, the gate checks feat(ai): finish reasons and stream completeness for model replies #599's new attributes. - feat(ai): model prompt and reply text kept out of telemetry by default #606 (backlog) puts the previews behind a setting; this item renames them to
llm.prompt_previewandllm.response_preview. - feat(cli): thinking-stream sanitizer initial state, unopened-tag count and thought cap #590 (backlog) adds counters to the stream span, which this item renames to
ai.llm.stream. Those counters belong underllm.*. - feat(cli): reasoning-token share in the spend ledger and provider-reported stream usage #591 (backlog) adds reasoning tokens.
gen_ai.usage.reasoning.output_tokensis a current key. - feat(ai): ollama model residency per-pod model budget, keep-alive, ms/token #598 (backlog): its "wire or delete
record_llm_metrics" step is settled here. Its histogram name passes the check because the snapshot lists the convention's metric names. - Source: vibes
tools/semconv_snapshot.py,examples/agent-telemetry-trace-generator/semconv_genai.json(snapshot shape) andobservations/systems/19-self-consistency-is-not-conformance.md.
- feat(ai): finish reasons and stream completeness for model replies #599 (v0.2.25) edits the same functions (
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 1, 2026
Retargeted from the shipped v0.2.23 to v0.2.25. It is still valid (checked 2026-10-01), and a P1 left open in a shipped release keeps precedence over P1 work committed later.
feat(cli): genai span attributes checked against the pinned semantic …
dan-petty commentedon Oct 2, 2026
Closed by #941, merged into
release/v0.2.25.GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by
devops gh issues close-merged.feat(release): v0.2.25 (#1089)