diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/package.json b/aws-distro-opentelemetry-node-autoinstrumentation/package.json index 34fd5883..b2c81488 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/package.json +++ b/aws-distro-opentelemetry-node-autoinstrumentation/package.json @@ -43,7 +43,7 @@ ], "exclude": [ "src/third-party/**/*.ts", - "src/otlp-aws-span-exporter.ts" + "src/aws-span-exporter/otlp-aws-span-exporter.ts" ] }, "bugs": { diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts index cd261e87..34ee673f 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts @@ -56,7 +56,7 @@ import { AttributePropagatingSpanProcessorBuilder } from './attribute-propagatin import { AwsBatchUnsampledSpanProcessor } from './aws-batch-unsampled-span-processor'; import { AwsMetricAttributesSpanExporterBuilder } from './aws-metric-attributes-span-exporter-builder'; import { AwsSpanMetricsProcessorBuilder } from './aws-span-metrics-processor-builder'; -import { OTLPAwsSpanExporter } from './otlp-aws-span-exporter'; +import { OTLPAwsSpanExporter } from './aws-span-exporter/otlp-aws-span-exporter'; import { OTLPUdpSpanExporter } from './otlp-udp-exporter'; import { AwsXRayRemoteSampler } from './sampler/aws-xray-remote-sampler'; // This file is generated via `npm run compile` diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md new file mode 100644 index 00000000..53eead2e --- /dev/null +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md @@ -0,0 +1,28 @@ +# ADOT X-Ray OTLP Trace Export Configuration + +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) + +## Pre-requisites + +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. + +2. Ensure the AWS role in your application environment has [AWSXRayWriteOnlyAccess](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AWSXrayWriteOnlyAccess.html) managed policy attached. + +## Environment Variables + +Set the following environment variables to **PROPERLY** configure trace export with SigV4 authentication: + +```shell +# Set X-Ray endpoint (replace AWS_REGION with your region) +OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://xray..amazonaws.com/v1/traces + +# Configure OTLP export protocol +OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf + +OTEL_TRACES_EXPORTER=otlp +OTEL_METRICS_EXPORTER=none +OTEL_LOGS_EXPORTER=none +OTEL_RESOURCE_ATTRIBUTES="service.name=" + +# Disable application signals (they will be generated in CloudWatch backend) +OTEL_AWS_APPLICATION_SIGNALS_ENABLED=false diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/otlp-aws-span-exporter.ts similarity index 99% rename from aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts rename to aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/otlp-aws-span-exporter.ts index 406d0bea..79828abd 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/otlp-aws-span-exporter.ts @@ -6,7 +6,7 @@ import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import { ProtobufTraceSerializer } from '@opentelemetry/otlp-transformer'; import { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { ExportResult } from '@opentelemetry/core'; -import { getNodeVersion } from './utils'; +import { getNodeVersion } from '../utils'; /** * This exporter extends the functionality of the OTLPProtoTraceExporter to allow spans to be exported diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/test/otlp-aws-span-exporter.test.ts b/aws-distro-opentelemetry-node-autoinstrumentation/test/otlp-aws-span-exporter.test.ts index 4002293c..5c95eee4 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/test/otlp-aws-span-exporter.test.ts +++ b/aws-distro-opentelemetry-node-autoinstrumentation/test/otlp-aws-span-exporter.test.ts @@ -1,8 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import expect from 'expect'; -import { OTLPAwsSpanExporter } from '../src/otlp-aws-span-exporter'; import * as sinon from 'sinon'; +import { OTLPAwsSpanExporter } from '../src/aws-span-exporter/otlp-aws-span-exporter'; import * as proxyquire from 'proxyquire'; import * as nock from 'nock'; import { getNodeVersion } from '../src/utils'; @@ -36,7 +36,7 @@ if (nodeVersion >= 16) { return [200, '']; }); - mockModule = proxyquire('../src/otlp-aws-span-exporter', { + mockModule = proxyquire('../src/aws-span-exporter/otlp-aws-span-exporter', { '@smithy/signature-v4': { SignatureV4: class MockSignatureV4 { sign(req: any) { @@ -127,7 +127,7 @@ if (nodeVersion >= 16) { }); it('should not inject SigV4 headers if failure to sign headers', done => { - const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', { + const stubbedModule = proxyquire('../src/aws-span-exporter/otlp-aws-span-exporter', { '@smithy/signature-v4': { SignatureV4: class MockSignatureV4 { sign() { @@ -156,7 +156,7 @@ if (nodeVersion >= 16) { }); it('should not inject SigV4 headers if failure to retrieve credentials', done => { - const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', { + const stubbedModule = proxyquire('../src/aws-span-exporter/otlp-aws-span-exporter', { '@aws-sdk/credential-provider-node': { defaultProvider: () => async () => { throw new Error('credentials error');