feat(google-genai): capture embedding config attributes - #326
feat(google-genai): capture embedding config attributes#326tomatotomata wants to merge 4 commits into
Conversation
Expose non-sensitive EmbedContentConfig fields under the existing Google GenAI operation config prefix for sync and async embedding calls. Fixes open-telemetry#170 Assisted-by: Codex
Pull request dashboard statusWaiting on reviewers · refreshed 2026-08-05 05:11 UTC Review the latest changes. Status above doesn't look right?
|
| pass | ||
|
|
||
|
|
||
| def _apply_embedding_request_attributes( |
There was a problem hiding this comment.
For GenerateContentConfig we made it default off // opt-in whether to include it..
Check out https://github.com/open-telemetry/opentelemetry-python-genai/blob/3b86f51593cf1a58169d6d76d08865c7082f2f44/instrumentation/opentelemetry-instrumentation-google-genai/README.rst#configuration-recording and https://github.com/open-telemetry/opentelemetry-python-genai/blob/main/instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py#L306 -- EmbedContentConfig is smaller so maybe it's fine to just dump it though.. probably most of the time just 1 or 2 fields will be set on it..
There was a problem hiding this comment.
You are right: issue #170 explicitly calls for EmbedContentConfig to follow GenerateContentConfig, so treating small config values as safe by default was inconsistent. e258f09 now defaults embedding-config capture off and adds the matching OTEL_GOOGLE_GENAI_EMBED_CONTENT_CONFIG_INCLUDES / ..._EXCLUDES controls. I also added coverage for default omission and explicit opt-in; the focused embedding and instrumentor tests pass (7 tests).
There was a problem hiding this comment.
Pull request overview
Adds optional capture of non-sensitive EmbedContentConfig fields as attributes on Google GenAI embedding spans, with opt-in allowlisting via env vars and support for both object and dict configs across sync/async APIs.
Changes:
- Introduces an embed-content config allowlist (constructor arg + env vars) and threads it into the embeddings instrumentation.
- Extracts and flattens
EmbedContentConfigintogcp.gen_ai.operation.config.*attributes while explicitly excludinghttp_options. - Updates tests/docs/changelog to reflect the new embedding config capture capability.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/embeddings.py | Captures allowlisted EmbedContentConfig fields (including dict->model conversion) and excludes http_options. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/instrumentor.py | Adds embed-content allowlist initialization and passes it into embeddings instrumentation. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/embeddings/test_embeddings.py | Adds coverage for default non-capture and allowlisted async capture of embedding config attributes. |
| instrumentation/opentelemetry-instrumentation-google-genai/README.rst | Documents embedding config capture env vars and expands the configuration-recording section. |
| instrumentation/opentelemetry-instrumentation-google-genai/.changelog/170.added | Adds a changelog entry for embedding config attribute capture. |
Comments suppressed due to low confidence (1)
instrumentation/opentelemetry-instrumentation-google-genai/README.rst:103
- README examples/descriptions for config allowlisting are currently misleading: the allowlist matches the fully-qualified attribute keys produced by
flatten_dict(e.g.gcp.gen_ai.operation.config.temperature), not bare field names liketemperature. Also, embedding invocations set these config attributes on the span (the embedding invocation does not emit a corresponding event).
The instrumentation can optionally record ``GenerateContentConfig`` and
``EmbedContentConfig`` parameters as span and event attributes under the
``gcp.gen_ai.operation.config.*`` namespace.
By default, no config fields are recorded. You can control which fields are
captured using the following environment variables:
* ``OTEL_GOOGLE_GENAI_GENERATE_CONTENT_CONFIG_INCLUDES`` — A comma-separated
list of config field names to include in the span attributes. For example:
Summary
EmbedContentConfigfields on Google GenAI embedding spansEmbedContentConfigobjects and dict configurations for sync and async callshttp_optionsso headers and request settings are not copied into telemetryFixes #170
Validation
python -m pytest instrumentation/opentelemetry-instrumentation-google-genai/tests/embeddings/test_embeddings.py -q� 6 passedgit diff --checkpass