Skip to content

feat(diagnostics): bundle diagnostics-otel by default, span pre-model setup, keep lane trace scope - #227

Merged
insomnius merged 7 commits into
boonfrom
feat/otel-turn-tracing
Sep 16, 2026
Merged

insomnius merged 7 commits into
boonfrom
feat/otel-turn-tracing

Conversation

@insomnius

@insomnius insomnius commented Sep 16, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Boon fleet gateways run Sentry only: no performance traces, so per-turn bottlenecks (pre-model setup, model latency, tool time, delivery) cannot be drilled into. Upstream already ships a diagnostics-otel plugin, but it is excluded from the npm package, so a fleet install cannot load it without a separate ClawHub/npm install step. Two gaps also limited what a trace would show even with the plugin on:

  • enqueueCommandInLane ran dequeued tasks from the previous task's promise continuation, so a task queued behind a busy lane inherited the earlier task's async context (diagnostic trace scope) instead of its enqueuer's. Proven at the primitive level (unit test + tsx experiment); gateway E2E runs did not reproduce it because per-session gates serialize turns upstream of the lane, so this is a defensive fix of the primitive rather than a fleet-observed merge.
  • openclaw.context.assembled was a zero-duration marker, leaving the time from run start to the first model call unattributed (13.8s on a cold turn in the local E2E).

