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 immutable attributes consistent #1909

Conversation

codeboten
Copy link
Contributor

Description

This change ensures Event, Link and Resource attributes are made immutable in a consistent fashion. Note that this does change the behaviour to raise a TypeError when someone tries to modify a resource or link attribute, but I believe this is the correct behaviour, rather than silently failing to modify the attributes.

Fixes #1907

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Does This PR Require a Contrib Repo Change?

Answer the following question based on these examples of changes that would require a Contrib Repo Change:

  • The OTel specification has changed which prompted this PR to update the method interfaces of opentelemetry-api/ or opentelemetry-sdk/

  • The method interfaces of test/util have changed

  • Scripts in scripts/ that were copied over to the Contrib repo have changed

  • Configuration files that were copied over to the Contrib repo have changed (when consistency between repositories is applicable) such as in

    • pyproject.toml
    • isort.cfg
    • .flake8
  • When a new .github/CODEOWNER is added

  • Major changes to project information, such as in:

    • README.md
    • CONTRIBUTING.md
  • No.

Checklist:

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

@codeboten codeboten requested review from a team, aabmass and ocelotl and removed request for a team June 10, 2021 20:43
Alex Boten added 2 commits June 10, 2021 14:26
…m:codeboten/opentelemetry-python into codeboten/consistent-immutable-attributes
@srikanthccv
Copy link
Member

I believe this is the correct behaviour, rather than silently failing to modify the attributes.

We mention these are immutable so I wouldn't expect users to be surprised when they modify and don't see the modifications. I agree that we should be consistent.

@@ -139,7 +140,7 @@ def __init__(
attributes: types.Attributes = None,
) -> None:
super().__init__(context)
self._attributes = attributes
self._attributes = _create_immutable_attributes(attributes)
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the docstring for Link and Event about immutability like we do for Resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, done.

@codeboten codeboten merged commit 32b83a0 into open-telemetry:main Jun 14, 2021
@codeboten codeboten deleted the codeboten/consistent-immutable-attributes branch June 14, 2021 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attributes immutability should be consistent
4 participants