Skip to content

fix: gate span content capture behind OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT - #146

Open
enternal111 wants to merge 7 commits into
DEVtheOPS:mainfrom
enternal111:fix/gate-span-content-capture
Open

enternal111 wants to merge 7 commits into
DEVtheOPS:mainfrom
enternal111:fix/gate-span-content-capture

Conversation

@enternal111

@enternal111 enternal111 commented Nov 14, 2026 •

Copy link
Copy Markdown

Which problem is this PR solving?

Fixes #144. Every LLM, session, and tool span embeds the full user/model content (input.value, output.value, llm.input_messages, llm.output_messages, run-span prompt text, tool.parameters and tool inputs/outputs), so traces sent to a hosted OTLP backend effectively contain the entire conversation. Additionally, error messages (tool.error, span statusMessage, api_error log attributes) can echo user input (e.g. a websearch query repeated in the failure text), and captured content is unbounded.

Short description of the changes

  • New captureContent plugin option, plus the OPENCODE_CAPTURE_CONTENT environment variable, following the OpenTelemetry GenAI semantic-conventions guidance for message-content capture. The default is privacy-first: content is not captured.
  • Content-bearing span attributes are only emitted when capture is explicitly enabled.
  • Error messages are redacted (user input after common prepositions is masked) unless content capture is enabled; the error type stays visible for debugging.
  • Prompt text is capped at 64 KB; tool arguments are capped and re-encoded as valid JSON; tool output is filtered to text parts and capped at 64 KB with the original byte count preserved.
  • Tool argument serialization is skipped entirely when capture is disabled.

How Has This Been Tested?

  • bun run typecheck
  • bun run lint
  • bun test (unit suite; content-asserting tests opt in through the env var)
  • End-to-end: verified no content attributes in default mode, all content attributes present when enabled, and error messages redacted in default mode

…URE_MESSAGE_CONTENT

Span attributes that embed user or model content (input.value,
output.value, llm.input_messages, llm.output_messages, session run
span prompt text, and tool parameters/inputs/outputs) are now
emitted only when capture is explicitly enabled, either via the new
captureContent plugin option or the standard
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment
variable (true/1). The default is privacy-first: content is not
captured, matching the OpenTelemetry GenAI semantic-conventions
guidance for message content.

Fixes DEVtheOPS#144
@enternal111

Copy link
Copy Markdown
Author

@codex review

@enternal111

Copy link
Copy Markdown
Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T12:42:38.948880Z 57fffba New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53bb29231b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/config.ts Resolved
Comment thread tests/integration/fixtures.ts Resolved
Comment thread src/config.ts Resolved
…option

Follow the repository convention that plugin settings use the OPENCODE_
namespace. Document captureContent in the README environment variable and
plugin option tables, and update the privacy note to cover span content.
@enternal111

Copy link
Copy Markdown
Author

@codex review

@enternal111

Copy link
Copy Markdown
Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c2d2608e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/handlers/tool.ts Resolved
Cap the JSON.stringify of tool input to 64 KB, matching the bound the
step handler already applies to streamed text.
@enternal111

Copy link
Copy Markdown
Author

@codex review

@enternal111

Copy link
Copy Markdown
Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b116d73971

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/handlers/tool.ts Resolved
@enternal111

Copy link
Copy Markdown
Author

@codex review

@enternal111

Copy link
Copy Markdown
Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b116d73971

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/integration/opencode.test.ts Resolved
Re-encode the truncated text so span attributes always carry valid JSON,
and remove the remaining test comment.
@enternal111

Copy link
Copy Markdown
Author

@codex review

@enternal111

Copy link
Copy Markdown
Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: bf9b4e3960

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@enternal111

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Setup repeatedly failed. Update the setup script or commit, then try again later.
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@enternal111

Copy link
Copy Markdown
Author

@codex review

@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.

@enternal111

Copy link
Copy Markdown
Author

@codex review

@enternal111

Copy link
Copy Markdown
Author

@codex security review

@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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57fffba91b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/handlers/session.ts
span.setStatus({ code: SpanStatusCode.ERROR, message })
span.setAttribute("error", message)
span.setStatus({ code: SpanStatusCode.ERROR, message: ctx.captureContent ? message : redactErrorMessage(message) })
span.setAttribute("error", ctx.captureContent ? message : redactErrorMessage(message))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Redact errors before emitting failure logs

When captureContent is off (the default) and a failed session or tool error echoes a prompt or query, this redacts only the span fields: handleExecutionEnded still emits the raw message in session.error, and finishTool still emits the raw error in tool_result. Since OTLP logs are enabled by default, those failures still export user content despite the privacy mode; redact those log attributes too.

Useful? React with 👍 / 👎.

Comment thread src/util.ts
Comment on lines +39 to +40
.replace(/\b(?:for|with|query|search(?:ing)?\s+for)\s+.+$/i, " for [redacted]")
.slice(0, 128)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fail closed when an error does not match the redactor

An upstream error may echo input as prompt: <text> or in another format without these trigger words; the regex then does not match, and the fallback only truncates to 128 characters, so a short prompt is still written into status/error attributes and the api_error log with content capture disabled. Since StructuredError.message is arbitrary text, retain only a safe error type/status on non-matches instead of forwarding the message.

Useful? React with 👍 / 👎.

Comment thread src/handlers/session.ts
"agent.type": totals?.agentType ?? "primary",
"session.is_subagent": isSubagent,
...(promptText
...(promptText && ctx.captureContent

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound the prompt on the session span

When content capture is enabled for a prompt longer than 64,000 characters, handleExecutionStarted puts the entire pendingPrompt.text into input.value and llm.input_messages; unlike handleStepStarted, this session-span path never slices it. This can still create an oversized span despite the new content limit, so cap the root prompt before attaching it.

AGENTS.md reference: AGENTS.md:L61-L61

Useful? React with 👍 / 👎.

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.

[Bug]: Span attributes record prompts and tool inputs even with prompt/context capture disabled

1 participant