Repository navigation
Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-11-09 18:13 UTC Resolve merge conflicts. Two things need attention:
Status above doesn't look right?
|
| if resource is None: | ||
| resource = Resource.create({}) | ||
| super().__init__( | ||
| name=name, |
There was a problem hiding this comment.
Can we quantify how the named arguments contribute to this? Not a fan on making things less readable.
There was a problem hiding this comment.
IIRC it does result in a >10% speedup for Span creation. I'll add benchmarks breaking it down. I agree though, switching to positional args makes it hard to read, if you'd prefer we remove it that's OK with me.
Contribution of positional argumentsApple M5 Pro, CPython 3.14.5
|
|
Hi @herin049 — just a friendly reminder that this pull request is waiting on you. The dashboard status comment has the open items and is kept current.
|
| self.dropped += len(attributes) - len(cleaned_attributes) | ||
| for key, value in cleaned_attributes.items(): | ||
| self._setitem_locked(key, value) | ||
| for key, value in attributes.items(): |
There was a problem hiding this comment.
Could we keep input iteration and cleanup outside this lock? For a span with existing attributes, span.set_attributes(span.attributes) tries to acquire the same lock twice and hangs.
| self._setitem_locked(key, _clean_attribute_value(value, self.max_value_len)) | ||
|
|
||
| def _setitem_locked(self, key: str, value: types.AnyValue) -> None: | ||
| if len(self._dict) < self.maxlen: |
There was a problem hiding this comment.
Updating an existing attribute below capacity no longer moves it to the end, so a recently updated attribute can now be dropped instead of an older one. Could we preserve the previous eviction behavior?
Description
Reduces per-span overhead in the SDK hot path. Most performance gains where achieved by reordering branch statements, inlining a few function calls and switching from keyword to positional calling where possible.
Note: There are some very minor/subtle breaking changes with adding
__slots__on some classes (i.e.__dict__goes away onSpanobjects). Likewise, the bounded attributes change does switch the default fromNonetosys.maxsize, but this one is extremely unlikely to break any existing code. If we're concerned about the__slots__changes, we can remove this from the PR.Type of change
Please delete options that are not relevant.
Benchmarks (MacBook M5, CPython 3.14)
opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.pystart_span_with_attributes[0]start_span_with_attributes[1]start_span_with_attributes[10]start_span_with_attributes[50]start_span_with_attributes[128]simple_start_spansimple_start_as_current_spanset_attribute[10]read_events[10]set_attribute_types[str]set_attribute_types[seq_int]Per span, memory drops by 56 B: the span object goes from 344 B to 224 B, and
SpanContextfrom 112 B to 96 B.Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
tox -e precommittox -e typecheck