Skip to content

Commit 2564edd

Browse files
committed
add export failed return to aws span exporter
1 parent 54f3229 commit 2564edd

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,15 @@ export abstract class OTLPAwsBaseExporter<Payload, Response> extends OTLPExporte
8787
this.serializer.setSerializedData(serializedData);
8888
const signedHeaders = await this.authenticator.authenticate(headers, serializedData);
8989

90-
if (signedHeaders) {
91-
this.parentExporter['_delegate']._transport._transport._parameters.headers = () => signedHeaders;
90+
if (!signedHeaders) {
91+
resultCallback({
92+
code: ExportResultCode.FAILED,
93+
error: new Error('Sigv4 Signing Failed. Not exporting'),
94+
});
95+
return;
9296
}
9397

98+
this.parentExporter['_delegate']._transport._transport._parameters.headers = () => signedHeaders;
9499
this.parentExporter.export(items, resultCallback);
95100
}
96101

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class OTLPAwsSpanExporter
6565
return !!this.lloHandler;
6666
}
6767

68-
public override async export(items: ReadableSpan[], resultCallback: (result: ExportResult) => void): Promise<void> {
68+
override async export(items: ReadableSpan[], resultCallback: (result: ExportResult) => void): Promise<void> {
6969
let itemsToSerialize: ReadableSpan[] = items;
7070
if (isAgentObservabilityEnabled() && this.ensureLloHandler() && this.lloHandler) {
7171
// items to serialize are now the lloProcessedSpans

aws-distro-opentelemetry-node-autoinstrumentation/test/exporter/otlp/aws/common/otlp-aws-base-exporter.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export abstract class OTLPAwsBaseExporterTest {
8080
description: 'Should fail when headers are undefined',
8181
test: (done: () => void) => this.testUndefinedHeaders(done),
8282
},
83+
{
84+
description: 'Should continue when authenticate returns undefined',
85+
test: (done: () => void) => this.testSigningFails(done),
86+
},
8387
];
8488
}
8589

@@ -154,6 +158,22 @@ export abstract class OTLPAwsBaseExporterTest {
154158
});
155159
}
156160

161+
private testSigningFails(done: () => void) {
162+
this.sandbox.restore();
163+
this.sandbox = sinon.createSandbox();
164+
165+
this.sandbox.stub(AwsAuthenticator.prototype, 'authenticate').resolves(undefined);
166+
167+
const exporterClass = this.getExporter();
168+
const exporter = new exporterClass(this.getEndpoint() + this.getEndpointPath());
169+
170+
exporter.export([], (result: ExportResult) => {
171+
expect(result.code).toBe(ExportResultCode.FAILED);
172+
expect(this.scope.isDone()).toBe(true);
173+
done();
174+
});
175+
}
176+
157177
private testEmptySerialize(done: () => void) {
158178
const exporterClass = this.getExporter();
159179
const exporter = new exporterClass(this.getEndpoint() + this.getEndpointPath());

0 commit comments

Comments
 (0)