From f117bfafb8f623bbe9bc87411a059683d93cd8e6 Mon Sep 17 00:00:00 2001 From: liustve Date: Wed, 26 Mar 2025 23:21:12 +0000 Subject: [PATCH 1/6] add readme.md for sigv4 exporter --- .../src/aws-opentelemetry-configurator.ts | 2 +- .../src/exporter/README.md | 27 +++++++++++++++++++ .../{ => exporter}/otlp-aws-span-exporter.ts | 2 +- .../test/otlp-aws-span-exporter.test.ts | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/README.md rename aws-distro-opentelemetry-node-autoinstrumentation/src/{ => exporter}/otlp-aws-span-exporter.ts (99%) 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 cd261e8..68605ce 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 './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/exporter/README.md b/aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/README.md new file mode 100644 index 0000000..fc80719 --- /dev/null +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/README.md @@ -0,0 +1,27 @@ +# 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 \ No newline at end of file diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts b/aws-distro-opentelemetry-node-autoinstrumentation/src/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/exporter/otlp-aws-span-exporter.ts index 406d0be..79828ab 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/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 4002293..aa1ecb9 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,7 +1,7 @@ // 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 { OTLPAwsSpanExporter } from '../src/exporter/otlp-aws-span-exporter'; import * as sinon from 'sinon'; import * as proxyquire from 'proxyquire'; import * as nock from 'nock'; From 5a12d6f881a4754e4765a7de4571b5e3e89774b8 Mon Sep 17 00:00:00 2001 From: liustve Date: Thu, 27 Mar 2025 18:49:09 +0000 Subject: [PATCH 2/6] fix import error --- .../test/otlp-aws-span-exporter.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 aa1ecb9..66703dd 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/exporter/otlp-aws-span-exporter'; import * as sinon from 'sinon'; +import { OTLPAwsSpanExporter } from '../src/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/exporter/otlp-aws-span-exporter', { '@smithy/signature-v4': { SignatureV4: class MockSignatureV4 { sign(req: any) { From 0779fc352b900d90339b79404c71e8c1c2873bce Mon Sep 17 00:00:00 2001 From: liustve Date: Tue, 1 Apr 2025 00:22:06 +0000 Subject: [PATCH 3/6] fixed import errors, renamed sigv4 exporter folder --- .../src/aws-opentelemetry-configurator.ts | 2 +- .../src/{exporter => aws-span-exporter}/README.md | 0 .../otlp-aws-span-exporter.ts | 0 .../test/otlp-aws-span-exporter.test.ts | 8 ++++---- 4 files changed, 5 insertions(+), 5 deletions(-) rename aws-distro-opentelemetry-node-autoinstrumentation/src/{exporter => aws-span-exporter}/README.md (100%) rename aws-distro-opentelemetry-node-autoinstrumentation/src/{exporter => aws-span-exporter}/otlp-aws-span-exporter.ts (100%) 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 68605ce..34ee673 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 './exporter/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/exporter/README.md b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md similarity index 100% rename from aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/README.md rename to aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/otlp-aws-span-exporter.ts b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/otlp-aws-span-exporter.ts similarity index 100% rename from aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/otlp-aws-span-exporter.ts rename to aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/otlp-aws-span-exporter.ts 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 66703dd..5c95eee 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 @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import expect from 'expect'; import * as sinon from 'sinon'; -import { OTLPAwsSpanExporter } from '../src/exporter/otlp-aws-span-exporter'; +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/exporter/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'); From b3ecaaa1d0b6f6f789a2df348c8a935e623074f9 Mon Sep 17 00:00:00 2001 From: liustve Date: Tue, 1 Apr 2025 00:26:04 +0000 Subject: [PATCH 4/6] readme linting fix --- .../src/aws-span-exporter/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index fc80719..82f5495 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md @@ -3,6 +3,7 @@ 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. @@ -24,4 +25,4 @@ 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 \ No newline at end of file +OTEL_AWS_APPLICATION_SIGNALS_ENABLED=false From 8ea4b1ffe5b79ded1f7ce0da071e76491b0c419e Mon Sep 17 00:00:00 2001 From: liustve Date: Tue, 1 Apr 2025 00:29:26 +0000 Subject: [PATCH 5/6] update otlp-aws-span-exporter for unit tests --- aws-distro-opentelemetry-node-autoinstrumentation/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/package.json b/aws-distro-opentelemetry-node-autoinstrumentation/package.json index 34fd588..b2c8148 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": { From 21e161c3e621ce0a859bb90328e667122d090534 Mon Sep 17 00:00:00 2001 From: liustve Date: Tue, 1 Apr 2025 00:32:37 +0000 Subject: [PATCH 6/6] linting fix --- .../src/aws-span-exporter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 82f5495..53eead2 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-exporter/README.md @@ -2,7 +2,7 @@ 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: +## 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.