Skip to content

feat: honour OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT when RIUS_CAPTURE_CONTENT is unset - #287

Closed
PabloPardoGarcia wants to merge 2 commits into
mainfrom
pablo/rius-1883-otel-capture-content-env
Closed

PabloPardoGarcia wants to merge 2 commits into
mainfrom
pablo/rius-1883-otel-capture-content-env

Conversation

@PabloPardoGarcia

@PabloPardoGarcia PabloPardoGarcia commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

The GenAI conventions now define the content-capture setting (semantic-conventions-genai #543): OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT, with NO_CONTENT (their default), SPAN_ONLY, EVENT_ONLY and SPAN_AND_EVENT.

When RIUS_CAPTURE_CONTENT is unset, the SDK now reads that variable:

Value Content capture
NO_CONTENT off
EVENT_ONLY off: content is only recorded on spans, and this mode asks for none there
SPAN_ONLY, SPAN_AND_EVENT on
empty or blank unset: on (our default), no warning
anything else on (our default), with a warning that the value is not recognised, that capture stays on, and which values are valid

The value is case-insensitive and trimmed, as the conventions define. Precedence is unchanged at the top: the capture_content argument, then RIUS_CAPTURE_CONTENT, then the OpenTelemetry variable, then on. With neither variable set capture stays on (deliberately different from the upstream NO_CONTENT default).

An unrecognised OpenTelemetry value keeps capture on. This intentionally differs from the conventions, which say an instrumentation SHOULD fall back to NO_CONTENT: capture is on by default in Rius, and the warning names the valid values so a typo is visible.

An empty (or blank) RIUS_CAPTURE_CONTENT counts as unset, so the OpenTelemetry variable applies; templated deployments often render an omitted value as "". It still logs a warning ("RIUS_CAPTURE_CONTENT is empty; treated as unset"), as the other blank RIUS_* flags do and as the shared sdk_cases/env.json case expects.

README configuration table and the capture section, plus the init() / resolve_config() docstrings, document it.

Tests (in tests/test_config.py): each mode, case-insensitivity, unrecognised values (including false and NO-CONTENT) warn with the new text and keep capture on, an empty OTel variable is unset with no warning, an empty RIUS_CAPTURE_CONTENT lets the OTel setting apply, RIUS_CAPTURE_CONTENT wins, the argument wins over both. ruff check, ruff format --check, mypy and pytest (2920 passed) are green.

Not changed here: tool definitions stay among the content attributes stripped under NO_CONTENT (tracked separately), and the older OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT is not read.

Closes RIUS-1883

…TURE_CONTENT is unset

NO_CONTENT and EVENT_ONLY turn content capture off (content is recorded on
spans only), SPAN_ONLY and SPAN_AND_EVENT keep it on. Read
case-insensitively; an unrecognised value keeps the default (on) and warns.
The explicit option and RIUS_CAPTURE_CONTENT keep precedence, and with
neither variable set capture stays on.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Automated review

No blocking issues. Precedence is correct and tested: the capture_content argument, then RIUS_CAPTURE_CONTENT, then OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT, then on. The default stays ON when both variables are unset. EVENT_ONLY turning capture off is the right reading, because Rius records content on spans and emits no GenAI log events. The logic matches rius-sdk-typescript#252 line for line. tests/test_config.py: 87 passed locally, and CI is green.

I checked the upstream text in #543 ("Content capture configuration"). Two parts of it matter here:

Environment variable value SHOULD be parsed case-insensitively.
If an unrecognized or invalid value is provided, instrumentations SHOULD default to NO_CONTENT.

Should fix

1. An unrecognised OTEL value fails open, where upstream says fail closed (src/rius/config.py:117-123). I checked these on the branch with resolve_config():

  • OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT=false gives True, with a warning
  • ...=none gives True
  • ...=NO-CONTENT (a typo) gives True

false is a very plausible value to set by hand, and the user who sets it clearly wants no content. Our deliberate default-ON decision is about the unset case, and that doesn't change here. Once someone engages the OTel variable, the OTel scheme's failure mode is NO_CONTENT. Suggestions, in order of preference:

  • Read an unrecognised value as off and warn, as the spec says.
  • At minimum, accept the boolean spellings _env_bool already knows (0/false/no/off as off, 1/true/yes/on as on) before warning. That keeps "true" working, and the test at tests/test_config.py:253 already treats it as on.

2. An empty RIUS_CAPTURE_CONTENT shadows the OTEL variable (src/rius/config.py:109). RIUS_CAPTURE_CONTENT= (empty) together with OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT=NO_CONTENT resolves to True, with a "not a recognised boolean" warning; I verified this on the branch. The OpenTelemetry SDK env-var spec treats an empty value as unset. Helm and compose templates often render VAR: "" when a value is omitted, so this can happen without anyone noticing. Suggest treating a blank value as unset in the precedence check, for RIUS_CAPTURE_CONTENT and for the OTEL variable (which currently warns on ""). This keeps parity with #252, which has the same behaviour.

Nits / questions

  • Tool definitions under NO_CONTENT. Upstream #543 excludes gen_ai.tool.definitions from content capture ("schemas rather than user/model payload content"). Our exporter strips it with the rest. Under NO_CONTENT this also empties the amnesia detector's tool-name column. That was a deliberate choice before this PR. Now that we read the upstream variable, it may deserve a line in the README section.
  • Not in scope, just noting: opentelemetry-python-contrib's GenAI instrumentations (openai-v2, google-genai, util-genai) read OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. That variable is already set in many deployments. Reading it as a lower-precedence fallback would be a separate decision.

…id OTel values

An empty RIUS_CAPTURE_CONTENT no longer shadows
OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT (it still warns, as the other
blank RIUS_* flags do), and an empty OTel variable counts as unset. The
warning for an unrecognised OTel value says capture stays on and lists the
valid values.
@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Addressed in ca0346b:

  1. Unrecognised OTel value. Kept as is: capture stays on. This intentionally differs from upstream's SHOULD-default-to-NO_CONTENT, because capture is on by default in Rius. The warning now says so: OTEL_INSTRUMENTATION_GENAI_CAPTURE_CONTENT='false' is not recognised; content capture stays on. Valid values: NO_CONTENT, SPAN_ONLY, EVENT_ONLY, SPAN_AND_EVENT. The PR body and README state the deviation.
  2. Empty values. An empty or blank RIUS_CAPTURE_CONTENT now counts as unset, so the OTel variable applies (RIUS_CAPTURE_CONTENT= with NO_CONTENT gives capture off). It still logs RIUS_CAPTURE_CONTENT is empty; treated as unset., as the other blank RIUS_* flags do. The shared sdk_cases/env.json case blank_capture_content_keeps_the_default expects that warning. An empty OTel variable is unset, with no warning.

Nits: tool-definition masking under NO_CONTENT is unchanged (tracked separately), and OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT is deliberately not read.

ruff, mypy and pytest (2920 passed) are green locally. rius-sdk-typescript#252 has the same changes.

@PabloPardoGarcia

Copy link
Copy Markdown
Member Author

Landed through #289, together with the rius-semconv v1.13.0 sync.

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