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

Exceeding max number of attributes/links on span start raises exception #1844

Closed
mariojonke opened this issue May 12, 2021 · 1 comment · Fixed by #1856
Closed

Exceeding max number of attributes/links on span start raises exception #1844

mariojonke opened this issue May 12, 2021 · 1 comment · Fixed by #1856
Assignees
Labels
bug Something isn't working good first issue Good first issue help wanted

Comments

@mariojonke
Copy link
Contributor

When passing a list/dict of links/attributes that exceed the maximum configured limit to start_span a ValueError is raised instead of truncating the exceeding links/attributes.

Steps to reproduce
Add following tests to opentelemetry-sdk/tests/trace/test_trace.py

   def test_links(self):
        links = [trace_api.Link(trace_api.SpanContext(0x1, idx, is_remote=False)) for idx in range(0, 200)]
        tracer = new_tracer()
        with tracer.start_as_current_span("span", links=links):
            pass

    def test_span_attributes(self):
        attributes = {str(idx): idx for idx in range(0, 200)}
        tracer = new_tracer()
        with tracer.start_as_current_span("span", attributes=attributes):
            pass

What is the expected behavior?
The SDK should not raise an exception but rather truncate the exceeding attributes/links.

What is the actual behavior?
Exceeding the max number of links raises a ValueError in BoundedList:

../../src/opentelemetry/sdk/trace/__init__.py:871: in start_as_current_span
    set_status_on_exception=set_status_on_exception,
../../src/opentelemetry/sdk/trace/__init__.py:949: in start_span
    set_status_on_exception=set_status_on_exception,
../../src/opentelemetry/sdk/trace/__init__.py:643: in __init__
    self._links = BoundedList.from_seq(_SPAN_LINK_COUNT_LIMIT, links)

cls = <class 'opentelemetry.sdk.util.BoundedList'>, maxlen = 128
seq = (...)

    @classmethod
    def from_seq(cls, maxlen, seq):
        seq = tuple(seq)
        if len(seq) > maxlen:
>           raise ValueError
E           ValueError

Exceeding the max number of attributes on a Span raises a ValueError in BoundedDict:

../../src/opentelemetry/sdk/trace/__init__.py:871: in start_as_current_span
    set_status_on_exception=set_status_on_exception,
../../src/opentelemetry/sdk/trace/__init__.py:949: in start_span
    set_status_on_exception=set_status_on_exception,
../../src/opentelemetry/sdk/trace/__init__.py:627: in __init__
    SPAN_ATTRIBUTE_COUNT_LIMIT, attributes

cls = <class 'opentelemetry.sdk.util.BoundedDict'>, maxlen = 128
mapping = OrderedDict(...)

    @classmethod
    def from_map(cls, maxlen, mapping):
        mapping = OrderedDict(mapping)
        if len(mapping) > maxlen:
>           raise ValueError
E           ValueError
@mariojonke mariojonke added the bug Something isn't working label May 12, 2021
@c-kruse
Copy link
Contributor

c-kruse commented May 16, 2021

Hi there! I would like to give this a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good first issue help wanted
Projects
None yet
3 participants