1
1
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
# SPDX-License-Identifier: Apache-2.0
3
+ from typing import List
4
+
3
5
from mock_collector_client import ResourceScopeMetric , ResourceScopeSpan
4
6
from requests import Response , request
5
7
from typing_extensions import override
@@ -27,7 +29,7 @@ def get_application_image_name(self) -> str:
27
29
return "aws-appsignals-tests-requests-app"
28
30
29
31
@override
30
- def get_application_network_aliases (self ) -> list [str ]:
32
+ def get_application_network_aliases (self ) -> List [str ]:
31
33
"""
32
34
This will be the target hostname of the clients making http requests in the application image, so that they
33
35
don't use localhost.
@@ -70,21 +72,21 @@ def do_test_requests(
70
72
71
73
self .assertEqual (status_code , response .status_code )
72
74
73
- resource_scope_spans : list [ResourceScopeSpan ] = self ._mock_collector_client .get_traces ()
75
+ resource_scope_spans : List [ResourceScopeSpan ] = self ._mock_collector_client .get_traces ()
74
76
self ._assert_aws_span_attributes (resource_scope_spans , method , path )
75
77
self ._assert_semantic_conventions_span_attributes (resource_scope_spans , method , path , status_code )
76
78
77
- metrics : list [ResourceScopeMetric ] = self ._mock_collector_client .get_metrics (
79
+ metrics : List [ResourceScopeMetric ] = self ._mock_collector_client .get_metrics (
78
80
{LATENCY_METRIC , ERROR_METRIC , FAULT_METRIC }
79
81
)
80
82
self ._assert_metric_attributes (metrics , method , path , LATENCY_METRIC , 5000 )
81
83
self ._assert_metric_attributes (metrics , method , path , ERROR_METRIC , expected_error )
82
84
self ._assert_metric_attributes (metrics , method , path , FAULT_METRIC , expected_fault )
83
85
84
86
def _assert_aws_span_attributes (
85
- self , resource_scope_spans : list [ResourceScopeSpan ], method : str , path : str
87
+ self , resource_scope_spans : List [ResourceScopeSpan ], method : str , path : str
86
88
) -> None :
87
- target_spans : list [Span ] = []
89
+ target_spans : List [Span ] = []
88
90
for resource_scope_span in resource_scope_spans :
89
91
# pylint: disable=no-member
90
92
if resource_scope_span .span .kind == Span .SPAN_KIND_CLIENT :
@@ -93,7 +95,7 @@ def _assert_aws_span_attributes(
93
95
self .assertEqual (len (target_spans ), 1 )
94
96
self ._assert_aws_attributes (target_spans [0 ].attributes , method , path )
95
97
96
- def _assert_aws_attributes (self , attributes_list : list [KeyValue ], method : str , endpoint : str ) -> None :
98
+ def _assert_aws_attributes (self , attributes_list : List [KeyValue ], method : str , endpoint : str ) -> None :
97
99
attributes_dict : dict [str , AnyValue ] = self ._get_attributes_dict (attributes_list )
98
100
self ._assert_str_attribute (attributes_dict , AWS_LOCAL_SERVICE , self .get_application_otel_service_name ())
99
101
# InternalOperation as OTEL does not instrument the basic server we are using, so the client span is a local
@@ -106,7 +108,7 @@ def _assert_aws_attributes(self, attributes_list: list[KeyValue], method: str, e
106
108
# See comment above AWS_LOCAL_OPERATION
107
109
self ._assert_str_attribute (attributes_dict , AWS_SPAN_KIND , "LOCAL_ROOT" )
108
110
109
- def _get_attributes_dict (self , attributes_list : list [KeyValue ]) -> dict [str , AnyValue ]:
111
+ def _get_attributes_dict (self , attributes_list : List [KeyValue ]) -> dict [str , AnyValue ]:
110
112
attributes_dict : dict [str , AnyValue ] = {}
111
113
for attribute in attributes_list :
112
114
key : str = attribute .key
@@ -129,9 +131,9 @@ def _assert_int_attribute(self, attributes_dict: dict[str, AnyValue], key: str,
129
131
self .assertEqual (expected_value , actual_value .int_value )
130
132
131
133
def _assert_semantic_conventions_span_attributes (
132
- self , resource_scope_spans : list [ResourceScopeSpan ], method : str , path : str , status_code : int
134
+ self , resource_scope_spans : List [ResourceScopeSpan ], method : str , path : str , status_code : int
133
135
) -> None :
134
- target_spans : list [Span ] = []
136
+ target_spans : List [Span ] = []
135
137
for resource_scope_span in resource_scope_spans :
136
138
# pylint: disable=no-member
137
139
if resource_scope_span .span .kind == Span .SPAN_KIND_CLIENT :
@@ -142,7 +144,7 @@ def _assert_semantic_conventions_span_attributes(
142
144
self ._assert_semantic_conventions_attributes (target_spans [0 ].attributes , method , path , status_code )
143
145
144
146
def _assert_semantic_conventions_attributes (
145
- self , attributes_list : list [KeyValue ], method : str , endpoint : str , status_code : int
147
+ self , attributes_list : List [KeyValue ], method : str , endpoint : str , status_code : int
146
148
) -> None :
147
149
attributes_dict : dict [str , AnyValue ] = self ._get_attributes_dict (attributes_list )
148
150
# TODO: requests instrumentation is not populating net peer attributes
@@ -156,20 +158,20 @@ def _assert_semantic_conventions_attributes(
156
158
157
159
def _assert_metric_attributes (
158
160
self ,
159
- resource_scope_metrics : list [ResourceScopeMetric ],
161
+ resource_scope_metrics : List [ResourceScopeMetric ],
160
162
method : str ,
161
163
path : str ,
162
164
metric_name : str ,
163
165
expected_sum : float ,
164
166
) -> None :
165
- target_metrics : list [Metric ] = []
167
+ target_metrics : List [Metric ] = []
166
168
for resource_scope_metric in resource_scope_metrics :
167
169
if resource_scope_metric .metric .name == metric_name :
168
170
target_metrics .append (resource_scope_metric .metric )
169
171
170
172
self .assertEqual (len (target_metrics ), 1 )
171
173
target_metric : Metric = target_metrics [0 ]
172
- dp_list : list [ExponentialHistogramDataPoint ] = target_metric .exponential_histogram .data_points
174
+ dp_list : List [ExponentialHistogramDataPoint ] = target_metric .exponential_histogram .data_points
173
175
174
176
self .assertEqual (len (dp_list ), 2 )
175
177
dp : ExponentialHistogramDataPoint = dp_list [0 ]
0 commit comments