feat(openclaw): custom SpanProcessor injection + fix runaway ENTRY/AGENT span durations#56
Merged
fangxiu-wf merged 3 commits intoJul 14, 2026
Conversation
…ENT span durations 新增: - 自定义 SpanProcessor 注入:配置项 spanProcessorModule / 环境变量 ARMS_SPAN_PROCESSOR_MODULE。 通过包子路径导出 defineGenAiSpanProcessor helper,按 GenAI span 类型分派并屏蔽语义规范方言差异; 加载/校验失败优雅降级到内置 processor,用户回调全程 try/catch 隔离,绝不影响内置导出管道。 - ENTRY span 诊断属性 openclaw.trace.close_reason(normal / runid_recovered / stale_sweeper), 便于在 ARMS 中定位异常关闭的调用链。 修复: - 跨天巨长 ENTRY/AGENT span(时长被拉到 1d+):agent_end 仅按 channel 归属 context,当其 channel 与 llm_input 注册的 channel 不一致时关不掉本轮 span 导致泄漏,后续某次 agent_end 或会话 reset 时以 Date.now() 误关产生天级时长。主修:channel 解析不到可关 span 时用 openclaw 附带的 runId 兜回本轮 context(channel 优先、runId 补充,不改动常见路径)。加固:过期上下文清扫器对仍开放的 ENTRY/AGENT/STEP span 用有界最后活动时间强制关闭,并彻底清理所有查找结构。 - 工具 span 因 channel 错配被静默丢弃:before_tool_call 在 agent/ 通道无锚点时用 runId 兜回 context 恢复工具 span,并对 runId==sessionId 且上下文正在关闭的场景加守卫,避免挂到上一轮 trace。 版本 bump 0.1.5-beta;新增 span-processor / channel-mismatch-repro / agent-end-stale-close 单元测试。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Previously the sweeper's forceFlush error was silently swallowed, hiding export-pipeline faults. Log it at warn level when debug is enabled. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #54
Summary
Two changes to
opentelemetry-instrumentation-openclaw, released together as0.1.5-beta.Feature — custom SpanProcessor injection
spanProcessorModule(env fallbackARMS_SPAN_PROCESSOR_MODULE): points at a module whose default export is aSpanProcessor. Absolute paths as-is; relative resolved againstOPENCLAW_HOME(~/.openclaw).@loongsuite/opentelemetry-instrumentation-openclaw/span-processorprovidesdefineGenAiSpanProcessor, dispatching by GenAI span kind (onLlmEnding/onToolEnding/onAgentEnding/onStepEnding/onEntryEnding) and hiding semconv dialect differences.globalSpanAttributesonly supports static values.Fix — runaway ENTRY/AGENT span durations (seen as 1d+ traces)
agent_endattributed context purely by channel. When its channel differs from the onellm_inputregistered (system/ vs agent/ mismatch), it failed to find the turn's context and closed nothing, leaking the open ENTRY/AGENT spans. A lateragent_end(or session reset) then mis-closed them withDate.now(), producing day-long durations.runIdopenclaw attaches toagent_end(channel-first, runId as supplement — the common path is unchanged).Date.now()) and fully cleans up all lookup structures.before_tool_callrecovers viarunId, with a guard for therunId==sessionIdclosing-turn case).openclaw.trace.close_reason∈ {normal,runid_recovered,stale_sweeper}.Test plan
tsc --noEmitcleanspan-processor.test.ts(dispatch / dialect tolerance / graceful degradation / runtime isolation),channel-mismatch-repro.test.ts(tool-span recovery),agent-end-stale-close.test.ts(agent_end runId recovery + sweeper bounded force-close)close_reason=normalwith sane second-level ENTRY/AGENT durations and intact hierarchy (no regression); a custom SpanProcessor was injected and confirmed to addbusiness.*attributes onto LLM/ENTRY/TOOL spans in ARMS.🤖 Generated with Claude Code