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

use BoundedAttributes for attributes in link, event, resource, spans #1915

Merged
merged 14 commits into from
Jun 25, 2021

Conversation

codeboten
Copy link
Contributor

Description

Continuing towards making attributes consistent across Span, Link, Event and Resource by utilizing BoundedDict everywhere. Added BoundedDict to the API to make it available for Link which is defined in the API. Marked BoundedDict in the SDK as deprecated as a result. This is getting us one step closer to supporting dropped attribute counts in the exporters. One question I have for reviewers is whether the BoundedDict should be in opentelemetry.attributes or not, it could live in utils or something like that instead.

Fixes #1906

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?

  • No.

Checklist:

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

@codeboten codeboten requested a review from a team as a code owner June 16, 2021 21:22
@codeboten codeboten requested review from aabmass and ocelotl and removed request for a team June 16, 2021 21:22
def __init__(
self,
maxlen: Optional[int] = _DEFAULT_LIMIT,
attributes: types.Attributes = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

attributes makes sense in terms of what we are using BoundedDict for, but for the class itself it doesn't make much sense. Should we have a different name instead of BoundedDict?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to make a separation from the SDK BoundedDict too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I considered for a minute making Attributes a class to replace BoundedDict, wasn't sure if this would be doable without breaking Attributes' current interface though

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just BoundedAttributes or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -555,6 +561,16 @@ def __init__(
OTEL_SPAN_LINK_COUNT_LIMIT,
_DEFAULT_OTEL_SPAN_LINK_COUNT_LIMIT,
)
self.max_event_attributes = self._from_env_if_absent(
max_event_attributes,
OTEL_SPAN_LINK_COUNT_LIMIT,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these placeholders until this is merged? Would be good to have a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Captured the work in an issue #1918

@lzchen
Copy link
Contributor

lzchen commented Jun 21, 2021

@codeboten

One question I have for reviewers is whether the BoundedDict should be in opentelemetry.attributes or not

The functionality seems very specific to attributes (like filtering), so having it exist in opentelemetry.attributes makes sense to me.

@codeboten codeboten requested a review from lzchen June 21, 2021 20:53
if key in self._dict:
del self._dict[key]
elif self.maxlen is not None and len(self._dict) == self.maxlen:
del self._dict[next(iter(self._dict.keys()))]
Copy link
Member

Choose a reason for hiding this comment

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

self._dict.popitem(last=False)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious what people's thoughts on this are. It's confusing to me that if the attributes dict is full, we delete an existing item from the dictionary in favour of the new item. Any thoughts @lzchen?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah my first impression when reading the specs is that the LATEST item that is attempting to be added would be dropped instead of popping the first item that was added. If we decide on changing the functionality, you could leave that for a separate PR if you wish.

Copy link
Member

Choose a reason for hiding this comment

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

What do other SIGs do? And also spec says There SHOULD be a log emitted to indicate to the user that an attribute, event, or link was discarded due to such a limit. To prevent excessive logging, the log should not be emitted once per span, or per discarded attribute, event, or links. https://github.com/open-telemetry/opentelemetry-specification/blob/b46bcab5fb709381f1fd52096a19541370c7d1b3/specification/trace/sdk.md#span-limits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like go does the same thing as we do currently. https://github.com/open-telemetry/opentelemetry-go/blob/c1f460e097d395fa7cd02acc4a6096d6c6f14b08/sdk/trace/attributesmap.go#L45-L62

I agree that for now it probably doesn't make sense to change the behaviour

@codeboten codeboten changed the title use BoundedDict for attributes in link, event, resource, spans use BoundedAttributes for attributes in link, event, resource, spans Jun 24, 2021
@ocelotl ocelotl added the Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary label Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approve Public API check This label shows that the public symbols added or changed in a PR are strictly necessary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure consistent way to address attributes
4 participants