Why This Change Was Made

  • src/process/command-queue.ts: capture AsyncLocalStorage.snapshot() at enqueue and run the dequeued task inside it. Field is optional only for entries queued by an older module copy sharing the global singleton (existing legacy-entry test).
  • src/infra/diagnostic-events.ts, src/agents/embedded-agent-runner/run/attempt.ts, extensions/diagnostics-otel/src/service.ts, src/logging/diagnostic-stability.ts: context.assembled carries durationMs since run.started; the exporter spans it, so openclaw.context.assembled now covers run start -> prompt assembled.
  • Bundle diagnostics-otel into the package the same way sentry-monitor is bundled: drop the files exclude, add its @opentelemetry/* deps as root deps (root dist ships the import), mark the manifest enabledByDefault (the service is a no-op until diagnostics.otel.enabled), remove it from the official external plugin catalog and the optional-bundled-clusters list, make the workspace package private with no standalone publish/install blocks, delete its standalone npm-shrinkwrap.json, regenerate plugin inventory docs.

User Impact

  • Fleet: enabling traces becomes config only (diagnostics.otel.{enabled,endpoint,headers,serviceName}), no plugin install. Existing configs that still set plugins.entries.diagnostics-otel.enabled: true keep working.
  • Traces: openclaw.context.assembled shows pre-model setup time; queued lane tasks keep their own trace scope.
  • No behavior change when diagnostics.otel.enabled is unset.

Evidence

  • pnpm test src/process/command-queue.test.ts 35/35 (new: "runs a queued task in the async context captured at enqueue", red before fix: expected 'first' to be 'second').
  • pnpm test extensions/diagnostics-otel/src/service.test.ts src/logging/diagnostic-stability.test.ts 95/95 + 11/11 (new duration assertion red before fix: expected +0 to be 1500).
  • pnpm test src/plugins/bundled-plugin-metadata.test.ts 36/36 (empty-config startup list red before manifest change).
  • pnpm test src/cli/plugins-location-bridges.test.ts src/infra/package-dist-inventory.test.ts src/plugins/contracts/extension-runtime-dependencies.contract.test.ts src/plugins/contracts/package-manifest.contract.test.ts src/plugins/official-external-plugin-catalog.test.ts src/plugins/prune-docker-plugin-dist.test.ts src/wizard/setup.official-plugins.test.ts src/dockerfile.test.ts all green.
  • pnpm tsgo:core, pnpm tsgo:extensions, pnpm check:test-types, oxlint on changed files, oxfmt, git diff --check, node scripts/generate-plugin-inventory-doc.mjs --check: clean.
  • npm pack --dry-run --json --ignore-scripts: dist/extensions/diagnostics-otel/ files 0 -> 6.
  • Local E2E (pnpm build, isolated gateway on 18999 with no plugins.* config, mock OpenAI Responses provider behind a 2.5s latency proxy, stub OTLP/HTTP collector decoding protobuf spans): plugin listed in startup plugins by default; two chat.send turns on one session in followup queue mode produced two traces with distinct trace ids; openclaw.context.assembled durations 13817ms (cold) / 121ms (warm) starting at run start (+1ms / +0ms), followed by openclaw.model.call.
  • Lockfile regenerated with pnpm 11.2.2 (--lockfile-only): +33 lines, root @opentelemetry/* entries only.

Summary by cubic

Bundles diagnostics-otel into the OpenClaw package so OTLP export no longer requires a separate plugin install. The plugin is enabled by default but remains a no-op until diagnostics.otel.enabled is true.

Tracing

  • openclaw.context.assembled now spans run start through prompt assembly, attributing pre-model setup time.
  • Queued lane tasks run in the async context captured at enqueue, preserving each task's trace and session scope.

Packaging

  • Add the @opentelemetry/* runtime dependencies to the root package and remove standalone install and release metadata.
  • Restrictive plugins.allow lists must include diagnostics-otel; existing plugins.entries.diagnostics-otel.enabled settings remain supported.
  • External-plugin tests now use diagnostics-prometheus, which remains in the official catalog.

Written for commit 86fcb8f. Summary will update on new commits.

Review in cubic

A busy command lane dequeues the next task from the previous task's promise
continuation, so the dequeued task inherited that task's AsyncLocalStorage
context (diagnostic trace scope, session scope) instead of its enqueuer's.
Capture AsyncLocalStorage.snapshot() at enqueue and run the task inside it.
The field stays optional only for entries queued by an older module copy
that shares the global queue state.
context.assembled now carries durationMs since run.started, and the
diagnostics-otel exporter uses it as the span duration, so the
openclaw.context.assembled span covers run start until the prompt context is
assembled (session load, system prompt, context engine). The stability log
records the same duration. Previously the span was a zero-duration marker
and the time before the first model call was unattributed.
…efault

Ship the diagnostics-otel plugin inside the openclaw npm package the same
way sentry-monitor ships: drop the files exclude, add its @opentelemetry
runtime deps as root deps because the root dist now owns the import, and mark
the manifest enabledByDefault. The service stays a no-op until
diagnostics.otel.enabled is true, so enabling OTLP export on a fleet gateway
becomes config only with no separate plugin install.

Remove the plugin from the official external plugin catalog and the
optional-bundled-clusters list, make the workspace package private with no
standalone publish or install blocks, delete its standalone npm-shrinkwrap,
regenerate the plugin inventory docs, and update the OpenTelemetry docs and
the tests that used diagnostics-otel as the external-plugin sample.
@insomnius
insomnius requested a review from a team September 16, 2026 15:20
@claude

claude Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • extensions/diagnostics-otel/npm-shrinkwrap.json
  • npm-shrinkwrap.json
  • package.json
  • pnpm-lock.yaml

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 86fcb8f3ca5e33acddb740527ad0cefb25c60644
  • Trusted actor: @insomnius
  • Trusted role: pull request author; repository admin

Security review is still recommended before merge when the dependency graph change is intentional.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 21 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread package.json Resolved
Comment thread docs/gateway/opentelemetry.md Resolved
Comment thread docs/gateway/opentelemetry.md Resolved
Regenerate the root npm-shrinkwrap.json so the published package resolves the
new @opentelemetry root dependencies, and whitelist @opentelemetry/* in the
knip config next to @sentry/node because only the bundled plugin imports them.
Update the Docker install docs, the OpenTelemetry quick start (plugins.allow
note), and the plugin README to describe the bundled, enabled-by-default,
config-only setup instead of a standalone ClawHub install.

@augusteo augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review: approve (covers 6a4fb6f5 specifically)

Reviewed at module level per repo AGENTS.md (full changed modules + callers/callees + scoped guides), with local test execution as CI substitute. This token cannot read CI (/check-runs and statusCheckRollup 403), so reported green is taken as stated; I re-ran the load-bearing lanes locally.

1. Lane async-context fix (src/process/command-queue.ts) — verified RED-GREEN

  • Mechanism confirmed in source: pump() (line ~401) shifts entries and runs them from an async IIFE inside the previous task's continuation chain, so a dequeued task inherits the prior task's ALS context. The fix captures AsyncLocalStorage.snapshot() at enqueue and runs entry.task inside it in runQueueEntryTask — correct use of the Node API (snapshot returns a fn-runner). Optional field rationale (legacy entries from an older module copy sharing the global singleton) matches the existing legacy-entry test.
  • RED-GREEN reproduced locally: swapped in origin/boon's command-queue.ts, new test fails with the exact reported assertion expected 'first' to be 'second'; restored, test passes. Full file 35/35.
  • Agree with the honest-note framing: defensive primitive fix, per-session gates serialize turns upstream. The unit test proves the primitive; no fleet claim needed.

2. openclaw.context.assembled duration — verified

  • Sole emitter is attempt.ts:4572; durationMs: Date.now() - diagnosticRunStartedAt where diagnosticRunStartedAt is captured immediately after the run.started emit (line 1198) — same clock base as run.completed, so span nesting is coherent.
  • spanWithDuration (service.ts:1973) maps endTimeMs = evt.ts, startTime = end - durationMs; new service test asserts the 1500ms mapping end-to-end. diagnostic-stability.ts passes durationMs through the sanitizer. Grep confirms no other context.assembled emitters broken by the now-required field; tsgo lanes clean locally.

3. Bundling packaging — verified against the sentry-monitor precedent

  • Same shape as sentry-monitor: manifest enabledByDefault: true, activation onStartup, runtime deps mirrored to root dependencies (root dist owns the import — the extensions/AGENTS.md exception). The 11 @opentelemetry/* root additions exactly match the extension's own dependencies; extension-runtime-dependencies.contract.test.ts green locally.
  • files exclude removal is the actual pack gate; shouldBuildBundledCluster no longer treats it as optional; removed from official-external catalog, optional-bundled-clusters, and wizard onboarding (tests updated to diagnostics-prometheus fixtures). Companion knip.config.ts whitelist entry present.
  • No-op guarantee verified in service.ts start(): early return unless diagnostics.otel.enabled (and content capture separately defaults off).
  • Allowlist compatibility verified in code, not docs: config-activation-shared.ts runs the plugins.allow check before bundled default-enablement, so restrictive-allow installs keep the plugin off unless added — the follow-up commit documents exactly this. plugins.entries.diagnostics-otel.enabled: true legacy configs still work (explicit/entry-enable paths unchanged).
  • Delta f6a425fe..6a4fb6f5: all 4 cubic findings re-verified as fixed in code (root npm-shrinkwrap.json regenerated — spot-checked versions match pnpm-lock: api 1.9.1, sdk-node/exporters 0.219.0; docker.md/README rewritten; allowlist note added; knip whitelist). All 4 review threads resolved (GraphQL).

Local evidence (this host, worktree at f6a425fe; delta touched no runtime code)

  • vitest run on all 8 touched core/test files: 555/555 passed; extensions/diagnostics-otel/src/service.test.ts: 95/95.
  • pnpm tsgo:core, pnpm tsgo:extensions: clean.
  • Not re-run locally: oxlint/oxfmt (reported), and npm pack --dry-run 0→6 files (needs a full dist build; mechanism verified instead — the files-exclude was the only pack gate).

Nits (non-blocking)

  • scripts/lib/official-external-plugin-catalog.json carries formatter noise (unicode escapes, array re-wrapping) unrelated to the removal — fine, but it inflates the diff.
  • .github/workflows/docker-release.yml still passes OPENCLAW_EXTENSIONS=diagnostics-otel,codex; now redundant for diagnostics-otel (docker.md says so) but harmless as a prune keep-list entry.

Reviews from this host post as augusteo.

augusteo
augusteo previously approved these changes Sep 16, 2026

@augusteo augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hermes Agent Review

Verdict: Approve — clean, well-scoped change with good test coverage. (Note: CI is still mostly queued at review time — 12 green, 0 failed, 80 pending — so merge should wait on the full run.)

What I checked

1. src/process/command-queue.ts — enqueue-context capture ✅

  • AsyncLocalStorage.snapshot() captured at enqueue and invoked at dequeue via entry.runInEnqueueContext?.(entry.task) ?? entry.task() is the correct primitive-level fix for the continuation-context inheritance bug. snapshot() returns a (fn, ...args) => R invoker, so the call shape is right; a sync throw from task() still lands as a rejection inside Promise.resolve().then(...), preserving existing error semantics.
  • Making the field optional for legacy entries queued by an older module copy sharing the global singleton is a thoughtful migration guard.
  • New unit test ("runs a queued task in the async context captured at enqueue") is genuinely red-before-fix and pins the exact regression.

2. durationMs plumbing (attempt.ts → diagnostic-events.ts → service.ts / diagnostic-stability.ts) ✅

  • Field is required on the event type, set unconditionally at the single emission site, threaded through the stability recorder, and consumed by the OTel exporter (spanWithDuration(..., evt.durationMs, { endTimeMs: evt.ts })) so openclaw.context.assembled now covers run start → prompt assembled instead of being a zero-duration marker. Assertions updated in both test suites with a red-before-fix duration check.

3. Bundling diagnostics-otel into the package ✅

  • All the moving parts are consistent: files exclude dropped, @opentelemetry/* deps promoted to root (versions match the deleted standalone shrinkwrap), manifest enabledByDefault: true, workspace package made private with install/release blocks removed, standalone shrinkwrap deleted, external catalog + optional-bundled-clusters entries removed, knip config updated, inventory docs regenerated, and wizard/bridge tests re-pointed at diagnostics-prometheus as the canonical external example.
  • Safe-by-default: service is a no-op until diagnostics.otel.enabled, and existing plugins.entries.diagnostics-otel.enabled: true configs keep working.

Nits (non-blocking)

  • 💡 scripts/lib/official-external-plugin-catalog.json picks up unrelated prettier reformatting (brave / llama.cpp / parallel / perplexity entries) — harmless, but adds diff noise.
  • 💡 attempt.ts uses wall-clock Date.now() for durationMs — fine for diagnostics; performance.now() would be monotonic but this matches surrounding code.

Security

No new user-input surface, no secrets, no injection vectors. OTLP endpoint/headers remain config-driven.

LGTM pending green CI.

@augusteo
augusteo dismissed their stale review September 16, 2026 15:50

Duplicate of review 5225014763

Rewrite scripts/lib/official-external-plugin-catalog.json from the original
text so the diff only drops the diagnostics-otel entry, without the array
re-wrapping and unicode escapes a JSON re-serialization introduced.

@augusteo augusteo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Re-approve (covers ed2bbdb327d specifically)

Re-approving the new head. The previous approval (review 5225014763, on 6a4fb6f5) stopped counting because a later same-account review was dismissed, and GitHub takes the latest per-user review state. All prior verification (module-level review, local RED-GREEN on the lane fix, 555/555 + 95/95 tests, tsgo core/extensions) stands — the delta touches no runtime code.

Delta 6a4fb6f5..ed2bbdb327d verified: single commit, single file (scripts/lib/official-external-plugin-catalog.json), formatting-only. Net diff vs origin/boon for that file is now 0 added lines, 12 deleted lines, all inside the removed diagnostics-otel entry — the pure-deletion claim checks out. Catalog and wizard test changes are unchanged from the already-reviewed head, and the suites covering this file (official-external-plugin-catalog.test.ts, setup.official-plugins.test.ts) were green locally in the earlier run.

Reviews from this host post as augusteo.

…ugin sample

diagnostics-otel is bundled now and no longer in the official external
plugin catalog, so tests that need a trusted official ClawHub or npm install
record (update command payload repair, manifest registry trust, npm update
via catalog spec, dual-published release metadata) switch their sample to
diagnostics-prometheus, which is still catalog-listed.
@augusteo

Copy link
Copy Markdown

Delta ed2bbdb..a518529 verified from the review host: 4 test files, all diagnostics-otel -> diagnostics-prometheus sample swaps plus the dual-publish metadata entry removal; no runtime change. Sweep completeness checked: the one remaining diagnostics-otel install-sample test (missing-configured-plugin-install.test.ts) mocks its own catalog fixture, so it is catalog-independent. Ran the 4 changed suites plus 5 catalog-adjacent suites locally: 9 files, 507/507 green. Approval (review 5225063711) stands; reviewDecision reads APPROVED on this head.

@insomnius
insomnius merged commit b78a1dd into boon Sep 16, 2026
144 checks passed
@insomnius
insomnius deleted the feat/otel-turn-tracing branch September 16, 2026 16:34
orswn added a commit that referenced this pull request Sep 17, 2026
Routine release chore for the next train. Root package.json to
2026.6.11-boon.44, plugin package.json files synced via
scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files
regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a
CHANGELOG.md section for boon.44.

Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately
published plugin source changed since boon.43 (#227 moves
diagnostics-otel into the gateway bundle), so a gateway roll delivers
the whole release.
orswn added a commit that referenced this pull request Sep 17, 2026
…226)

Routine release chore for the next train. Root package.json to
2026.6.11-boon.44, plugin package.json files synced via
scripts/sync-plugin-versions.ts, changed npm-shrinkwrap.json files
regenerated via scripts/generate-npm-shrinkwrap.mjs --changed, and a
CHANGELOG.md section for boon.44.

Ships #225 (ENG-20103), #224, #228 (ENG-20090) and #227. No separately
published plugin source changed since boon.43 (#227 moves
diagnostics-otel into the gateway bundle), so a gateway roll delivers
the whole release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants