Skip to content

Commit b6b7cf8

Browse files
authored
Add OtlpAwsLogExporter and OtlpAwsSpanExporter (#360)
*Background:* #358 The above PR got rid of OtlpAwsSpanExporter and OtlpAwsLogExporter as to use the default upstream exporters as that was a cleaner approach. However, we need the OtlpAwsSpanExporter and OtlpAwsLogExporter classes to support later requirements for Gen AI as we need to override the export method. *Description of changes:* This PR reintroduces the OtlpAwsSpanExporter and OtlpAwsLogExporter classes to support later requirements for Gen AI as we need to override the export method. This change does not introduce anything new and the Sigv4 span + logs exporter still work as intended: Logs: ``` { "resource": { "attributes": { "aws.local.service": "test", "service.name": "test", "cloud.region": "us-west-2", "host.type": "c5.4xlarge", "cloud.availability_zone": "us-west-2c", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.language": "python", "cloud.provider": "aws", "cloud.account.id": "571600841604", "telemetry.sdk.version": "1.27.0", "host.name": "ip-172-31-7-29.us-west-2.compute.internal", "cloud.platform": "aws_ec2", "host.id": "i-0b04d6affbae7d629", "telemetry.auto.version": "0.9.0.dev0-aws" } }, "scope": { "name": "opentelemetry.sdk._logs._internal" }, "timeUnixNano": 1747074906326769664, "observedTimeUnixNano": 1747074906326822815, "severityNumber": 9, "severityText": "INFO", "body": "127.0.0.1 - - [12/May/2025 18:35:06] \"GET /server_request HTTP/1.1\" 200 -", "attributes": { "code.filepath": "/home/ec2-user/.local/lib/python3.9/site-packages/werkzeug/_internal.py", "otelTraceSampled": false, "code.function": "_log", "code.lineno": 97, "otelTraceID": "0", "otelSpanID": "0", "otelServiceName": "test" }, "traceId": "", "spanId": "" } ``` Spans: ``` { "resource": { "attributes": { "aws.local.service": "test", "service.name": "test", "cloud.region": "us-west-2", "host.type": "c5.4xlarge", "cloud.availability_zone": "us-west-2c", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.language": "python", "cloud.provider": "aws", "cloud.account.id": "571600841604", "telemetry.sdk.version": "1.27.0", "host.name": "ip-172-31-7-29.us-west-2.compute.internal", "cloud.platform": "aws_ec2", "host.id": "i-0b04d6affbae7d629", "telemetry.auto.version": "0.9.0.dev0-aws" } }, "scope": { "name": "opentelemetry.instrumentation.flask", "version": "0.48b0" }, "traceId": "68223f2d375733237e24512171012437", "spanId": "34dd5a89d7a21fdf", "flags": 256, "name": "GET /", "kind": "SERVER", "startTimeUnixNano": 1747074861988123056, "endTimeUnixNano": 1747074861988911516, "durationNano": 788460, "attributes": { "net.host.name": "localhost:8082", "aws.local.service": "test", "net.peer.port": 57356, "telemetry.extended": "true", "http.target": "/", "http.flavor": "1.1", "net.peer.ip": "127.0.0.1", "http.host": "localhost:8082", "aws.local.environment": "ec2:default", "http.status_code": 404, "aws.local.operation": "GET /", "aws.span.kind": "LOCAL_ROOT", "http.server_name": "127.0.0.1", "http.user_agent": "curl/8.5.0", "net.host.port": 8082, "PlatformType": "AWS::EC2", "http.method": "GET", "http.response.status_code": 404, "http.scheme": "http" }, "status": { "code": "UNSET" } } ``` By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent cb3a1b0 commit b6b7cf8

File tree

4 files changed

+86
-13
lines changed

4 files changed

+86
-13
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/aws_opentelemetry_configurator.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
AwsMetricAttributesSpanExporterBuilder,
2222
)
2323
from amazon.opentelemetry.distro.aws_span_metrics_processor_builder import AwsSpanMetricsProcessorBuilder
24-
from amazon.opentelemetry.distro.exporter.otlp.aws.common.aws_auth_session import AwsAuthSession
24+
from amazon.opentelemetry.distro.exporter.otlp.aws.logs.otlp_aws_logs_exporter import OTLPAwsLogExporter
25+
from amazon.opentelemetry.distro.exporter.otlp.aws.traces.otlp_aws_span_exporter import OTLPAwsSpanExporter
2526
from amazon.opentelemetry.distro.otlp_udp_exporter import OTLPUdpSpanExporter
2627
from amazon.opentelemetry.distro.sampler.aws_xray_remote_sampler import AwsXRayRemoteSampler
2728
from amazon.opentelemetry.distro.scope_based_exporter import ScopeBasedPeriodicExportingMetricReader
2829
from amazon.opentelemetry.distro.scope_based_filtering_view import ScopeBasedRetainingView
2930
from opentelemetry._logs import set_logger_provider
30-
from opentelemetry.exporter.otlp.proto.http import Compression
3131
from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter
3232
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter as OTLPHttpOTLPMetricExporter
3333
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
@@ -359,10 +359,7 @@ def _customize_span_exporter(span_exporter: SpanExporter, resource: Resource) ->
359359
_logger.info("Detected using AWS OTLP Traces Endpoint.")
360360

