Skip to content

Commit 155962b

Browse files
author
Liudmila Molkova
authored
GenAI: Use common env var for content recording (#2947)
1 parent 3109724 commit 155962b

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Use generic `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` environment variable
11+
to control if content of prompt, completion, and other messages is captured.
12+
([#2947](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2947))
13+
1014
- Update OpenAI instrumentation to Semantic Conventions v1.28.0: add new attributes
1115
and switch prompts and completions to log-based events.
1216
([#2925](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2925))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
server_attributes as ServerAttributes,
2828
)
2929

30-
OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT = (
31-
"OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT"
30+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = (
31+
"OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"
3232
)
3333

3434

3535
def is_content_enabled() -> bool:
3636
capture_content = environ.get(
37-
OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT, "false"
37+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, "false"
3838
)
3939

4040
return capture_content.lower() == "true"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
99
from opentelemetry.instrumentation.openai_v2.utils import (
10-
OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT,
10+
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT,
1111
)
1212
from opentelemetry.sdk._events import EventLoggerProvider
1313
from opentelemetry.sdk._logs import LoggerProvider
@@ -85,7 +85,7 @@ def instrument_no_content(tracer_provider, event_logger_provider):
8585
@pytest.fixture(scope="function")
8686
def instrument_with_content(tracer_provider, event_logger_provider):
8787
os.environ.update(
88-
{OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT: "True"}
88+
{OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "True"}
8989
)
9090
instrumentor = OpenAIInstrumentor()
9191
instrumentor.instrument(
@@ -94,7 +94,7 @@ def instrument_with_content(tracer_provider, event_logger_provider):
9494
)
9595

9696
yield instrumentor
97-
os.environ.pop(OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT, None)
97+
os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None)
9898
instrumentor.uninstrument()
9999

100100

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ def assert_message_in_logs(log, event_name, expected_content, parent_span):
713713
if not expected_content:
714714
assert not log.log_record.body
715715
else:
716+
assert log.log_record.body
716717
assert dict(log.log_record.body) == remove_none_values(
717718
expected_content
718719
)

0 commit comments

Comments
 (0)