Skip to content

Commit 554535a

Browse files
committed
reintroduce aws otlp logs and spans exporter
1 parent cb3a1b0 commit 554535a

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 "
Lines changed: 36 additions & 0 deletions
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+
)
Lines changed: 37 additions & 0 deletions
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)