361361
if isinstance(span_exporter, OTLPSpanExporter):
362-
span_exporter = OTLPSpanExporter(
363-
endpoint=traces_endpoint,
364-
session=AwsAuthSession(traces_endpoint.split(".")[1], "xray"),
365-
)
362+
span_exporter = OTLPAwsSpanExporter(endpoint=traces_endpoint)
366363

367364
else:
368365
_logger.warning(
@@ -386,11 +383,7 @@ def _customize_logs_exporter(log_exporter: LogExporter, resource: Resource) -> L
386383
# Setting default compression mode to Gzip as this is the behavior in upstream's
387384
# collector otlp http exporter:
388385
# https://github.com/open-telemetry/opentelemetry-collector/tree/main/exporter/otlphttpexporter
389-
return OTLPLogExporter(
390-
endpoint=logs_endpoint,
391-
compression=Compression.Gzip,
392-
session=AwsAuthSession(logs_endpoint.split(".")[1], "logs"),
393-
)
386+
return OTLPAwsLogExporter(endpoint=logs_endpoint)
394387

395388
_logger.warning(
396389
"Improper configuration see: please export/set "
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from typing import Dict, Optional
5+
6+
from amazon.opentelemetry.distro.exporter.otlp.aws.common.aws_auth_session import AwsAuthSession
7+
from opentelemetry.exporter.otlp.proto.http import Compression
8+
from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter
9+
10+
11+
class OTLPAwsLogExporter(OTLPLogExporter):
12+
def __init__(
13+
self,
14+
endpoint: Optional[str] = None,
15+
certificate_file: Optional[str] = None,
16+
client_key_file: Optional[str] = None,
17+
client_certificate_file: Optional[str] = None,
18+
headers: Optional[Dict[str, str]] = None,
19+
timeout: Optional[int] = None,
20+
):
21+
self._aws_region = None
22+
23+
if endpoint:
24+
self._aws_region = endpoint.split(".")[1]
25+
26+
OTLPLogExporter.__init__(
27+
self,
28+
endpoint,
29+
certificate_file,
30+
client_key_file,
31+
client_certificate_file,
32+
headers,
33+
timeout,
34+
compression=Compression.Gzip,
35+
session=AwsAuthSession(aws_region=self._aws_region, service="logs"),
36+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from typing import Dict, Optional
5+
6+
from amazon.opentelemetry.distro.exporter.otlp.aws.common.aws_auth_session import AwsAuthSession
7+
from opentelemetry.exporter.otlp.proto.http import Compression
8+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
9+
10+
11+
class OTLPAwsSpanExporter(OTLPSpanExporter):
12+
def __init__(
13+
self,
14+
endpoint: Optional[str] = None,
15+
certificate_file: Optional[str] = None,
16+
client_key_file: Optional[str] = None,
17+
client_certificate_file: Optional[str] = None,
18+
headers: Optional[Dict[str, str]] = None,
19+
timeout: Optional[int] = None,
20+
compression: Optional[Compression] = None,
21+
):
22+
self._aws_region = None
23+
24+
if endpoint:
25+
self._aws_region = endpoint.split(".")[1]
26+
27+
OTLPSpanExporter.__init__(
28+
self,
29+
endpoint,
30+
certificate_file,
31+
client_key_file,
32+
client_certificate_file,
33+
headers,
34+
timeout,
35+
compression,
36+
session=AwsAuthSession(aws_region=self._aws_region, service="xray"),
37+
)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
from amazon.opentelemetry.distro.aws_opentelemetry_distro import AwsOpenTelemetryDistro
3636
from amazon.opentelemetry.distro.aws_span_metrics_processor import AwsSpanMetricsProcessor
3737
from amazon.opentelemetry.distro.exporter.otlp.aws.common.aws_auth_session import AwsAuthSession
38+
from amazon.opentelemetry.distro.exporter.otlp.aws.logs.otlp_aws_logs_exporter import OTLPAwsLogExporter
39+
from amazon.opentelemetry.distro.exporter.otlp.aws.traces.otlp_aws_span_exporter import OTLPAwsSpanExporter
3840
from amazon.opentelemetry.distro.otlp_udp_exporter import OTLPUdpSpanExporter
3941
from amazon.opentelemetry.distro.sampler._aws_xray_sampling_client import _AwsXRaySamplingClient
4042
from amazon.opentelemetry.distro.sampler.aws_xray_remote_sampler import _AwsXRayRemoteSampler
@@ -377,7 +379,7 @@ def test_customize_span_exporter_sigv4(self):
377379
config,
378380
_customize_span_exporter,
379381
OTLPSpanExporter(),
380-
OTLPSpanExporter,
382+
OTLPAwsSpanExporter,
381383
AwsAuthSession,
382384
Compression.NoCompression,
383385
)
@@ -480,7 +482,12 @@ def test_customize_logs_exporter_sigv4(self):
480482

481483
for config in good_configs:
482484
self.customize_exporter_test(
483-
config, _customize_logs_exporter, OTLPLogExporter(), OTLPLogExporter, AwsAuthSession, Compression.Gzip
485+
config,
486+
_customize_logs_exporter,
487+
OTLPLogExporter(),
488+
OTLPAwsLogExporter,
489+
AwsAuthSession,
490+
Compression.Gzip,
484491
)
485492

486493
for config in bad_configs:

0 commit comments

Comments
 (0)