Skip to content

feat(proxy): expanded fields and new usage events (OTLP analytics pipeline) - #609

Merged
codemie-ai merged 42 commits into
codemie-ai:mainfrom
dzhalai:EPMCDME-15301_stage-1-1
Oct 13, 2026
Merged

codemie-ai merged 42 commits into
codemie-ai:mainfrom
dzhalai:EPMCDME-15301_stage-1-1

Conversation

@dzhalai

@dzhalai dzhalai commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends the claude-code-otlp analytics pipeline with common fields on every agent.* event, incremental persisted transcript parsing, and three new usage events, plus story/identity resolution. Additive only — no changes to existing event content, no server-side changes.

Changes

  • Common fields (schema_version, event_id, codemie_cli_version, platform, client_version, entrypoint) stamped on every event via forwarder.ts + new OtlpAgentAdapter.prepareAnalyticsFields().
  • New agent.usage.request, agent.subagent.usage, agent.session.summary events, derived by incremental transcript re-parsing on Stop/SubagentStop/PreCompact/SessionEnd, backed by persisted per-session parse state (src/agents/plugins/claude-code-otlp/transcript/*).
  • 4-tier identity resolution (jwt → git → codemie_cli → os) and story/ticket resolution (explicit → marker → branch → mention), new modules under otlp-spool/.
  • Added docs/ARCHITECTURE-OTLP-PLUGIN.md; full unit test coverage for all new modules (this pipeline previously had none).

Impact

  • No breaking changes; existing 13 agent.* events keep their content, only gain the common fields.
  • Identity-chain CRITICAL security finding (CR-023) reviewed and signed off: used only for analytics developer_name/identity_source, never SSO/billing/attribution headers.

Checklist

  • Self-reviewed
  • Manual testing performed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)

Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forwarder.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forwarder.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forwarder.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forwarder.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forwarder.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forwarder.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forward-context.ts Outdated
Comment thread src/agents/plugins/claude-code-otlp/claude-code-otlp.plugin.ts Outdated
Comment thread src/agents/plugins/claude-code-otlp/claude-code-otlp.plugin.ts Outdated
Comment thread src/agents/plugins/claude-code-otlp/transcript/orchestrator.ts
Comment thread src/agents/plugins/claude-code-otlp/claude-code-otlp.plugin.ts Outdated
Comment thread src/agents/plugins/claude-code-otlp/claude-code-otlp.plugin.ts Outdated
Comment thread src/providers/plugins/sso/proxy/plugins/otlp-spool/forward-context.ts Outdated
Comment thread src/agents/plugins/claude-code-otlp/claude-code-otlp.plugin.ts Outdated
dzhalai and others added 15 commits October 7, 2026 09:55
Replace the mixed if/switch dispatch with one if-chain and one handler
per hook event, each returning its own ForwardDecision directly. Drop
the shared fallback sink, collapse the raw/parsed object duplication by
extending BaseClaudeCodeHookEvent, rename the orchestrator collectors,
and split client-version caching from resolution.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Add docs/ARCHITECTURE-OTLP-PLUGIN.md: the agent-agnostic
OtlpAgentAdapter contract, the evaluate()/ForwardDecision dispatch
pattern, how to add a new hook event or a new adapter, and the current
otlp-spool completeness-gating/draining behavior (with planned
extensions clearly flagged as not-yet-implemented). Index it from
AGENTS.md's Agent Plugins table and add a top-level OTel (OTLP)
Ingestion section pointing new contributors at it.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
@dzhalai
dzhalai force-pushed the EPMCDME-15301_stage-1-1 branch from e9d0083 to 93512cf Compare October 7, 2026 07:31
vld-m and others added 25 commits October 7, 2026 13:12
Analytics forwarding hooks no longer block Claude Code. UserPromptSubmit
stays synchronous so its SSO-gate block decision reaches Claude Code
before the prompt proceeds.
…rwarding

mapHookRecords overwrote the record's own timestamp and git_branch with the
spool-write time and the daemon's cwd branch, so every request in a hook pass
collapsed to one moment and carried the wrong branch. Prefer the event's own
values and fall back only when they are missing, empty or unparseable.

Generated with AI
Move git_branch, repo_remote, story_id and story_source resolution from
the proxy-daemon forwarder into an abstract OtlpAgentAdapter that runs
at
hook time. The daemon env is frozen at spawn, so env-dependent fields
such
as SDLC_ANALYTICS_STORY_ID were read from the wrong process.

- add OtlpAgentAdapter<TInput, TBlockOutput> with a fixed
  processOtlpEvent
  flow and a generic ForwardDecision
- inject forwardOtlpEventToSpool via OtlpAdapterDeps
- move story-resolver to agents/core and add resolveStoryFor
- make the forwarder pass the four fields through from the record
- migrate ClaudeCodeOtlpPlugin to the base class
- update tests and OTLP architecture docs

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
the adapter

The abstract OtlpAgentAdapter now produces the complete event at hook
time: type, truncation,
prompt_body, session_id, cwd, schema_version, event_id, timestamp, plus
identity, project name and
CLI version resolved for the hook cwd from the stored SSO credentials.
Events are sent awaited and
in order. The forwarder only unwraps the spool envelope, POSTs it as is,
advances the cursor and
retries on auth failure; session end is detected from the event type.

- rename OtlpHookSpoolData.raw to hookEvent and drop its timestamp
- move identity.ts to agents/core/identity-resolver.ts, add
  hook-credentials.ts
- remove forward-context.ts and the daemon-side CLI version lookup
- add abstract resolveEventType, rename resolveAgentCommonFields to
  resolveAgentFields
- update OTLP and proxy architecture docs
…tics contract

request_id is now the API request id (top-level requestId, empty when the
transcript has none) and message_id carries message.id. Requests are grouped
by requestId, else message.id, plus model, through a single usageRequestKey
helper. This lets the backend pair direct Claude Code requests with their
OTel api_request records instead of counting them twice.

Generated with AI
Derive the summary fields the backend reads only from the summary once one
exists, instead of sending null, omitting them or sending the wrong shape:

- lines_added/lines_removed from applied edit diffs (null until measured)
- commands in call order with repeats; primary_command is the first
- turns from real user prompts
- compactions, compaction_count and compaction_pre_tokens from
  compact_boundary lines (replaces the PreCompact hook counter)
- client_versions, git_branch and title (latest ai-title)
- branch_counts count user lines only; branch_dominant ties go to the later branch

Generated with AI
…-code-otlp

Fills agent.subagent.usage's worktree from the triggering hook's cwd, threads
agent_type through agent.usage.request end to end, tracks a Skill tool_use as
a scope_kind='skill' context (cleared on the next genuine user turn), counts
MultiEdit/NotebookEdit toward files_edited/files_changed, and rejects an
empty or path-traversing session_id before it ever reaches a filesystem path.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>

@vld-m vld-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codemie-ai
codemie-ai merged commit e0f79aa into codemie-ai:main Oct 13, 2026
5 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.

3 participants