Skip to content

Commit 693ace0

Browse files
committed
add extra unit tests
1 parent 2bd2593 commit 693ace0

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/exporter/otlp/aws/logs/otlp_aws_logs_exporter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
class OTLPAwsLogExporter(OTLPLogExporter):
3030
"""
31-
Below is the protobuf-JSON formatted path to "content" and "role" for the following GenAI Consolidated Log Event Schema:
31+
Below is the protobuf-JSON formatted path to "content" and "role" for the
32+
following GenAI Consolidated Log Event Schema:
3233
3334
"body": {
3435
"output": {
@@ -188,7 +189,7 @@ def _send(self, serialized_data: bytes):
188189
cert=self._client_cert,
189190
)
190191
return response
191-
except ConnectionError:
192+
except requests.exceptions.ConnectionError:
192193
response = self._session.post(
193194
url=self._endpoint,
194195
headers={self._LARGE_LOG_HEADER: self._LARGE_GEN_AI_LOG_PATH_HEADER} if self._gen_ai_log_flag else None,

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/exporter/otlp/aws/common/test_aws_auth_session.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,18 @@ def test_aws_auth_session(self, _, __):
6363
self.assertIn(AUTHORIZATION_HEADER, actual_headers)
6464
self.assertIn(X_AMZ_DATE_HEADER, actual_headers)
6565
self.assertIn(X_AMZ_SECURITY_TOKEN_HEADER, actual_headers)
66+
67+
@patch("requests.Session.request", return_value=requests.Response())
68+
@patch("botocore.session.Session.get_credentials", return_value=mock_credentials)
69+
@patch("botocore.auth.SigV4Auth.add_auth", side_effect=Exception("Signing failed"))
70+
def test_aws_auth_session_signing_error(self, mock_add_auth, mock_get_credentials, mock_request):
71+
"""Tests that aws_auth_session does not any Sigv4 headers if signing errors."""
72+
73+
session = AwsAuthSession("us-east-1", "xray")
74+
actual_headers = {"test": "test"}
75+
76+
session.request("POST", AWS_OTLP_TRACES_ENDPOINT, data="", headers=actual_headers)
77+
78+
self.assertNotIn(AUTHORIZATION_HEADER, actual_headers)
79+
self.assertNotIn(X_AMZ_DATE_HEADER, actual_headers)
80+
self.assertNotIn(X_AMZ_SECURITY_TOKEN_HEADER, actual_headers)

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/exporter/otlp/aws/logs/test_aws_batch_log_record_processor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
)
1010
from opentelemetry._logs.severity import SeverityNumber
1111
from opentelemetry.sdk._logs import LogData, LogRecord
12-
from opentelemetry.sdk._logs._internal import LogLimits
1312
from opentelemetry.sdk._logs.export import LogExportResult
1413
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
1514
from opentelemetry.trace import TraceFlags

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/exporter/otlp/aws/logs/test_otlp_aws_logs_exporter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def test_should_export_again_with_backoff_delay_if_retryable_and_bad_retry_after
159159
self.assertEqual(mock_request.call_count, 4)
160160
self.assertEqual(result, LogExportResult.SUCCESS)
161161

162+
@patch("requests.Session.post", side_effect=[requests.exceptions.ConnectionError(), good_response])
163+
def test_export_connection_error_retry(self, mock_request):
164+
"""Tests that the exporter retries on ConnectionError."""
165+
result = self.exporter.export(self.logs)
166+
167+
self.assertEqual(mock_request.call_count, 2)
168+
self.assertEqual(result, LogExportResult.SUCCESS)
169+
162170
def generate_test_log_data(self, count=5):
163171
logs = []
164172
for i in range(count):

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/exporter/otlp/aws/metrics/test_aws_cloudwatch_emf_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from botocore.exceptions import ClientError
1010

11-
from amazon.opentelemetry.distro.exporter.aws.metrics.aws_cloudwatch_emf_exporter import AwsCloudWatchEmfExporter
11+
from amazon.opentelemetry.distro.exporter.otlp.aws.metrics.aws_cloudwatch_emf_exporter import AwsCloudWatchEmfExporter
1212
from opentelemetry.sdk.metrics.export import Gauge, MetricExportResult
1313
from opentelemetry.sdk.resources import Resource
1414

0 commit comments

Comments
 (0)