Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make event attributes immutable #1195

Merged
merged 8 commits into from
Oct 9, 2020

Conversation

eoinnoble
Copy link
Contributor

@eoinnoble eoinnoble commented Oct 1, 2020

Description

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!

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.

  • 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?

I've added regression tests to:

  • make sure that the properties of an Event raise an error when someone directly tries to change them; and
  • make sure that an error is raised if someone tries to directly edit any of the attributes dictionary 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 attributes dictionary itself.

Checklist:

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

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
@eoinnoble eoinnoble requested a review from a team October 1, 2020 23:18
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 1, 2020

CLA Check
The committers are authorized under a signed CLA.

Copy link
Contributor

@lzchen lzchen left a comment

Choose a reason for hiding this comment

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

Just a few comments

@eoinnoble
Copy link
Contributor Author

Thanks @lzchen, wasn't sure where to put this code so thanks for clearing that up!

@codeboten codeboten added the release:required-for-ga To be resolved before GA release label Oct 8, 2020
@lzchen lzchen merged commit 5760c0e into open-telemetry:master Oct 9, 2020
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:required-for-ga To be resolved before GA release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Events should be immutable and should preserve the order in which they are set
5 participants