1
1
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: Apache-2.0
3
- import copy
4
3
from typing import List , Sequence , TypeVar
5
4
6
5
from typing_extensions import override
@@ -103,11 +102,12 @@ def copy_attributes_with_local_root(attributes: BoundedAttributes) -> BoundedAtt
103
102
)
104
103
105
104
105
+ # TODO: AwsMetricAttributesSpanExporter depends on internal ReadableSpan method _attributes.
106
+ # This is a bit risky but is required for our implementation.
107
+ # The risk is that the implementation of _attributes changes in the future.
108
+ # We need tests that thoroughly test this behaviour to make sure it does not change upstream.
106
109
def wrap_span_with_attributes (span : ReadableSpan , attributes : BoundedAttributes ) -> ReadableSpan :
107
- # To make sure we create a new span without influence original span's Attributes
108
- # We have to create a deepcopy for it
109
- new_span = copy .deepcopy (span )
110
- original_attributes : AttributesT = new_span .attributes
110
+ original_attributes : AttributesT = span .attributes
111
111
update_attributes : types .Attributes = {}
112
112
# Copy all attribute in span into update_attributes
113
113
for key , value in original_attributes .items ():
@@ -117,12 +117,12 @@ def wrap_span_with_attributes(span: ReadableSpan, attributes: BoundedAttributes)
117
117
update_attributes [key ] = value
118
118
119
119
if isinstance (original_attributes , BoundedAttributes ):
120
- new_span ._attributes = BoundedAttributes (
120
+ span ._attributes = BoundedAttributes (
121
121
maxlen = original_attributes .maxlen ,
122
122
attributes = update_attributes ,
123
123
immutable = original_attributes ._immutable ,
124
124
max_value_len = original_attributes .max_value_len ,
125
125
)
126
126
else :
127
- new_span ._attributes = update_attributes
128
- return new_span
127
+ span ._attributes = update_attributes
128
+ return span
0 commit comments