Skip to content

Commit 502eb01

Browse files
committed
linting + formatting fix
1 parent 6dd6a67 commit 502eb01

File tree

5 files changed

+53
-24
lines changed

5 files changed

+53
-24
lines changed

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
3-
# Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.
3+
# Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
44

55
import logging
66
from typing import Mapping, Optional, Sequence, cast
@@ -136,10 +136,33 @@ def _estimate_log_size(self, log: LogData, depth: int = 3) -> int: # pylint: di
136136
"""
137137
Estimates the size in bytes of a log by calculating the size of its body and its attributes
138138
and adding a buffer amount to account for other log metadata information.
139-
Will process complex log structures up to the specified depth limit.
140-
Includes cycle detection to prevent processing the log content more than once.
141-
If the depth limit of the log structure is exceeded, returns the truncated calculation
142-
to everything up to that point.
139+
140+
Features:
141+
- Processes complex log structures up to the specified depth limit
142+
- Includes cycle detection to prevent processing the same content more than once
143+
- Returns truncated calculation if depth limit is exceeded
144+
145+
We set depth to 3 as this is the minimum required depth to estimate our consolidated Gen AI log events:
146+
147+
Example structure:
148+
{
149+
"output": {
150+
"messages": [
151+
{
152+
"content": "Hello, World!",
153+
"role": "assistant"
154+
}
155+
]
156+
},
157+
"input": {
158+
"messages": [
159+
{
160+
"content": "Say Hello, World!",
161+
"role": "user"
162+
}
163+
]
164+
}
165+
}
143166
144167
Args:
145168
log: The Log object to calculate size for

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
3-
# Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.
3+
# Modifications Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
44

55
import gzip
66
import logging

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,3 @@ 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def test_process_log_data_nested_structure_size_exceeds_max_log_size(self):
117117
def test_process_log_data_primitive(self):
118118

119119
primitives: List[AnyValue] = ["test", b"test", 1, 1.2, True, False, None, "深入 Python", "café"]
120-
expected_sizes = [4, 4, 1, 3, 4, 5, 0, 2 * 4 + len(" Python"), 1 * 4 + len("caf")]
120+
expected_sizes = [4, 4, 1, 3, 4, 5, 0, 2 * 4 + len(" Python"), 1 * 4 + len("calf")]
121121

122122
for index, primitive in enumerate(primitives):
123123
log = self.generate_test_log_data(log_body=primitive, count=1)

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelementry_configurator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
OtlpLogHeaderSetting,
2727
_check_emf_exporter_enabled,
2828
_custom_import_sampler,
29+
_customize_log_record_processor,
2930
_customize_logs_exporter,
3031
_customize_metric_exporters,
3132
_customize_resource,
@@ -1009,6 +1010,26 @@ def test_validate_and_fetch_logs_header(self):
10091010
# Clean up
10101011
os.environ.pop(OTEL_EXPORTER_OTLP_LOGS_HEADERS, None)
10111012

1013+
@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator.is_agent_observability_enabled")
1014+
@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator._is_aws_otlp_endpoint")
1015+
def test_customize_log_record_processor_with_agent_observability(self, mock_is_aws_endpoint, mock_is_agent_enabled):
1016+
"""Test that AwsCloudWatchOtlpBatchLogRecordProcessor is used when agent observability is enabled and endpoint is logs endpoint"""
1017+
from amazon.opentelemetry.distro.exporter.otlp.aws.logs.aws_batch_log_record_processor import (
1018+
AwsCloudWatchOtlpBatchLogRecordProcessor,
1019+
)
1020+
from amazon.opentelemetry.distro.exporter.otlp.aws.logs.otlp_aws_logs_exporter import OTLPAwsLogExporter
1021+
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
1022+
1023+
# Mock the OTLPAwsLogExporter
1024+
mock_exporter = MagicMock(spec=OTLPAwsLogExporter)
1025+
1026+
# Test case 1: Agent observability enabled and AWS logs endpoint
1027+
mock_is_agent_enabled.return_value = True
1028+
mock_is_aws_endpoint.return_value = True
1029+
1030+
processor = _customize_log_record_processor(mock_exporter)
1031+
self.assertIsInstance(processor, AwsCloudWatchOtlpBatchLogRecordProcessor)
1032+
10121033
@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator._validate_and_fetch_logs_header")
10131034
@patch("amazon.opentelemetry.distro.aws_opentelemetry_configurator.is_installed")
10141035
def test_create_emf_exporter(self, mock_is_installed, mock_validate):

0 commit comments

Comments
 (0)