Skip to content

feat: add deepcopy implementation for BoundedAttributes#4934

Open
herin049 wants to merge 2 commits intoopen-telemetry:mainfrom
herin049:feat/bounded-attr-deepcopy
Open

feat: add deepcopy implementation for BoundedAttributes#4934
herin049 wants to merge 2 commits intoopen-telemetry:mainfrom
herin049:feat/bounded-attr-deepcopy

Conversation

@herin049
Copy link
Contributor

Description

Adds a custom __deepcopy__ implementation for BoundedAttributes.

Fixes #4928

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

tox -e py314-test-opentelemetry-sdk

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added

@herin049 herin049 requested a review from a team as a code owner February 24, 2026 23:16
Copy link
Member

@pmcollins pmcollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like if you create a span via tracer.start_as_current_span(...), the _events member is set to a BoundedList, which apparently also has a lock that will prevent a deep copy.

def __deepcopy__(self, memo: dict) -> "BoundedAttributes":
with self._lock:
attributes = copy.deepcopy(self._dict, memo)
copy_ = BoundedAttributes(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a dropped field in BoundedAttributes that we may want to copy (looks like this value is actually exported in _encode_links), but it would have to be set via direct field access since there's no constructor arg for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Add __deepcopy__ support to Span and BoundedAttributes

2 participants