Skip to content

Commit 64d1b17

Browse files
committed
fix(openai): Handle content capture with span_and_event mode
The is_content_enabled() function only recognized 'true' as a valid value for OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, causing newer enum values like 'span_and_event' to be treated as disabled. Updated is_content_enabled() to recognize all valid ContentCapturingMode enum values (span_only, event_only, span_and_event) in addition to the legacy 'true' value. Fixes #4038
1 parent 7f107df commit 64d1b17

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

  • instrumentation-genai/opentelemetry-instrumentation-openai-v2

instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from opentelemetry.trace.status import Status, StatusCode
3939
from opentelemetry.util.genai.types import (
40+
ContentCapturingMode,
4041
InputMessage,
4142
LLMInvocation,
4243
OutputMessage,
@@ -55,7 +56,16 @@ def is_content_enabled() -> bool:
5556
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, "false"
5657
)
5758

58-
return capture_content.lower() == "true"
59+
lower = capture_content.lower()
60+
if lower == "true":
61+
return True
62+
63+
# Support newer ContentCapturingMode enum values (e.g. span_and_event)
64+
try:
65+
mode = ContentCapturingMode[lower.upper()]
66+
return mode != ContentCapturingMode.NO_CONTENT
67+
except KeyError:
68+
return False
5969

6070

6171
def extract_tool_calls(item, capture_content):

instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def vcr_config():
118118

119119
@pytest.fixture(
120120
scope="function",
121-
params=[(True, "span_only"), (False, "True")],
121+
params=[(True, "span_only"), (False, "True"), (False, "span_and_event")],
122122
name="content_mode",
123123
)
124124
def fixture_content_mode(request):

0 commit comments

Comments
 (0)