Skip to content

Commit fa269d0

Browse files
authored
Remove old SigV4 headers before signing (#159)
*Description of changes:* There was a bug where the old headers were not cleaned before the request was signed causing 403 errors to occur when exporting traces to XRay OTLP endpoint. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 91971e3 commit fa269d0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-opentelemetry-configurator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ export class AwsSpanProcessorProvider {
448448
return new OTLPHttpTraceExporter();
449449
case 'http/protobuf':
450450
if (otlp_exporter_traces_endpoint && isXrayOtlpEndpoint(otlp_exporter_traces_endpoint)) {
451+
diag.debug('Detected XRay OTLP Traces endpoint. Switching exporter to OtlpAwsSpanExporter');
451452
return new OTLPAwsSpanExporter(otlp_exporter_traces_endpoint);
452453
}
453454
return new OTLPProtoTraceExporter();
@@ -457,6 +458,7 @@ export class AwsSpanProcessorProvider {
457458
default:
458459
diag.warn(`Unsupported OTLP traces protocol: ${protocol}. Using http/protobuf.`);
459460
if (otlp_exporter_traces_endpoint && isXrayOtlpEndpoint(otlp_exporter_traces_endpoint)) {
461+
diag.debug('Detected XRay OTLP Traces endpoint. Switching exporter to OtlpAwsSpanExporter');
460462
return new OTLPAwsSpanExporter(otlp_exporter_traces_endpoint);
461463
}
462464
return new OTLPProtoTraceExporter();

aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
6666
path: url.pathname,
6767
body: serializedSpans,
6868
headers: {
69-
...oldHeaders,
69+
...this.removeSigV4Headers(oldHeaders),
7070
host: url.hostname,
7171
},
7272
});
@@ -93,6 +93,19 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
9393
await super.export(items, resultCallback);
9494
}
9595

96+
// Removes Sigv4 headers from old headers to avoid accidentally copying them to the new headers
97+
private removeSigV4Headers(headers: Record<string, string>) {
98+
const newHeaders: Record<string, string> = {};
99+
const sigV4Headers = ['x-amz-date', 'authorization', 'x-amz-content-sha256', 'x-amz-security-token'];
100+
101+
for (const key in headers) {
102+
if (!sigV4Headers.includes(key.toLowerCase())) {
103+
newHeaders[key] = headers[key];
104+
}
105+
}
106+
return newHeaders;
107+
}
108+
96109
private initDependencies(): any {
97110
if (getNodeVersion() < 16) {
98111
diag.error('SigV4 signing requires atleast Node major version 16');

0 commit comments

Comments
 (0)