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
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
7
7
8
8
## Unreleased
9
9
10
+ - Fix use of ` link.attributes.dropped ` , which may not exist
11
+ ([ #4119 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/4119 ) )
10
12
- Running mypy on SDK resources
11
13
([ #4053 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/4053 ) )
12
14
- 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]:
157
157
trace_id = _encode_trace_id (link .context .trace_id ),
158
158
span_id = _encode_span_id (link .context .span_id ),
159
159
attributes = _encode_attributes (link .attributes ),
160
- dropped_attributes_count = link .attributes . dropped ,
160
+ dropped_attributes_count = link .dropped_attributes ,
161
161
flags = _span_flags (link .context ),
162
162
)
163
163
pb2_links .append (encoded_link )
Original file line number Diff line number Diff line change @@ -171,6 +171,7 @@ def setUp(self):
171
171
"attributes" : BoundedAttributes (
172
172
attributes = {"a" : 1 , "b" : False }
173
173
),
174
+ "dropped_attributes" : 0 ,
174
175
"kind" : OTLPSpan .SpanKind .SPAN_KIND_INTERNAL , # pylint: disable=no-member
175
176
}
176
177
)
Original file line number Diff line number Diff line change 84
84
from deprecated import deprecated
85
85
86
86
from opentelemetry import context as context_api
87
+ from opentelemetry .attributes import BoundedAttributes
87
88
from opentelemetry .context .context import Context
88
89
from opentelemetry .environment_variables import OTEL_PYTHON_TRACER_PROVIDER
89
90
from opentelemetry .trace .propagation import (
@@ -149,6 +150,12 @@ def __init__(
149
150
def attributes (self ) -> types .Attributes :
150
151
return self ._attributes
151
152
153
+ @property
154
+ def dropped_attributes (self ) -> int :
155
+ if isinstance (self ._attributes , BoundedAttributes ):
156
+ return self ._attributes .dropped
157
+ return 0
158
+
152
159
153
160
_Links = Optional [Sequence [Link ]]
154
161
Original file line number Diff line number Diff line change @@ -669,6 +669,19 @@ def test_event_dropped_attributes(self):
669
669
event2 = trace .Event ("foo2" , {"bar2" : "baz2" })
670
670
self .assertEqual (event2 .dropped_attributes , 0 )
671
671
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
+
672
685
673
686
class DummyError (Exception ):
674
687
pass
@@ -1897,7 +1910,7 @@ def test_dropped_attributes(self):
1897
1910
self .assertEqual (2 , span .dropped_attributes )
1898
1911
self .assertEqual (3 , span .dropped_events )
1899
1912
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 )
1901
1914
1902
1915
def _test_span_limits (
1903
1916
self ,
You can’t perform that action at this time.
0 commit comments