Skip to content

Commit 33154c8

Browse files
committed
added README for sigv4 exporter and added a more graceful fall through for catching missing dependencies
1 parent 1b3f738 commit 33154c8

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ADOT X-Ray OTLP Trace Export Configuration
2+
3+
This guide explains how to automatically configure ADOT environment variables for exporting traces to [AWS X-Ray OTLP endpoint](https://docs.aws.amazon.com/xray/latest/devguide/xray-opentelemetry.html)
4+
5+
## Pre-requisites:
6+
1. Transaction Search must be enabled in order to send spans to the Xray OTLP endpoint. See [this doc](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Transaction-Search-getting-started.html) on how to enable Transaction Search.
7+
8+
2. Ensure the AWS credentials in your application environment has the `xray:PutTraceSegments` action allowed.
9+
10+
## Environment Variables
11+
12+
Set the following environment variables to **PROPERLY** configure trace export with SigV4 authentication:
13+
14+
```shell
15+
# Set X-Ray endpoint (replace AWS_REGION with your region)
16+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://xray.<AWS_REGION>.amazonaws.com/v1/traces
17+
18+
# Configure OTLP export protocol
19+
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
20+
21+
OTEL_METRICS_EXPORTER=none
22+
OTEL_LOGS_EXPORTER=none
23+
OTEL_PYTHON_DISTRO=aws_distro
24+
OTEL_PYTHON_CONFIGURATOR=aws_configurator
25+
OTEL_RESOURCE_ATTRIBUTES="service.name=<YOUR_SERVICE_NAME>"
26+
27+
# Disable application signals (they will be generated in CloudWatch backend)
28+
OTEL_AWS_APPLICATION_SIGNALS_ENABLED=false

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/otlp_aws_span_exporter.py renamed to aws-opentelemetry-distro/src/amazon/opentelemetry/distro/otlp-aws-span-exporter/otlp_aws_span_exporter.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535
):
3636

3737
self._aws_region = None
38+
self._has_dependencies = False
3839

3940
# Requires botocore to be installed to sign the headers. However,
4041
# some users might not need to use this exporter. In order not conflict
@@ -52,6 +53,7 @@ def __init__(
5253
# The only usecase for this class would be for ADOT Python Auto Instrumentation and that already validates
5354
# the endpoint to be an XRay OTLP endpoint.
5455
self._aws_region = endpoint.split(".")[1]
56+
self._has_dependencies = True
5557

5658
else:
5759
_logger.error(
@@ -74,23 +76,24 @@ def __init__(
7476
# the same except if the endpoint is an XRay OTLP endpoint, we will sign the request
7577
# with SigV4 in headers before sending it to the endpoint. Otherwise, we will skip signing.
7678
def _export(self, serialized_data: bytes):
77-
request = self.boto_aws_request.AWSRequest(
78-
method="POST",
79-
url=self._endpoint,
80-
data=serialized_data,
81-
headers={"Content-Type": "application/x-protobuf"},
82-
)
79+
if(self._has_dependencies):
80+
request = self.boto_aws_request.AWSRequest(
81+
method="POST",
82+
url=self._endpoint,
83+
data=serialized_data,
84+
headers={"Content-Type": "application/x-protobuf"},
85+
)
8386

84-
credentials = self.boto_session.get_credentials()
87+
credentials = self.boto_session.get_credentials()
8588

86-
if credentials is not None:
87-
signer = self.boto_auth.SigV4Auth(credentials, AWS_SERVICE, self._aws_region)
89+
if credentials is not None:
90+
signer = self.boto_auth.SigV4Auth(credentials, AWS_SERVICE, self._aws_region)
8891

89-
try:
90-
signer.add_auth(request)
91-
self._session.headers.update(dict(request.headers))
92+
try:
93+
signer.add_auth(request)
94+
self._session.headers.update(dict(request.headers))
9295

93-
except Exception as signing_error: # pylint: disable=broad-except
94-
_logger.error("Failed to sign request: %s", signing_error)
96+
except Exception as signing_error: # pylint: disable=broad-except
97+
_logger.error("Failed to sign request: %s", signing_error)
9598

9699
return super()._export(serialized_data)

0 commit comments

Comments
 (0)