21
21
from opentelemetry .trace import SpanContext , SpanKind
22
22
from opentelemetry .util .types import Attributes
23
23
24
+ _CONTAINS_ATTRIBUTES : bool = True
25
+ _CONTAINS_NO_ATTRIBUTES : bool = False
26
+
24
27
25
28
class TestAwsMetricAttributesSpanExporter (TestCase ):
26
- _CONTAINS_ATTRIBUTES : bool = True
27
- _CONTAINS_NO_ATTRIBUTES : bool = False
28
29
29
30
def setUp (self ):
30
31
self .delegate_mock : SpanExporter = MagicMock ()
@@ -40,9 +41,9 @@ def test_pass_through_delegations(self):
40
41
self .delegate_mock .assert_has_calls ([call .force_flush (30000 ), call .shutdown ()])
41
42
42
43
def test_export_delegation_without_attributes_or_modification (self ):
43
- span_attributes : Attributes = _build_span_attributes (self . _CONTAINS_NO_ATTRIBUTES )
44
+ span_attributes : Attributes = _build_span_attributes (_CONTAINS_NO_ATTRIBUTES )
44
45
span_data_mock : ReadableSpan = _build_readable_span_mock (span_attributes )
45
- metric_attributes : Attributes = _build_metric_attributes (self . _CONTAINS_NO_ATTRIBUTES )
46
+ metric_attributes : Attributes = _build_metric_attributes (_CONTAINS_NO_ATTRIBUTES )
46
47
self .__configure_mock_for_export (span_data_mock , metric_attributes )
47
48
48
49
self .aws_metric_attributes_span_exporter .export ([span_data_mock ])
@@ -53,9 +54,9 @@ def test_export_delegation_without_attributes_or_modification(self):
53
54
self .assertEqual (span_data_mock , exported_span )
54
55
55
56
def test_export_delegation_with_attributes_but_without_modification (self ):
56
- span_attributes : Attributes = _build_span_attributes (self . _CONTAINS_ATTRIBUTES )
57
+ span_attributes : Attributes = _build_span_attributes (_CONTAINS_ATTRIBUTES )
57
58
span_data_mock : ReadableSpan = _build_readable_span_mock (span_attributes )
58
- metric_attributes : Attributes = _build_metric_attributes (self . _CONTAINS_NO_ATTRIBUTES )
59
+ metric_attributes : Attributes = _build_metric_attributes (_CONTAINS_NO_ATTRIBUTES )
59
60
self .__configure_mock_for_export (span_data_mock , metric_attributes )
60
61
61
62
self .aws_metric_attributes_span_exporter .export ([span_data_mock ])
@@ -66,9 +67,9 @@ def test_export_delegation_with_attributes_but_without_modification(self):
66
67
self .assertEqual (span_data_mock , exported_span )
67
68
68
69
def test_export_delegation_without_attributes_but_with_modification (self ):
69
- span_attributes : Attributes = _build_span_attributes (self . _CONTAINS_NO_ATTRIBUTES )
70
+ span_attributes : Attributes = _build_span_attributes (_CONTAINS_NO_ATTRIBUTES )
70
71
span_data_mock : ReadableSpan = _build_readable_span_mock (span_attributes )
71
- metric_attributes : Attributes = _build_metric_attributes (self . _CONTAINS_ATTRIBUTES )
72
+ metric_attributes : Attributes = _build_metric_attributes (_CONTAINS_ATTRIBUTES )
72
73
self .__configure_mock_for_export (span_data_mock , metric_attributes )
73
74
74
75
self .aws_metric_attributes_span_exporter .export ([span_data_mock ])
@@ -82,9 +83,9 @@ def test_export_delegation_without_attributes_but_with_modification(self):
82
83
self .assertEqual (exported_span ._attributes [key ], value )
83
84
84
85
def test_export_delegation_with_attributes_and_modification (self ):
85
- span_attributes : Attributes = _build_span_attributes (self . _CONTAINS_ATTRIBUTES )
86
+ span_attributes : Attributes = _build_span_attributes (_CONTAINS_ATTRIBUTES )
86
87
span_data_mock : ReadableSpan = _build_readable_span_mock (span_attributes )
87
- metric_attributes : Attributes = _build_metric_attributes (self . _CONTAINS_ATTRIBUTES )
88
+ metric_attributes : Attributes = _build_metric_attributes (_CONTAINS_ATTRIBUTES )
88
89
self .__configure_mock_for_export (span_data_mock , metric_attributes )
89
90
90
91
self .aws_metric_attributes_span_exporter .export ([span_data_mock ])
@@ -98,15 +99,15 @@ def test_export_delegation_with_attributes_and_modification(self):
98
99
self .assertEqual (exported_span ._attributes [key ], value )
99
100
100
101
def test_export_delegation_with_multiple_spans (self ):
101
- span_data_mock1 : ReadableSpan = _build_readable_span_mock (_build_span_attributes (self . _CONTAINS_NO_ATTRIBUTES ))
102
- metric_attributes1 : Attributes = _build_metric_attributes (self . _CONTAINS_NO_ATTRIBUTES )
102
+ span_data_mock1 : ReadableSpan = _build_readable_span_mock (_build_span_attributes (_CONTAINS_NO_ATTRIBUTES ))
103
+ metric_attributes1 : Attributes = _build_metric_attributes (_CONTAINS_NO_ATTRIBUTES )
103
104
104
- span_attributes2 : Attributes = _build_span_attributes (self . _CONTAINS_ATTRIBUTES )
105
+ span_attributes2 : Attributes = _build_span_attributes (_CONTAINS_ATTRIBUTES )
105
106
span_data_mock2 : ReadableSpan = _build_readable_span_mock (span_attributes2 )
106
- metric_attributes2 : Attributes = _build_metric_attributes (self . _CONTAINS_ATTRIBUTES )
107
+ metric_attributes2 : Attributes = _build_metric_attributes (_CONTAINS_ATTRIBUTES )
107
108
108
- span_data_mock3 : ReadableSpan = _build_readable_span_mock (_build_span_attributes (self . _CONTAINS_ATTRIBUTES ))
109
- metric_attributes3 : Attributes = _build_metric_attributes (self . _CONTAINS_NO_ATTRIBUTES )
109
+ span_data_mock3 : ReadableSpan = _build_readable_span_mock (_build_span_attributes (_CONTAINS_ATTRIBUTES ))
110
+ metric_attributes3 : Attributes = _build_metric_attributes (_CONTAINS_NO_ATTRIBUTES )
110
111
111
112
self .__configure_mock_for_export_with_multiple_side_effect (
112
113
[span_data_mock1 , span_data_mock2 , span_data_mock3 ],
@@ -152,9 +153,9 @@ def test_overridden_attributes(self):
152
153
self .assertEqual (exported_span ._attributes ["key3" ], "new value3" )
153
154
154
155
def test_export_delegating_span_data_behaviour (self ):
155
- span_attributes = _build_span_attributes (self . _CONTAINS_ATTRIBUTES )
156
+ span_attributes = _build_span_attributes (_CONTAINS_ATTRIBUTES )
156
157
span_data_mock = _build_readable_span_mock_without_deepcopy_support (span_attributes )
157
- metric_attributes = _build_metric_attributes (self . _CONTAINS_ATTRIBUTES )
158
+ metric_attributes = _build_metric_attributes (_CONTAINS_ATTRIBUTES )
158
159
self .__configure_mock_for_export (span_data_mock , metric_attributes )
159
160
160
161
self .aws_metric_attributes_span_exporter .export ([span_data_mock ])
@@ -200,7 +201,7 @@ def test_export_delegating_span_data_behaviour(self):
200
201
self .assertEqual (exported_span .status , status_mock )
201
202
202
203
def test_export_delegation_with_two_metrics (self ):
203
- span_attributes = _build_span_attributes (self . _CONTAINS_ATTRIBUTES )
204
+ span_attributes = _build_span_attributes (_CONTAINS_ATTRIBUTES )
204
205
205
206
span_data_mock = MagicMock ()
206
207
span_data_mock ._attributes = span_attributes
@@ -276,7 +277,7 @@ def test_consumer_process_span_has_empty_attribute(self):
276
277
self .assertEqual (exported_span , span_data_mock )
277
278
278
279
def test_export_delegation_with_dependency_metrics (self ):
279
- span_attributes = _build_span_attributes (self . _CONTAINS_ATTRIBUTES )
280
+ span_attributes = _build_span_attributes (_CONTAINS_ATTRIBUTES )
280
281
span_data_mock : ReadableSpan = MagicMock ()
281
282
span_context_mock : SpanContext = SpanContext (1 , 1 , False )
282
283
span_data_mock .attributes = span_attributes
@@ -327,7 +328,7 @@ def generate_metric_attribute_map_side_effect(span, resource):
327
328
)
328
329
329
330
def __configure_mock_for_export_with_multiple_side_effect (
330
- self , span_data_mocks : [ReadableSpan ], metric_attributes_list : [Attributes ]
331
+ self , span_data_mocks : [ReadableSpan ], metric_attributes_list : [Attributes ]
331
332
):
332
333
attributes_map_list : list = []
333
334
for span in span_data_mocks :
0 commit comments