AWS Distro for OpenTelemetry
Getting Started with the AWS X-Ray Exporter in the Collector
Getting Started with the AWS X-Ray Exporter in the Collector
The OpenTelemetry Collector has three key components: the receiver, exporter, and processor. The receiver in the OpenTelemetry Collector is responsible for receiving data via gRPC or HTTP using the OpenTelemetry protocol (OTLP). The AWS X-Ray exporter available in the OpenTelemetry Collector converts OTLP formatted trace data to the AWS X-Ray format and then exports this data to the AWS X-Ray service.
In this guide, we will demonstrate how to configure the AWS Distro for the OpenTelemetry (ADOT) Collector for use with AWS X-Ray. To learn more about AWS X-Ray, see the X-Ray Developer Guide.
Prerequisites
To get started using the ADOT Collector to connect with AWS X-Ray to analyze distributed traces, you have to first install AWS Distro for the OpenTelemetry Collector. Make sure you have your access key ID and secret access key properly configured in the docker file. You can generate access key ID and secret access key with the information here.
In order to set up the ADOT Collector on a particular platform such as EKS, ECS, EC2 or on-premises, please see the Getting Started guide for
ADOT also includes fully managed AWS Lambda Layers, which include an OpenTelemetry SDK and the ADOT Collector to auto-instrument your function for tracing with X-Ray. See AWS Distro for OpenTelemetry Lambda to get started.
Configuring the OTLP Receiver
To enable the OTLP receiver, we include the “otlp” flag in the definitions. You will have to set the “endpoint” consisting of <host>:<port>
for
the gRPC or HTTP protocols. You can change the endpoints depending on how you set up your instrumentation with OpenTelemetry.
Example:
1receivers:2 otlp:3 protocols:4 grpc:5 endpoint: 0.0.0.0:43176 http:7 endpoint: 0.0.0.0:4318
Note: A protocol can be disabled by not specifying it in the list of protocols.
Configuring the AWS X-Ray Exporter
By default, the AWS Distribution for the OpenTelemetry Collector has enabled exporting to AWS X-Ray without any additional configurations - converting the AWS X-Ray OTLP formatted trace data to the AWS X-Ray format and then exports this data to the AWS X-Ray service. For additional configuration options of the AWS X-Ray exporter in the Collector, you can find the comprehensive list here.
Example:
1exporters:2 awsxray:3 # you can add additional configuration here4 # for example configure sending traces to AWS X-Ray in a specific region5 region: us-west-2
Note: These configurations are optional
OTel to X-Ray data model translation behavior of AWS X-Ray Exporter
OTel span attributes translation
OTel data model field/Attribute keys | X-Ray data model field | Notes |
---|---|---|
Attributes | annotations/metadata |
|
SpanId | id |
|
TraceId | trace_id |
|
StartTime | start_time | |
EndTime | end_time | |
ParentSpanId | parent_id | |
Status.StatusCode | fault |
|
Status.StatusCode | error |
|
Status.StatusCode | throttle |
|
Event | exception |
|
Link | N/A |
|
enduser.id | user |
|
cloud.provider and cloud.platform | origin |
|
rpc.system and aws.service | namespace |
|
peer.service, aws.service, db.service, service.name, span.kind, and span name | name |
|
pdata.SpanKindServer | type |
|
OTel span HTTP attributes translation
OTel Attributes keys | X-Ray data model field | Notes |
---|---|---|
http.method, http.request.method | http.request.method | |
http.client_ip | http.request.client_ip | |
http.client_ip | http.request.x_forwarded_for | |
http.user_agent, user_agent.original | http.request.user_agent | |
http.status_code, http.response.status | http.response.status | |
http.url, http.scheme, http.host, http.target, http.server_name, net.host.port, host.name, net.host.name, net.peer.name, net.peer.port, net.peer.ip, server.address, client.address | http.request.url |
|
message.type | http.response.content_length |
|
OTel span SQL attributes translation
OTel Attributes env var value | X-Ray data model field | Notes |
---|---|---|
db.connection_string, db.name | sql.url |
|
db.system | sql.database_type | |
db.user | sql.user | |
db.statement | sql.sanatized_query |
OTel span AWS attributes translation
OTel Attributes env var value | X-Ray data model field | Notes |
---|---|---|
cloud.account.id | aws.account_id | |
aws.operation, rpc.method | aws.operation |
|
aws.region | aws.region | |
aws.requestId | aws.request_id | |
aws.queue.url | aws.queue_url | |
aws.table.name | aws.table_name |
OTel span metadata translation
OTel Attributes env var value | X-Ray data model field | Notes |
---|---|---|
telemetry.sdk.name | xray.sdk | |
telemetry.sdk.version | xray.sdk_version | |
telemetry.auto.version | xray.auto_instrumentation |
OTel span EC2 metadata translation
OTel Attributes env var value | X-Ray data model field | Notes |
---|---|---|
host.id | ec2.instance_id | |
cloud.availability_zone | ec2.availability_zone | |
host.type | ec2.instance_size | |
host.image.id | ec2.ami_id |
OTel span ECS metadata translation
OTel Attributes env var value | X-Ray data model field | Notes |
---|---|---|
container.name | ecs.container | |
container.id | ecs.container_id | |
cloud.availability_zone | ecs.availability_zone | |
aws.ecs.container.arn | ecs.container_arn | |
aws.ecs.cluster.arn | ecs.cluster_arn | |
aws.ecs.task.arn | ecs.task_arn | |
aws.ecs.task.family | ecs.task_family | |
aws.ecs.launchtype | ecs.launch_type |
OTel span EKS metadata translation
OTel Attributes env var | X-Ray data model field | Notes |
---|---|---|
k8s.cluster.name | eks.cluster_name | |
k8s.pod.name | eks.pod | |
k8s.pod.uid | eks.container_id |
OTel span EB metadata translation
OTel Attributes env var | X-Ray data model field | Notes |
---|---|---|
service.namespace | elastic_beanstalk.environment_name | |
service.instance.id | elastic_beanstalk.deployment_id |
|
service.version | elastic_beanstalk.version_label |
OTel span CW Logs metadata translation
The attributes in this section are translated into the AWS resource field cloudwatch_logs
. This resource field is used to correlate Cloudwatch Log Groups with the segments associated with it. This correlation can be explored when analyzing individual traces in the X-Ray console.
If an attribute is not specified, then the exporter's aws_log_groups field will be used if available.
OTel Attributes env var | X-Ray data model field | Notes |
---|---|---|
aws.log.group.arns | cloudwatch_logs.arn | |
aws.log.group.names | cloudwatch_logs.log_group | Precedence is given in the order of aws.log.group.arns , aws.log.group.names , then the exporter config's aws_log_groups . |
Using Config to set Cloud Watch Log Group Names
1awsxray:2 aws_log_groups: ["group1", "group2"]
With the ADOT Collector v0.26.0 and newer, it is also possible to set the resource attributes aws.log.group.names
and aws.log.group.arns
using the environment variable OTEL_RESOURCE_ATTRIBUTES
. This is useful for the case you are using auto-instrumentation in your application. The following is an example of value that you could use in that environment variable.
OTEL_RESOURCE_ATTRIBUTES=aws.log.group.names=group1
See AWS X-Ray Segment Documents for more information on the AWS X-Ray data model. See OpenTelemetry data model spec for more information on OpenTelemetry data model. See X-Ray Logging Configuration for references of expected log pattern. See AWS X-Ray Tracing Exporter for more information on the exporter's config.
Enable The Customized X-Ray Annotations
By using OpenTelemetry SDK, we can add the customized attributes for each trace subsegment. By default, these OpenTelemetry
attributes will be converted into metadata
attributes in X-Ray raw data. If we need to convert some or all OpenTelemetry attributes
into X-Ray annotation
, we can follow the steps below for enabling annotation conversion.
Enabling X-Ray annotations via the otel collector xray exporter config
Step 1: create an attribute by using OpenTelemetry SDK
For example:
setAttribute(“TransactionId”, <value>)setAttribute(“AccountId”, <value>)
Note: More detailed instructions for adding attributes can be found in individual languages' guides
Step 2: In the collector, set the config in one of two ways
For specific attributes to be indexed:
1awsxray:2 indexed_attributes: ["TransactionId", "AccountId"]
For all attributes to be indexed:
1awsxray:2 index_all_attributes: true
Enabling X-Ray annotations via an otel sdk span attribute
We can direct X-ray to annotate customized attributes of a span via otel span attributes.
Step 1: create an attribute by using OpenTelemetry SDK
For example:
setAttribute(“TransactionId”, <value>)setAttribute(“AccountId”, <value>)
Note: More detailed instructions for adding attributes can be found in individual languages' guides
Step 2: direct xray to annotate these attributes
For example:
setAttribute("aws.xray.annotations", List.of(“TransactionId”, “AccountId”))
*Note: More detailed instructions can be found here: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/exporter/awsxrayexporter
Configuring the OpenTelemetry Collector for X-Ray remote Sampling
AWS X-Ray remote sampling is supported
with OpenTelemetry by configuring the OpenTelemetry Collector to proxy sampling requests to AWS X-Ray using the
awsproxy
extension. Check out Configuring the OpenTelemetry Collector for X-Ray remote Sampling for more details.
Sample Collector Configuration (Putting it Together)
This is a sample configuration without additional configurations in the exporter:
1receivers:2 otlp:3 protocols:4 grpc:5 endpoint: 0.0.0.0:43176 http:7 endpoint: 0.0.0.0:43188
9exporters:10 awsxray:11
12processors:13 memory_limiter:14 limit_mib: 10015 check_interval: 5s16
17service:18 pipelines:19 traces:20 processors:21 - memory_limiter22 receivers:23 - otlp24 exporters:25 - awsxray
Using the ADOT SDKs
AWS Distro for OpenTelemetry currently supports applications written in Go, Java, JavaScript, .NET, and Python. Check out the Getting Started guides for the respective languages.
If the OpenTelemetry Collector is configured correctly and an application is instrumented to generate traces, we should be able see the traces on the AWS X-Ray console.
Questions, Issues, Missing Documentation
If you have questions or issues with this guide, you can submit an issue on the AWS Observability community page to let us know. This website is also open source, so you can submit a pull request directly to update this guide on GitHub.