Skip to content

feat(util-genai): event log → trace converter, passthrough & total_tokens#55

Merged
fangxiu-wf merged 2 commits into
mainfrom
feat/util-genai-event-log-to-trace
Jul 14, 2026
Merged

feat(util-genai): event log → trace converter, passthrough & total_tokens#55
fangxiu-wf merged 2 commits into
mainfrom
feat/util-genai-event-log-to-trace

Conversation

@fangxiu-wf

Copy link
Copy Markdown
Collaborator

Summary

Introduces the event log → OTel span tree converter for @loongsuite/otel-util-genai (published as 0.1.0-beta.9), turning loongsuite-pilot event logs into ARMS GenAI-compliant traces. This is the first time the converter lands in the repo (previously the package only shipped the handler/span utilities).

  • Converter: convertEventLogToTrace / convertEventLogToReadableSpans rebuild ENTRY→AGENT→STEP→LLM/TOOL span trees from flat event logs; honor upstream trace_id / parent_span_id, response.id merge, and 1-level subagent nesting.
  • Common attributes: gen_ai.agent.name / gen_ai.user.id / gen_ai.session.id written on every span kind.
  • ConvertOptions.passthroughKeys: allowlist to copy custom event fields onto spans — turn-level broadcast + LLM/TOOL per-record override, fill-only so converter-managed attributes are never overwritten.
  • gen_ai.usage.total_tokens: now prefers the upstream-reported value; falls back to input + output only when absent or unusable (incl. total=0 guard). AGENT aggregation only sums reported totals when every token-bearing response reports one, else falls back.
  • Package renamed to @loongsuite/otel-util-genai; docs updated; adds EVENT_LOG_TO_TRACE_SPEC.md.

Test plan

  • npm run build (tsc) — clean
  • npm test — 18 files / 203 tests passing (incl. new passthrough.test.ts, total-tokens.test.ts)
  • npm publish --dry-run — tarball contains only dist/** + LICENSE + README
  • Downstream: wire passthroughKeys in loongsuite-pilot (separate change)

🤖 Generated with Claude Code

fangxiu-wf and others added 2 commits July 9, 2026 14:32
…l_tokens

Introduce the event log → OTel span tree converter for
@loongsuite/otel-util-genai (published as 0.1.0-beta.9), turning
loongsuite-pilot event logs into ARMS GenAI-compliant traces.

- convertEventLogToTrace / convertEventLogToReadableSpans: rebuild
  ENTRY→AGENT→STEP→LLM/TOOL span trees from flat event logs; honor upstream
  trace_id / parent_span_id, response.id merge, and 1-level subagent nesting.
- ARMS GenAI common attributes (agent.name / user.id / session.id) on every span.
- ConvertOptions.passthroughKeys: allowlist to copy custom event fields onto
  spans (turn-level broadcast + LLM/TOOL per-record override, fill-only so
  converter-managed attributes are never overwritten).
- gen_ai.usage.total_tokens now prefers the upstream-reported value and falls
  back to input+output only when absent or unusable (incl. total=0 guard).
- Rename package to @loongsuite/otel-util-genai; update docs and add
  EVENT_LOG_TO_TRACE_SPEC.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
CI's `npm audit --audit-level=high` failed on vite 8.0.x (GHSA-fx2h-pf6j-xcff,
GHSA-v6wh-96g9-6wx3), pulled transitively via vitest. `npm audit fix` bumps
vite to 8.1.4 (lockfile-only, non-breaking). Remaining advisories are moderate
(@opentelemetry/core via optional sdk-trace-base) and do not fail the gate.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@fangxiu-wf fangxiu-wf merged commit e499730 into main Jul 14, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant