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 15180552..65266de0 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts @@ -448,6 +448,7 @@ export class AwsSpanProcessorProvider { return new OTLPHttpTraceExporter(); case 'http/protobuf': if (otlp_exporter_traces_endpoint && isXrayOtlpEndpoint(otlp_exporter_traces_endpoint)) { + diag.debug('Detected XRay OTLP Traces endpoint. Switching exporter to OtlpAwsSpanExporter'); return new OTLPAwsSpanExporter(otlp_exporter_traces_endpoint); } return new OTLPProtoTraceExporter(); @@ -457,6 +458,7 @@ export class AwsSpanProcessorProvider { default: diag.warn(`Unsupported OTLP traces protocol: ${protocol}. Using http/protobuf.`); if (otlp_exporter_traces_endpoint && isXrayOtlpEndpoint(otlp_exporter_traces_endpoint)) { + diag.debug('Detected XRay OTLP Traces endpoint. Switching exporter to OtlpAwsSpanExporter'); return new OTLPAwsSpanExporter(otlp_exporter_traces_endpoint); } return new OTLPProtoTraceExporter(); diff --git a/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts b/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts index e3b5d591..25303ece 100644 --- a/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts +++ b/aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts @@ -66,7 +66,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter { path: url.pathname, body: serializedSpans, headers: { - ...oldHeaders, + ...this.removeSigV4Headers(oldHeaders), host: url.hostname, }, }); @@ -93,6 +93,19 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter { await super.export(items, resultCallback); } + // Removes Sigv4 headers from old headers to avoid accidentally copying them to the new headers + private removeSigV4Headers(headers: Record) { + const newHeaders: Record = {}; + const sigV4Headers = ['x-amz-date', 'authorization', 'x-amz-content-sha256', 'x-amz-security-token']; + + for (const key in headers) { + if (!sigV4Headers.includes(key.toLowerCase())) { + newHeaders[key] = headers[key]; + } + } + return newHeaders; + } + private initDependencies(): any { if (getNodeVersion() < 16) { diag.error('SigV4 signing requires atleast Node major version 16');