Skip to content

Commit 87b6f01

Browse files
committed
add further refactoring
1 parent 9df5a67 commit 87b6f01

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ if (getNodeVersion() >= 16) {
2222
} else {
2323
diag.error('SigV4 signing requires at least Node major version 16');
2424
}
25+
// See: https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html
26+
const SIG_V4_HEADERS = ['x-amz-date', 'authorization', 'x-amz-content-sha256', 'x-amz-security-token'];
2527

2628
export class AwsAuthenticator {
2729
private region: string;
@@ -80,10 +82,9 @@ export class AwsAuthenticator {
8082
// Cleans up Sigv4 from headers to avoid accidentally copying them to the new headers
8183
private removeSigV4Headers(headers: Record<string, string>) {
8284
const newHeaders: Record<string, string> = {};
83-
const sigV4Headers = ['x-amz-date', 'authorization', 'x-amz-content-sha256', 'x-amz-security-token'];
8485

8586
for (const key in headers) {
86-
if (!sigV4Headers.includes(key.toLowerCase())) {
87+
if (!SIG_V4_HEADERS.includes(key.toLowerCase())) {
8788
newHeaders[key] = headers[key];
8889
}
8990
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ReadableLogRecord } from '@opentelemetry/sdk-logs';
88
import { AwsAuthenticator } from '../common/aws-authenticator';
99
import { ExportResult, ExportResultCode } from '@opentelemetry/core';
1010
import { PassthroughSerializer } from '../common/passthrough-serializer';
11+
import { diag } from '@opentelemetry/api';
1112

1213
/**
1314
* This exporter extends the functionality of the OTLPProtoLogExporter to allow spans to be exported
@@ -91,6 +92,8 @@ export class OTLPAwsLogExporter extends OTLPProtoLogExporter {
9192

9293
const newHeaders: () => Record<string, string> = () => signedRequest;
9394
this['_delegate']._transport._transport._parameters.headers = newHeaders;
95+
} else {
96+
diag.debug('Delegate headers is undefined - unable to authenticate request to CloudWatch Logs OTLP endpoint');
9497
}
9598

9699
super.export(items, resultCallback);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ExportResult, ExportResultCode } from '@opentelemetry/core';
88
import { AwsAuthenticator } from '../common/aws-authenticator';
99
import { PassthroughSerializer } from '../common/passthrough-serializer';
1010
import { gzipSync } from 'zlib';
11+
import { diag } from '@opentelemetry/api';
1112

1213
/**
1314
* This exporter extends the functionality of the OTLPProtoTraceExporter to allow spans to be exported
@@ -80,6 +81,8 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
8081
// See type: https://github.com/open-telemetry/opentelemetry-js/blob/experimental/v0.57.1/experimental/packages/otlp-exporter-base/src/transport/http-transport-types.ts#L31
8182
const newHeaders: () => Record<string, string> = () => signedRequest;
8283
this['_delegate']._transport._transport._parameters.headers = newHeaders;
84+
} else {
85+
diag.debug('Delegate headers is undefined - unable to authenticate request to XRay OTLP endpoint');
8386
}
8487

8588
super.export(items, resultCallback);

0 commit comments

Comments
 (0)