Skip to content

Commit 60a3b52

Browse files
authored
add support for 0 global attribute limit and tests (open-telemetry#2398)
* add support for 0 global attribute limit and tests * add PR number to changelog
1 parent 83e6e17 commit 60a3b52

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.8.0-0.27b0...HEAD)
99

10+
- Fix SpanLimits global span limit defaulting when set to 0
11+
([#2398](https://github.com/open-telemetry/opentelemetry-python/pull/2398))
1012
- Decode URL-encoded headers in environment variables
1113
([#2312](https://github.com/open-telemetry/opentelemetry-python/pull/2312))
1214
- [exporter/opentelemetry-exporter-otlp-proto-grpc] Add OTLPMetricExporter

opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,23 +594,31 @@ def __init__(
594594
max_attributes, OTEL_ATTRIBUTE_COUNT_LIMIT
595595
)
596596
self.max_attributes = (
597-
global_max_attributes or _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT
597+
global_max_attributes
598+
if global_max_attributes is not None
599+
else _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT
598600
)
599601

600602
self.max_span_attributes = self._from_env_if_absent(
601603
max_span_attributes,
602604
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
603-
global_max_attributes or _DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
605+
global_max_attributes
606+
if global_max_attributes is not None
607+
else _DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
604608
)
605609
self.max_event_attributes = self._from_env_if_absent(
606610
max_event_attributes,
607611
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT,
608-
global_max_attributes or _DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT,
612+
global_max_attributes
613+
if global_max_attributes is not None
614+
else _DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT,
609615
)
610616
self.max_link_attributes = self._from_env_if_absent(
611617
max_link_attributes,
612618
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT,
613-
global_max_attributes or _DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT,
619+
global_max_attributes
620+
if global_max_attributes is not None
621+
else _DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT,
614622
)
615623

616624
# attribute length

opentelemetry-sdk/tests/trace/test_trace.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,53 @@ def test_span_no_limits_code(self):
15941594
)
15951595
)
15961596

1597+
def test_span_zero_global_limit(self):
1598+
self._test_span_limits(
1599+
new_tracer(
1600+
span_limits=trace.SpanLimits(
1601+
max_attributes=0,
1602+
max_events=0,
1603+
max_links=0,
1604+
)
1605+
),
1606+
0,
1607+
0,
1608+
0,
1609+
0,
1610+
0,
1611+
)
1612+
1613+
def test_span_zero_global_nonzero_model(self):
1614+
self._test_span_limits(
1615+
new_tracer(
1616+
span_limits=trace.SpanLimits(
1617+
max_attributes=0,
1618+
max_events=0,
1619+
max_links=0,
1620+
max_span_attributes=15,
1621+
max_span_attribute_length=25,
1622+
)
1623+
),
1624+
15,
1625+
0,
1626+
0,
1627+
0,
1628+
25,
1629+
)
1630+
1631+
def test_span_zero_global_unset_model(self):
1632+
self._test_span_no_limits(
1633+
new_tracer(
1634+
span_limits=trace.SpanLimits(
1635+
max_attributes=0,
1636+
max_span_attributes=trace.SpanLimits.UNSET,
1637+
max_links=trace.SpanLimits.UNSET,
1638+
max_events=trace.SpanLimits.UNSET,
1639+
max_attribute_length=trace.SpanLimits.UNSET,
1640+
)
1641+
)
1642+
)
1643+
15971644
def test_dropped_attributes(self):
15981645
span = get_span_with_dropped_attributes_events_links()
15991646
self.assertEqual(1, span.dropped_links)

0 commit comments

Comments
 (0)