diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md index 3509eb5b79..16ecbdaefe 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Use generic `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` environment variable + to control if content of prompt, completion, and other messages is captured. + ([#2947](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2947)) + - Update OpenAI instrumentation to Semantic Conventions v1.28.0: add new attributes and switch prompts and completions to log-based events. ([#2925](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2925)) diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py index ffbf3db5aa..a3a2d317ce 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/utils.py @@ -27,14 +27,14 @@ server_attributes as ServerAttributes, ) -OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT = ( - "OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT" +OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT = ( + "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT" ) def is_content_enabled() -> bool: capture_content = environ.get( - OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT, "false" + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, "false" ) return capture_content.lower() == "true" diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/conftest.py b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/conftest.py index 1b79947cc5..f35dfbacf2 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/conftest.py +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/conftest.py @@ -7,7 +7,7 @@ from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor from opentelemetry.instrumentation.openai_v2.utils import ( - OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT, + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, ) from opentelemetry.sdk._events import EventLoggerProvider from opentelemetry.sdk._logs import LoggerProvider @@ -85,7 +85,7 @@ def instrument_no_content(tracer_provider, event_logger_provider): @pytest.fixture(scope="function") def instrument_with_content(tracer_provider, event_logger_provider): os.environ.update( - {OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT: "True"} + {OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "True"} ) instrumentor = OpenAIInstrumentor() instrumentor.instrument( @@ -94,7 +94,7 @@ def instrument_with_content(tracer_provider, event_logger_provider): ) yield instrumentor - os.environ.pop(OTEL_INSTRUMENTATION_OPENAI_CAPTURE_MESSAGE_CONTENT, None) + os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) instrumentor.uninstrument() diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_chat_completions.py b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_chat_completions.py index be7bfc09b3..4369aa6a38 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_chat_completions.py +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/tests/test_chat_completions.py @@ -713,6 +713,7 @@ def assert_message_in_logs(log, event_name, expected_content, parent_span): if not expected_content: assert not log.log_record.body else: + assert log.log_record.body assert dict(log.log_record.body) == remove_none_values( expected_content )