Skip to content

Commit 694980a

Browse files
committed
add better debug messages
1 parent 93807d7 commit 694980a

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ export class AwsAuthenticator {
7070

7171
return signedRequest.headers;
7272
} catch (exception) {
73-
diag.debug(
74-
`Failed to sign/authenticate the given exported Span request to OTLP XRay endpoint with error: ${exception}`
75-
);
73+
diag.debug(`Failed to sign/authenticate the given export request with error: ${exception}`);
7674
}
7775
}
7876

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { diag } from '@opentelemetry/api';
1818
*
1919
* This only works with version >=16 Node.js environments.
2020
*/
21-
2221
export class OTLPAwsLogExporter extends OTLPProtoLogExporter {
2322
private compression: CompressionAlgorithm | undefined;
2423
private endpoint: string;
@@ -30,7 +29,7 @@ export class OTLPAwsLogExporter extends OTLPProtoLogExporter {
3029
const modifiedConfig: OTLPExporterNodeConfigBase = {
3130
...config,
3231
url: endpoint,
33-
compression: CompressionAlgorithm.NONE,
32+
compression: CompressionAlgorithm.NONE, // Setting Compression to NONE as compression will be handled here.
3433
};
3534

3635
super(modifiedConfig);
@@ -51,10 +50,6 @@ export class OTLPAwsLogExporter extends OTLPProtoLogExporter {
5150
* To prevent performance degradation from serializing and compressing data twice, we handle serialization and compression
5251
* locally in this exporter and pass the pre-processed data to the upstream export functionality.
5352
*/
54-
55-
// Upstream already implements a retry mechanism:
56-
// https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/otlp-exporter-base/src/retrying-transport.ts
57-
5853
public override async export(
5954
items: ReadableLogRecord[],
6055
resultCallback: (result: ExportResult) => void
@@ -70,6 +65,7 @@ export class OTLPAwsLogExporter extends OTLPProtoLogExporter {
7065
}
7166

7267
const shouldCompress = this.compression && this.compression !== CompressionAlgorithm.NONE;
68+
7369
if (shouldCompress) {
7470
serializedLogs = gzipSync(serializedLogs);
7571
}
@@ -88,10 +84,11 @@ export class OTLPAwsLogExporter extends OTLPProtoLogExporter {
8884
delete headers['Content-Encoding'];
8985
}
9086

91-
const signedRequest = await this.authenticator.authenticate(this.endpoint, headers, serializedLogs);
87+
const signedRequestHeaders = await this.authenticator.authenticate(this.endpoint, headers, serializedLogs);
9288

93-
const newHeaders: () => Record<string, string> = () => signedRequest;
94-
this['_delegate']._transport._transport._parameters.headers = newHeaders;
89+
if ('authorization' in signedRequestHeaders) {
90+
this['_delegate']._transport._transport._parameters.headers = () => signedRequestHeaders;
91+
}
9592
} else {
9693
diag.debug('Delegate headers is undefined - unable to authenticate request to CloudWatch Logs OTLP endpoint');
9794
}

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
2929
const modifiedConfig: OTLPExporterNodeConfigBase = {
3030
...config,
3131
url: endpoint,
32-
compression: CompressionAlgorithm.NONE,
32+
compression: CompressionAlgorithm.NONE, // Setting Compression to NONE as compression will be handled here.
3333
};
3434

3535
super(modifiedConfig);
3636
this.region = endpoint.split('.')[1];
3737
this.endpoint = endpoint;
3838
this.authenticator = new AwsAuthenticator(this.region, 'xray');
39+
40+
// This is used in order to prevent serializing and compressing the data twice. Once for signing Sigv4 and
41+
// once when we pass the data to super.export() which will serialize and compress the data again.
3942
this.serializer = new PassthroughSerializer(ProtobufTraceSerializer.deserializeResponse);
4043
this['_delegate']._serializer = this.serializer;
4144
}
4245

4346
/**
44-
* Overrides the upstream implementation of export. All behaviors are the same except if the
45-
* endpoint is an XRay OTLP endpoint, we will sign the request with SigV4 in headers before
46-
* sending it to the endpoint. Otherwise, we will skip signing.
47+
* Overrides the upstream implementation of export.
48+
* All behaviors are the same except if the endpoint is an XRay OTLP endpoint, we will sign the request with SigV4
49+
* in headers before sending it to the endpoint.
4750
* To prevent performance degradation from serializing and compressing data twice, we handle serialization and compression
4851
* locally in this exporter and pass the pre-processed data to the upstream export functionality.
4952
*/
@@ -58,15 +61,17 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
5861
return;
5962
}
6063

61-
// Pass pre-processed data to passthrough serializer. When super.export() is called, the Passthrough Serializer will
62-
// use the pre-processed data instead of serializing and compressing the data again.
6364
const shouldCompress = this.compression && this.compression !== CompressionAlgorithm.NONE;
65+
6466
if (shouldCompress) {
6567
serializedSpans = gzipSync(serializedSpans);
6668
}
6769

70+
// Pass pre-processed data to passthrough serializer. When super.export() is called, the Passthrough Serializer will
71+
// use the pre-processed data instead of serializing and compressing the data again.
6872
this.serializer.setSerializedData(serializedSpans);
6973

74+
// 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
7075
const headers = this['_delegate']._transport?._transport?._parameters?.headers();
7176

7277
if (headers) {
@@ -76,11 +81,11 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
7681
delete headers['Content-Encoding'];
7782
}
7883

79-
const signedRequest = await this.authenticator.authenticate(this.endpoint, headers, serializedSpans);
84+
const signedRequestHeaders = await this.authenticator.authenticate(this.endpoint, headers, serializedSpans);
8085

81-
// 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
82-
const newHeaders: () => Record<string, string> = () => signedRequest;
83-
this['_delegate']._transport._transport._parameters.headers = newHeaders;
86+
if ('authorization' in signedRequestHeaders) {
87+
this['_delegate']._transport._transport._parameters.headers = () => signedRequestHeaders;
88+
}
8489
} else {
8590
diag.debug('Delegate headers is undefined - unable to authenticate request to XRay OTLP endpoint');
8691
}

0 commit comments

Comments
 (0)