@@ -38,15 +38,6 @@ def setUp(self):
38
38
self .create_span ("test_span5" , SpanKind .CONSUMER ),
39
39
]
40
40
41
- self .invalid_otlp_tracing_endpoints = [
42
- "https://xray.us-east-1.amaz.com/v1/traces" ,
43
- "https://logs.us-east-1.amazonaws.com/v1/logs" ,
44
- "https://test-endpoint123.com/test" ,
45
- "xray.us-east-1.amazonaws.com/v1/traces" ,
46
- "https://test-endpoint123.com/test https://xray.us-east-1.amazonaws.com/v1/traces" ,
47
- "https://xray.us-east-1.amazonaws.com/v1/tracesssda" ,
48
- ]
49
-
50
41
self .expected_auth_header = "AWS4-HMAC-SHA256 Credential=test_key/some_date/us-east-1/xray/aws4_request"
51
42
self .expected_auth_x_amz_date = "some_date"
52
43
self .expected_auth_security_token = "test_token"
@@ -88,73 +79,6 @@ def test_sigv4_exporter_init_valid_cw_otlp_endpoint(self, session_mock):
88
79
self .assertEqual (exporter ._aws_region , "us-east-1" )
89
80
self .validate_exporter_extends_http_span_exporter (exporter , OTLP_XRAY_ENDPOINT )
90
81
91
- def test_sigv4_exporter_init_invalid_cw_otlp_endpoint (self ):
92
- """Tests that the exporter constructor behavior is set by OTLP protobuf/http Span Exporter
93
- if an invalid OTLP CloudWatch endpoint is set"""
94
- for bad_endpoint in self .invalid_otlp_tracing_endpoints :
95
- with self .subTest (endpoint = bad_endpoint ):
96
- with patch .dict (os .environ , {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : bad_endpoint }):
97
- exporter = OTLPAwsSpanExporter (endpoint = bad_endpoint )
98
- self .validate_exporter_extends_http_span_exporter (exporter , bad_endpoint )
99
-
100
- self .assertIsNone (exporter ._aws_region )
101
-
102
- @patch ("requests.Session.post" )
103
- @patch ("botocore.auth.SigV4Auth.add_auth" )
104
- @patch ("botocore.session.Session" )
105
- def test_sigv4_exporter_export_does_not_add_sigv4_if_not_valid_cw_endpoint (
106
- self , botocore_mock , mock_sigv4_auth , requests_mock
107
- ):
108
- """Tests that if the OTLP endpoint is not a valid XRay endpoint but the credentials are valid,
109
- SigV4 authentication method is called but fails so NO headers are injected into the existing Session headers."""
110
-
111
- # Setting the exporter response
112
- mock_response = MagicMock ()
113
- mock_response .status_code = 200
114
- type(mock_response ).ok = PropertyMock (return_value = True )
115
-
116
- # Setting the request session headers to make the call to endpoint
117
- mock_session = MagicMock ()
118
- mock_session .headers = {"User-Agent" : USER_AGENT , "Content-Type" : CONTENT_TYPE }
119
- requests_mock .return_value = mock_session
120
- mock_session .post .return_value = mock_response
121
-
122
- # SigV4 mock authentication injection
123
- mock_sigv4_auth .side_effect = self .mock_add_auth
124
-
125
- mock_botocore_session = MagicMock ()
126
- botocore_mock .return_value = mock_botocore_session
127
-
128
- mock_botocore_session .get_credentials .return_value = Credentials (
129
- access_key = "test_key" , secret_key = "test_secret" , token = "test_token"
130
- )
131
-
132
- # For each invalid CW OTLP endpoint, validate that SigV4 is not injected
133
- self .invalid_otlp_tracing_endpoints .append ("https://xray.bad-region-1.amazonaws.com/v1/traces" )
134
- for bad_endpoint in self .invalid_otlp_tracing_endpoints :
135
- with self .subTest (endpoint = bad_endpoint ):
136
- with patch .dict (os .environ , {OTEL_EXPORTER_OTLP_TRACES_ENDPOINT : bad_endpoint }):
137
-
138
- exporter = OTLPAwsSpanExporter (endpoint = bad_endpoint )
139
-
140
- self .validate_exporter_extends_http_span_exporter (exporter , bad_endpoint )
141
-
142
- exporter .export (self .testing_spans )
143
-
144
- # Verify that SigV4 request headers were not injected
145
- actual_headers = mock_session .headers
146
- self .assertNotIn (AUTHORIZATION_HEADER , actual_headers )
147
- self .assertNotIn (X_AMZ_DATE_HEADER , actual_headers )
148
- self .assertNotIn (X_AMZ_SECURITY_TOKEN_HEADER , actual_headers )
149
-
150
- requests_mock .assert_called_with (
151
- url = bad_endpoint ,
152
- data = ANY ,
153
- verify = ANY ,
154
- timeout = ANY ,
155
- cert = ANY ,
156
- )
157
-
158
82
@patch ("botocore.session.Session" )
159
83
@patch ("requests.Session" )
160
84
@patch ("botocore.auth.SigV4Auth.add_auth" )
0 commit comments