Make event attributes immutable#1195
Merged
lzchen merged 8 commits intoopen-telemetry:masterfrom Oct 9, 2020
Merged
Conversation
This PR makes it more difficult for someone to edit the attributes of an `Event` once it has been added to a `Span`, as well as adding some regression tests around the other properties of an `Event` to ensure they have similar protections. It isn't particularly straightforward or idiomatic to make objects truly immutable in Python, but if these steps don't go far enough let me know! Fixes open-telemetry#1038
|
|
lzchen
reviewed
Oct 2, 2020
lzchen
reviewed
Oct 2, 2020
Contributor
Author
|
Thanks @lzchen, wasn't sure where to put this code so thanks for clearing that up! |
lzchen
reviewed
Oct 5, 2020
lzchen
approved these changes
Oct 5, 2020
owais
approved these changes
Oct 9, 2020
srikanthccv
pushed a commit
to srikanthccv/opentelemetry-python
that referenced
this pull request
Nov 1, 2020
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.

Description
This PR makes it more difficult for someone to edit the attributes of an
Eventonce it has been added to aSpan, as well as adding some regression tests around the other properties of anEventto ensure they have similar protections.It isn't particularly straightforward or idiomatic to make objects truly immutable in Python, but if these steps don't go far enough let me know!
I don't believe a documentation change is necessary because events are meant to be immutable according to the spec, but this should probably be considered a breaking change in case people were relying on the event attributes being mutable up until now.
Fixes #1038
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I've added regression tests to:
Eventraise an error when someone directly tries to change them; andattributesdictionary tuples.I've also added a new test for my change to make sure that an error is raised if someone tryies to directly edit the
attributesdictionary itself.Checklist: