|
1 | 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2 | 2 | # SPDX-License-Identifier: Apache-2.0
|
3 | 3 | import copy
|
4 |
| -from typing import Any |
5 | 4 | from unittest import TestCase
|
6 |
| -from unittest.mock import MagicMock, Mock, call |
| 5 | +from unittest.mock import MagicMock, call |
7 | 6 |
|
8 | 7 | from amazon.opentelemetry.distro._aws_attribute_keys import AWS_CONSUMER_PARENT_SPAN_KIND, AWS_SPAN_KIND
|
9 | 8 | from amazon.opentelemetry.distro._aws_metric_attribute_generator import _AwsMetricAttributeGenerator
|
|
16 | 15 | from amazon.opentelemetry.distro.metric_attribute_generator import DEPENDENCY_METRIC, SERVICE_METRIC
|
17 | 16 | from opentelemetry.attributes import BoundedAttributes
|
18 | 17 | from opentelemetry.sdk.resources import Resource
|
19 |
| -from opentelemetry.sdk.trace import Event, ReadableSpan |
| 18 | +from opentelemetry.sdk.trace import ReadableSpan |
20 | 19 | from opentelemetry.sdk.trace.export import SpanExporter
|
21 |
| -from opentelemetry.sdk.util.instrumentation import InstrumentationScope |
22 | 20 | from opentelemetry.semconv.trace import MessagingOperationValues, SpanAttributes
|
23 |
| -from opentelemetry.trace import Link, SpanContext, SpanKind, Status |
| 21 | +from opentelemetry.trace import SpanContext, SpanKind |
24 | 22 | from opentelemetry.util.types import Attributes
|
25 | 23 |
|
26 | 24 | _CONTAINS_ATTRIBUTES: bool = True
|
@@ -158,54 +156,6 @@ def test_overridden_attributes(self):
|
158 | 156 | self.assertEqual(exported_span._attributes["key2"], "old value2")
|
159 | 157 | self.assertEqual(exported_span._attributes["key3"], "new value3")
|
160 | 158 |
|
161 |
| - def test_export_delegating_span_data_behaviour(self): |
162 |
| - span_attributes: Attributes = self._build_span_attributes(_CONTAINS_ATTRIBUTES) |
163 |
| - span_data_mock: ReadableSpan = self._build_readable_span_mock_without_deepcopy_support(span_attributes) |
164 |
| - metric_attributes: Attributes = self._build_metric_attributes(_CONTAINS_ATTRIBUTES) |
165 |
| - self._configure_mock_for_export(span_data_mock, metric_attributes) |
166 |
| - |
167 |
| - self.aws_metric_attributes_span_exporter.export([span_data_mock]) |
168 |
| - self.delegate_mock.assert_has_calls([call.export([span_data_mock])]) |
169 |
| - exported_spans: Attributes = self.delegate_mock.export.call_args[0][0] |
170 |
| - self.assertEqual(len(exported_spans), 1) |
171 |
| - |
172 |
| - exported_span: ReadableSpan = exported_spans[0] |
173 |
| - |
174 |
| - span_context_mock: SpanContext = MagicMock() |
175 |
| - span_data_mock.get_span_context.return_value = span_context_mock |
176 |
| - self.assertEqual(exported_span.get_span_context(), span_context_mock) |
177 |
| - |
178 |
| - parent_span_context_mock: SpanContext = MagicMock() |
179 |
| - span_data_mock._parent = parent_span_context_mock |
180 |
| - self.assertEqual(exported_span._parent, parent_span_context_mock) |
181 |
| - |
182 |
| - span_data_mock.set_attribute("_resource", self.test_resource) |
183 |
| - self.assertEqual(exported_span._resource, self.test_resource) |
184 |
| - |
185 |
| - test_instrumentation_scope_info: InstrumentationScope = MagicMock() |
186 |
| - span_data_mock.set_attribute("_instrumentation_scope", test_instrumentation_scope_info) |
187 |
| - self.assertEqual(exported_span._instrumentation_scope, test_instrumentation_scope_info) |
188 |
| - |
189 |
| - test_name: str = "name" |
190 |
| - span_data_mock.set_attribute("_name", test_name) |
191 |
| - self.assertEqual(exported_span._name, test_name) |
192 |
| - |
193 |
| - kind_mock: SpanKind = Mock() |
194 |
| - span_data_mock.set_attribute("_kind", kind_mock) |
195 |
| - self.assertEqual(exported_span._kind, kind_mock) |
196 |
| - |
197 |
| - events_mock: [Event] = [Mock()] |
198 |
| - span_data_mock.set_attribute("_events", events_mock) |
199 |
| - self.assertEqual(exported_span._events, events_mock) |
200 |
| - |
201 |
| - links_mock: [Link] = [Mock()] |
202 |
| - span_data_mock.set_attribute("_links", links_mock) |
203 |
| - self.assertEqual(exported_span._links, links_mock) |
204 |
| - |
205 |
| - status_mock: Status = Mock() |
206 |
| - span_data_mock.set_attribute("_status", status_mock) |
207 |
| - self.assertEqual(exported_span._status, status_mock) |
208 |
| - |
209 | 159 | def test_export_delegation_with_two_metrics(self):
|
210 | 160 | span_attributes: Attributes = self._build_span_attributes(_CONTAINS_ATTRIBUTES)
|
211 | 161 |
|
@@ -375,22 +325,3 @@ def _build_readable_span_mock(self, span_attributes: Attributes) -> ReadableSpan
|
375 | 325 | mock_span_data._parent = None
|
376 | 326 | mock_span_data.attributes = mock_span_data._attributes
|
377 | 327 | return mock_span_data
|
378 |
| - |
379 |
| - def _build_readable_span_mock_without_deepcopy_support(self, span_attributes: Attributes) -> ReadableSpan: |
380 |
| - class NoDeepCopyMock(MagicMock): |
381 |
| - def __init__(self, *args: Any, **kw: Any): |
382 |
| - super().__init__(*args, **kw) |
383 |
| - self._attributes = span_attributes |
384 |
| - self._kind = SpanKind.SERVER |
385 |
| - self._parent = None |
386 |
| - self.attributes = self._attributes |
387 |
| - |
388 |
| - def set_attribute(self, name, value): |
389 |
| - setattr(self, name, value) |
390 |
| - |
391 |
| - def __deepcopy__(self, memo): |
392 |
| - return self |
393 |
| - |
394 |
| - mock_span_data: ReadableSpan = NoDeepCopyMock() |
395 |
| - |
396 |
| - return mock_span_data |
0 commit comments