File tree Expand file tree Collapse file tree 5 files changed +25
-2
lines changed
opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/trace_encoder
opentelemetry-exporter-otlp-proto-grpc/tests
opentelemetry-api/src/opentelemetry/trace
opentelemetry-sdk/tests/trace Expand file tree Collapse file tree 5 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## Unreleased
99
10+ - Fix use of ` link.attributes.dropped ` , which may not exist
11+ ([ #4119 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/4119 ) )
1012- Running mypy on SDK resources
1113 ([ #4053 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/4053 ) )
1214- Added py.typed file to top-level module
Original file line number Diff line number Diff line change @@ -157,7 +157,7 @@ def _encode_links(links: Sequence[Link]) -> Sequence[PB2SPan.Link]:
157157 trace_id = _encode_trace_id (link .context .trace_id ),
158158 span_id = _encode_span_id (link .context .span_id ),
159159 attributes = _encode_attributes (link .attributes ),
160- dropped_attributes_count = link .attributes . dropped ,
160+ dropped_attributes_count = link .dropped_attributes ,
161161 flags = _span_flags (link .context ),
162162 )
163163 pb2_links .append (encoded_link )
Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ def setUp(self):
171171 "attributes" : BoundedAttributes (
172172 attributes = {"a" : 1 , "b" : False }
173173 ),
174+ "dropped_attributes" : 0 ,
174175 "kind" : OTLPSpan .SpanKind .SPAN_KIND_INTERNAL , # pylint: disable=no-member
175176 }
176177 )
Original file line number Diff line number Diff line change 8484from deprecated import deprecated
8585
8686from opentelemetry import context as context_api
87+ from opentelemetry .attributes import BoundedAttributes
8788from opentelemetry .context .context import Context
8889from opentelemetry .environment_variables import OTEL_PYTHON_TRACER_PROVIDER
8990from opentelemetry .trace .propagation import (
@@ -149,6 +150,12 @@ def __init__(
149150 def attributes (self ) -> types .Attributes :
150151 return self ._attributes
151152
153+ @property
154+ def dropped_attributes (self ) -> int :
155+ if isinstance (self ._attributes , BoundedAttributes ):
156+ return self ._attributes .dropped
157+ return 0
158+
152159
153160_Links = Optional [Sequence [Link ]]
154161
Original file line number Diff line number Diff line change @@ -669,6 +669,19 @@ def test_event_dropped_attributes(self):
669669 event2 = trace .Event ("foo2" , {"bar2" : "baz2" })
670670 self .assertEqual (event2 .dropped_attributes , 0 )
671671
672+ def test_link_dropped_attributes (self ):
673+ link1 = trace_api .Link (
674+ mock .Mock (spec = trace_api .SpanContext ),
675+ BoundedAttributes (0 , attributes = {"bar1" : "baz1" }),
676+ )
677+ self .assertEqual (link1 .dropped_attributes , 1 )
678+
679+ link2 = trace_api .Link (
680+ mock .Mock (spec = trace_api .SpanContext ),
681+ {"bar2" : "baz2" },
682+ )
683+ self .assertEqual (link2 .dropped_attributes , 0 )
684+
672685
673686class DummyError (Exception ):
674687 pass
@@ -1897,7 +1910,7 @@ def test_dropped_attributes(self):
18971910 self .assertEqual (2 , span .dropped_attributes )
18981911 self .assertEqual (3 , span .dropped_events )
18991912 self .assertEqual (2 , span .events [0 ].dropped_attributes )
1900- self .assertEqual (2 , span .links [0 ].attributes . dropped )
1913+ self .assertEqual (2 , span .links [0 ].dropped_attributes )
19011914
19021915 def _test_span_limits (
19031916 self ,
You can’t perform that action at this time.
0 commit comments