Skip to content

Add JavaScript span transform plugins - #28

Open
Stephen Belanger (Qard) wants to merge 8 commits into
mainfrom
t3code/explore-rquickjs-span-plugins
Open

Add JavaScript span transform plugins#28
Stephen Belanger (Qard) wants to merge 8 commits into
mainfrom
t3code/explore-rquickjs-span-plugins

Conversation

@Qard

@Qard Stephen Belanger (Qard) commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add ordered synchronous JavaScript span transforms powered by per-worker QuickJS runtimes
  • bridge spans and context directly with rquickjs-serde, using strict result decoding without intermediate JSON text
  • expose operation, source, session ID, and an environment snapshot captured once when each daemon worker processor is constructed
  • canonicalize plugin paths to absolute paths before validation and persistent enable storage
  • persist enabled plugins for ordinary sessions while keeping managed runs and import/attach plugin chains invocation-local
  • replay raw journal events through the resumed session's current plugin chain
  • isolate failures per plugin and worker so successful plugins continue running while diagnostics remain bounded

Example

Create a synchronous ES module:

// tag-ci.mjs
export default function tagCi(span, context) {
  if (!context.env.CI) return span;

  return {
    ...span,
    tags: [...new Set([...(span.tags ?? []), "ci"])],
    metadata: {
      ...(span.metadata ?? {}),
      deployment: context.env.DEPLOYMENT_ENV ?? "unknown",
      trace_source: context.source,
    },
  };
}

Choose the scope when registering it:

# Persist an ordered global chain for ordinary Codex sessions.
bt trace enable codex --plugin ./redact.mjs --plugin ./tag-ci.mjs

# Only local.mjs runs for this managed invocation; enabled plugins are not merged.
bt trace run --plugin ./local.mjs codex -- "summarize this change"

# Only sanitize-history.mjs runs for this import; enabled plugins are not merged.
bt trace import codex SESSION_ID --plugin ./sanitize-history.mjs

Each function receives the previous plugin's returned span plus { operation, source, session_id, env }. Plugins may change span content but not span_id, root_span_id, or parent_span_ids.

Raw input events are journaled before transformation. On recovery, an ordinary session uses the current globally configured plugin chain, while an isolated managed session continues using its invocation-local chain. Import and attach are separate from journal recovery and use only their command-line plugins.

See the README examples for redaction, environment handling, chaining, replay, and security guidance.

Validation

  • cargo test --manifest-path bt-daemon/Cargo.toml --all-features --locked
  • cargo clippy --manifest-path bt-daemon/Cargo.toml --all-targets --all-features --locked -- -D warnings
  • cargo fmt --manifest-path bt-daemon/Cargo.toml -- --check
  • cargo metadata --manifest-path bt-daemon/Cargo.toml --locked --no-deps --format-version 1
  • make test
  • git diff --check

@Qard
Stephen Belanger (Qard) marked this pull request as ready for review August 21, 2026 15:17
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Qard
Stephen Belanger (Qard) force-pushed the t3code/explore-rquickjs-span-plugins branch from af6b477 to 41bd374 Compare August 24, 2026 11:54
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