Skip to content

Commit 928a5be

Browse files
XinRanZhAWSADOT Patch workflow
andauthored
Implement Unit Test for AWS Metric Attributes Span Exporter (#30)
*Description of changes:* Implement Unit Test for AWS Metric Attributes Span Exporter By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: ADOT Patch workflow <[email protected]>
1 parent ab460ea commit 928a5be

File tree

2 files changed

+395
-14
lines changed

2 files changed

+395
-14
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_metric_attributes_span_exporter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
import copy
34
from typing import List, Sequence, TypeVar
45

56
from typing_extensions import override
@@ -102,12 +103,11 @@ def copy_attributes_with_local_root(attributes: BoundedAttributes) -> BoundedAtt
102103
)
103104

104105

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.
109106
def wrap_span_with_attributes(span: ReadableSpan, attributes: BoundedAttributes) -> ReadableSpan:
110-
original_attributes: AttributesT = span.attributes
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
111111
update_attributes: types.Attributes = {}
112112
# Copy all attribute in span into update_attributes
113113
for key, value in original_attributes.items():
@@ -117,12 +117,12 @@ def wrap_span_with_attributes(span: ReadableSpan, attributes: BoundedAttributes)
117117
update_attributes[key] = value
118118

119119
if isinstance(original_attributes, BoundedAttributes):
120-
span._attributes = BoundedAttributes(
120+
new_span._attributes = BoundedAttributes(
121121
maxlen=original_attributes.maxlen,
122122
attributes=update_attributes,
123123
immutable=original_attributes._immutable,
124124
max_value_len=original_attributes.max_value_len,
125125
)
126126
else:
127-
span._attributes = update_attributes
128-
return span
127+
new_span._attributes = update_attributes
128+
return new_span

0 commit comments

Comments
 (0)