feat(diagnostics-otel): add genai usage span identity

This commit is contained in:
Vincent Koc
2026-04-25 12:02:48 -07:00
parent 5eab16e086
commit 5671fdca87
3 changed files with 5 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ Docs: https://docs.openclaw.ai
kept as a deprecated compatibility fallback. Thanks @vincentkoc.
- Diagnostics/OTEL: add the GenAI `gen_ai.client.operation.duration` histogram for model-call latency in seconds with bounded provider/model/API and error attributes. Thanks @vincentkoc.
- Diagnostics/OTEL: add GenAI usage token attributes to model-usage spans, including cache read/write input token counts without session identifiers or prompt/response content. Thanks @vincentkoc.
- Diagnostics/OTEL: include bounded GenAI operation, provider, and request-model attributes on model-usage spans so token usage remains self-describing without diagnostic identifiers. Thanks @vincentkoc.
- Diagnostics/OTEL: add bounded outbound message delivery lifecycle diagnostics and export them as low-cardinality delivery spans/metrics without message body, recipient, room, or media-path data. (#71471) Thanks @vincentkoc and @jlapenna.
- Diagnostics/OTEL: emit bounded exec-process diagnostics and export them as `openclaw.exec` spans without exposing command text, working directories, or container identifiers. (#71451) Thanks @vincentkoc and @jlapenna.
- Diagnostics/OTEL: support `OPENCLAW_OTEL_PRELOADED=1` so the plugin can reuse an already-registered OpenTelemetry SDK while keeping OpenClaw diagnostic listeners wired. (#71450) Thanks @vincentkoc and @jlapenna.

View File

@@ -768,6 +768,9 @@ describe("diagnostics-otel service", () => {
);
expect(modelUsageCall?.[1]).toMatchObject({
attributes: {
"gen_ai.operation.name": "chat",
"gen_ai.provider.name": "anthropic",
"gen_ai.request.model": "claude-sonnet-4.6",
"gen_ai.usage.input_tokens": 150,
"gen_ai.usage.output_tokens": 40,
"gen_ai.usage.cache_read.input_tokens": 30,

View File

@@ -953,6 +953,7 @@ export function createDiagnosticsOtelService(): OpenClawPluginService {
(usage.input ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0);
const spanAttrs: Record<string, string | number> = {
...attrs,
...genAiAttrs,
"openclaw.tokens.input": usage.input ?? 0,
"openclaw.tokens.output": usage.output ?? 0,
"openclaw.tokens.cache_read": usage.cacheRead ?? 0,