feat(telemetry): add user.id to gen_ai.user.message log records#5796
Closed
Achuth17 wants to merge 2 commits into
Closed
feat(telemetry): add user.id to gen_ai.user.message log records#5796Achuth17 wants to merge 2 commits into
Achuth17 wants to merge 2 commits into
Conversation
Please note that this change adds `user.id` field to an existing opt-in: `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT`. user.id is no longer set as a span attribute; it is emitted only on log records.
Collaborator
|
Merged by eb379be |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please note that this change adds
user.idfield to an existing opt-in:OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. user.id is no longer set as a span attribute; it is emitted only on log records.Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
user.idwas being attached as a span attribute on generate_content spans, which conflicted with security/privacy guidance that prompt/response-related PII should not be put in spans.user.idshould only be emitted on event logs (gated by the existing OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT opt-in), not on spans.Solution:
What: Stop setting
user.idas a span attribute. Instead, emit it only ongen_ai.user.messagelog records (and on the experimentaloperation_detailslog), gated by the existingOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTopt-in modes that include event output (EVENT_ONLY,SPAN_AND_EVENT).Why this solution:
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT) rather than introducing a new one, keeps the user-facing surface small.user.id) out of spans entirely.log_only_*parameter through the existing helpers so the span vs. log split is explicit at every call site, avoiding accidental leakage back into span attributes.opentelemetry-instrumentation-google-genaidoesn't yet support the event-only context key (viatry/except ImportError), so the change is non-blocking on the upstream contrib PR.Testing Plan
Tests run:
tests/unittests/telemetry/test_spans.py— 35/35 passed. Includes new ported tests covering:user.idabsent from span attributes, present ongen_ai.user.messagelogs only whenOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTincludes event output anduser_idis non-null, genai-instrumentor branch doesn't receiveuser.id, and graceful degradation when the upstreamopentelemetry-instrumentation-google-genaidoesn't expose the event-only context key.tests/unittests/telemetry/(broader suite incl. e2etest_node_functional.py) — 103/103 passed.tests/unittests/flows/(regression ontracing.pycallers) — 379/379 passed.Unit Tests:
Manual End-to-End (E2E) Tests:
Checklist
Additional context
Add any other context or screenshots about the feature request here.