1313 DEFAULT_ENDPOINT ,
1414 DEFAULT_TIMEOUT ,
1515 DEFAULT_TRACES_EXPORT_PATH ,
16+ OTLPSpanExporter ,
1617)
1718from opentelemetry .exporter .otlp .proto .http .version import __version__
1819from opentelemetry .sdk .environment_variables import OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
@@ -42,24 +43,29 @@ def setUp(self):
4243 "https://xray.us-east-1.amaz.com/v1/traces" ,
4344 "https://logs.us-east-1.amazonaws.com/v1/logs" ,
4445 "https://test-endpoint123.com/test" ,
46+ "xray.us-east-1.amazonaws.com/v1/traces" ,
47+ "https://test-endpoint123.com/test https://xray.us-east-1.amazonaws.com/v1/traces" ,
48+ "https://xray.us-east-1.amazonaws.com/v1/tracesssda" ,
4549 ]
4650
4751 self .expected_auth_header = "AWS4-HMAC-SHA256 Credential=test_key/some_date/us-east-1/xray/aws4_request"
4852 self .expected_auth_x_amz_date = "some_date"
4953 self .expected_auth_security_token = "test_token"
5054
51- # Tests that the default exporter is OTLP protobuf/http Span Exporter if no endpoint is set
5255 @patch .dict (os .environ , {}, clear = True )
5356 def test_sigv4_exporter_init_default (self ):
57+ """Tests that the default exporter is OTLP protobuf/http Span Exporter if no endpoint is set"""
58+
5459 exporter = OTLPAwsSigV4Exporter ()
5560 self .validate_exporter_extends_http_span_exporter (exporter , DEFAULT_ENDPOINT + DEFAULT_TRACES_EXPORT_PATH )
5661 self .assertIsInstance (exporter ._session , requests .Session )
5762
58- # Tests that the endpoint is validated and sets the aws_region but still uses the OTLP protobuf/http
59- # Span Exporter exporter constructor behavior if a valid OTLP CloudWatch endpoint is set
6063 @patch .dict (os .environ , {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : OTLP_CW_ENDPOINT }, clear = True )
6164 @patch ("botocore.session.Session" )
6265 def test_sigv4_exporter_init_valid_cw_otlp_endpoint (self , session_mock ):
66+ """Tests that the endpoint is validated and sets the aws_region but still uses the OTLP protobuf/http
67+ Span Exporter exporter constructor behavior if a valid OTLP CloudWatch endpoint is set."""
68+
6369 mock_session = MagicMock ()
6470 session_mock .return_value = mock_session
6571
@@ -71,12 +77,18 @@ def test_sigv4_exporter_init_valid_cw_otlp_endpoint(self, session_mock):
7177
7278 mock_session .get_available_regions .assert_called_once_with ("xray" )
7379
74- # Tests that the exporter constructor behavior
75- # is set by OTLP protobuf/http Span Exporter
76- # if an invalid OTLP CloudWatch endpoint is set
80+ @patch .dict ("sys.modules" , {"botocore" : None })
81+ def test_no_botocore_valid_xray_endpoint (self ):
82+ """Test that exporter defaults when using OTLP CW endpoint without botocore"""
83+
84+ exporter = OTLPAwsSigV4Exporter (endpoint = OTLP_CW_ENDPOINT )
85+
86+ self .assertIsNone (exporter ._aws_region )
87+
7788 @patch ("botocore.session.Session" )
7889 def test_sigv4_exporter_init_invalid_cw_otlp_endpoint (self , botocore_mock ):
79-
90+ """Tests that the exporter constructor behavior is set by OTLP protobuf/http Span Exporter
91+ if an invalid OTLP CloudWatch endpoint is set"""
8092 for bad_endpoint in self .invalid_cw_otlp_tracing_endpoints :
8193 with self .subTest (endpoint = bad_endpoint ):
8294 with patch .dict (os .environ , {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : bad_endpoint }):
@@ -90,15 +102,15 @@ def test_sigv4_exporter_init_invalid_cw_otlp_endpoint(self, botocore_mock):
90102
91103 self .assertIsNone (exporter ._aws_region )
92104
93- # Tests that if the OTLP endpoint is not a valid CW endpoint but the credentials are valid,
94- # SigV4 authentication method is NOT called and is
95- # NOT injected into the existing Session headers.
96105 @patch ("botocore.session.Session.get_available_regions" )
97106 @patch ("requests.Session.post" )
98107 @patch ("botocore.auth.SigV4Auth.add_auth" )
99108 def test_sigv4_exporter_export_does_not_add_sigv4_if_not_valid_cw_endpoint (
100109 self , mock_sigv4_auth , requests_mock , botocore_mock
101110 ):
111+ """Tests that if the OTLP endpoint is not a valid CW endpoint but the credentials are valid,
112+ SigV4 authentication method is NOT called and is NOT injected into the existing Session headers."""
113+
102114 # Setting the exporter response
103115 mock_response = MagicMock ()
104116 mock_response .status_code = 200
@@ -155,17 +167,16 @@ def test_sigv4_exporter_export_does_not_add_sigv4_if_not_valid_cw_endpoint(
155167 cert = ANY ,
156168 )
157169
158- # Tests that if the OTLP endpoint is a valid CW endpoint but no credentials are returned,
159- # SigV4 authentication method is NOT called and is NOT
160- # injected into the existing Session headers.
161170 @patch ("botocore.session.Session" )
162171 @patch ("requests.Session" )
163172 @patch ("botocore.auth.SigV4Auth.add_auth" )
164173 @patch .dict (os .environ , {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : OTLP_CW_ENDPOINT })
165174 def test_sigv4_exporter_export_does_not_add_sigv4_if_not_valid_credentials (
166175 self , mock_sigv4_auth , requests_posts_mock , botocore_mock
167176 ):
168-
177+ """Tests that if the OTLP endpoint is a valid CW endpoint but no credentials are returned,
178+ SigV4 authentication method is NOT called and is NOT injected into the existing
179+ Session headers."""
169180 # Setting the exporter response
170181 mock_response = MagicMock ()
171182 mock_response .status_code = 200
@@ -201,16 +212,16 @@ def test_sigv4_exporter_export_does_not_add_sigv4_if_not_valid_credentials(
201212 self .assertNotIn (X_AMZ_DATE_HEADER , actual_headers )
202213 self .assertNotIn (X_AMZ_SECURITY_TOKEN_HEADER , actual_headers )
203214
204- # Tests that if the OTLP endpoint is valid and credentials are valid,
205- # SigV4 authentication method is called and is
206- # injected into the existing Session headers.
207215 @patch ("botocore.session.Session" )
208216 @patch ("requests.Session" )
209217 @patch ("botocore.auth.SigV4Auth.add_auth" )
210218 @patch .dict (os .environ , {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : OTLP_CW_ENDPOINT })
211219 def test_sigv4_exporter_export_adds_sigv4_authentication_if_valid_cw_endpoint (
212220 self , mock_sigv4_auth , requests_posts_mock , botocore_mock
213221 ):
222+ """Tests that if the OTLP endpoint is valid and credentials are valid,
223+ SigV4 authentication method is called and is
224+ injected into the existing Session headers."""
214225
215226 # Setting the exporter response
216227 mock_response = MagicMock ()
@@ -251,6 +262,7 @@ def test_sigv4_exporter_export_adds_sigv4_authentication_if_valid_cw_endpoint(
251262 self .assertEqual (actual_headers [X_AMZ_SECURITY_TOKEN_HEADER ], self .expected_auth_security_token )
252263
253264 def validate_exporter_extends_http_span_exporter (self , exporter , endpoint ):
265+ self .assertIsInstance (exporter , OTLPSpanExporter )
254266 self .assertEqual (exporter ._endpoint , endpoint )
255267 self .assertEqual (exporter ._certificate_file , True )
256268 self .assertEqual (exporter ._client_certificate_file , None )
0 commit comments