Don't call set attribute twice for the same key and make start attributes unsettable#150
Open
lmolkova wants to merge 10 commits into
Open
Don't call set attribute twice for the same key and make start attributes unsettable#150lmolkova wants to merge 10 commits into
lmolkova wants to merge 10 commits into
Conversation
lmolkova
commented
Jun 18, 2026
hide or readonly
lmolkova
force-pushed
the
dont-duplicate-attributes
branch
from
June 19, 2026 23:20
56db4f0 to
d7f45d9
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors GenAI invocation types to (1) only set sampling-relevant attributes at span start (avoiding re-setting the same attribute keys again at finish) and (2) encourage providing span-name/sampling inputs at invocation construction time (e.g., passing agent_name into invoke_local_agent(...)).
Changes:
- Split “start-time” vs “finish-time” attribute setting by introducing
_get_start_attributes()and removing duplicatedset_attributes(...)keys at finish. - Make several start-time fields “construction-time only” (e.g., agent name/model/server info) and update tests to pass them at construction.
- Update OpenAI response streaming wrapper to populate
response_model_nameinstead of mutatingrequest_model.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_workflow_invocation.py | Uses start-only attributes and stores workflow name internally (_name). |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_tool_invocation.py | Moves tool metadata to start-time attributes and avoids re-setting at finish. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_retrieval_invocation.py | Moves retrieval sampling attributes to start-time, avoids duplication at finish. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py | Renames “start attributes” helper and removes syncing deprecated container fields that are now start-only. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_embedding_invocation.py | Restricts provider/model/server fields to start-time attributes; finish sets only non-start fields. |
| util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py | Moves sampling-relevant agent fields to start-time; updates finish-time attribute grouping. |
| util/opentelemetry-util-genai/tests/test_workflow_invocation.py | Updates workflow invocation tests for the new name storage/behavior. |
| util/opentelemetry-util-genai/tests/test_handler_workflow.py | Updates workflow handler tests for the new name storage/behavior. |
| util/opentelemetry-util-genai/tests/test_handler_retrieval.py | Updates retrieval handler tests for the new data source id storage/behavior. |
| util/opentelemetry-util-genai/tests/test_handler_completion_hook.py | Updates completion-hook test to pass agent_name at construction. |
| util/opentelemetry-util-genai/tests/test_handler_agent.py | Updates agent tests to pass agent_name at construction and reflect start-only fields. |
| util/opentelemetry-util-genai/.changelog/150.changed | Adds a towncrier fragment describing the behavioral change. |
| instrumentation/opentelemetry-instrumentation-genai-openai/tests/test_embedding_invocation_unit.py | Drops assertions tied to mutable request_model state. |
| instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/response_wrappers.py | Sets response_model_name (actual model) instead of mutating request_model. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…elemetry-python-genai into dont-duplicate-attributes
DylanRussell
approved these changes
Jun 26, 2026
lzchen
reviewed
Jul 7, 2026
Pull request dashboard statusStatus: Waiting on maintainers to merge the pull request. |
# Conflicts: # util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py # util/opentelemetry-util-genai/src/opentelemetry/util/genai/_embedding_invocation.py # util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py # util/opentelemetry-util-genai/src/opentelemetry/util/genai/_tool_invocation.py # util/opentelemetry-util-genai/src/opentelemetry/util/genai/_workflow_invocation.py
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.
No description provided.