Repository navigation
fix(telemetry): add ADK_STORE_USER_ID to preserve user.id on traces - #8450
Open
josuetrindade wants to merge 1 commit into
Open
josuetrindade wants to merge 1 commit into
josuetrindade wants to merge 1 commit into
Conversation
When opentelemetry-instrumentation-google-genai is active, ADK delegates inference spans and passes user.id via log_only_extra_attributes, which tries GENERATE_CONTENT_EVENT_ONLY_EXTRA_ATTRIBUTES_CONTEXT_KEY. Because released versions of that instrumentation package do not export that key, user.id is silently dropped from both spans and events. Add ADK_STORE_USER_ID (NO_CONTENT, EVENT_ONLY, SPAN_ONLY, SPAN_AND_EVENT) on TelemetryConfig so operators can explicitly opt in to propagating user.id onto inference spans (including GENERATE_CONTENT_EXTRA_ATTRIBUTES_CONTEXT_KEY for delegated Gemini calls) or log events, while preserving the default privacy boundary when unset and logging a one-time warning when the event-only instrumentation key is unavailable. Fixes google#6361
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.
Link to Issue or Description of Change
Problem:
When
opentelemetry-instrumentation-google-genaiis installed and active, ADK delegates Gemini inference spans and placesuser.idonly inlog_only_extra_attributes._use_extra_generate_content_attributes()attempts to readGENERATE_CONTENT_EVENT_ONLY_EXTRA_ATTRIBUTES_CONTEXT_KEYfromopentelemetry.instrumentation.google_genai, catches(ImportError, AttributeError), and silently ignores it. Because released versions ofopentelemetry-instrumentation-google-genai(including0.7b2and1.0b0) do not export that key,user.idis silently dropped from instrumented spans and events.Solution:
Add opt-in
ADK_STORE_USER_ID(NO_CONTENT,EVENT_ONLY,SPAN_ONLY,SPAN_AND_EVENT) onTelemetryConfig:ADK_STORE_USER_IDis unset, default behavior is preserved:user.idis not placed on spans, and native telemetry still followsOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTfor log records.ADK_STORE_USER_IDisSPAN_ONLYorSPAN_AND_EVENT,user.idis included on native inference spans and forwarded inGENERATE_CONTENT_EXTRA_ATTRIBUTES_CONTEXT_KEYforopentelemetry-instrumentation-google-genai.ADK_STORE_USER_IDisEVENT_ONLYorNO_CONTENT,user.idis never widened onto spans;NO_CONTENTsuppresses it from both spans and log events, whileEVENT_ONLYenables it on native log events regardless of message-content capture mode.ADK_STORE_USER_IDhas an unrecognized value, a warning is logged once and it falls back to unset.log_only_extra_attributesis dropped becauseGENERATE_CONTENT_EVENT_ONLY_EXTRA_ATTRIBUTES_CONTEXT_KEYis unavailable, a warning is logged once instead of failing silently.Testing Plan
Unit Tests:
Added unit and integration tests covering
ADK_STORE_USER_IDparsing and warn-once validation (tests/unittests/telemetry/test_telemetry_context.py),use_inference_spannative and delegated routing plus one-time missing-key warning (tests/unittests/telemetry/test_spans.py), and end-to-endGoogleGenAiSdkInstrumentorspan attribute propagation (tests/unittests/telemetry/test_genai_instrumentor_bypass.py).Local checks run on Windows (Python 3.11.0):
.venv\Scripts\pytest.exe tests/unittests/telemetry/ -q:1245 passed, 1 skipped, 2 xfailed(the 1 skipped test is pre-existing intest_genai_instrumentor_bypass.pywhenopentelemetry-util-genai < 1.4b0)..venv\Scripts\pytest.exe tests/unittests/test_import_loading.py -q:30 passed..venv\Scripts\ruff.exe check,isort --check --diff,pyink --check --diff,codespell, andscripts/compliance_checks.pyon all 6 modified files: passed..venv\Scripts\mypy.exe src/google/adk/telemetry/context.py src/google/adk/telemetry/_experimental_semconv.py src/google/adk/telemetry/tracing.py: 0 new errors (1 pre-existingno-any-returnattracing.py:1676in untouched_response_model).Not run locally:
tests/unittests/suite,toxmulti-version matrix,addlicense, and live Vertex AI / Cloud Trace calls (GoogleGenAiSdkInstrumentorwas exercised offline withAsyncModels.generate_contentstubbed).Manual End-to-End (E2E) Tests:
Verified offline with
GoogleGenAiSdkInstrumentor,TracerProvider,InMemorySpanExporter, and stubbedAsyncModels.generate_content: withADK_TELEMETRY_SCHEMA_VERSION_OPT_IN=2andOTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental,generate_contentspans omituser.idby default / underEVENT_ONLY/ underNO_CONTENT, and recorduser.id="test_user"underADK_STORE_USER_ID=SPAN_ONLYandSPAN_AND_EVENT.Checklist