Skip to content

GenAI: Use common env var for content recording #2947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down