Skip to content

Commit

Permalink
Don't end spans twice
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski committed Jun 28, 2024
1 parent 8bdf2ed commit 68f7d95
Showing 1 changed file with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,27 +436,31 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
lambdaResponse: any,
errorFromLambda: string | Error | null | undefined,
) {
if (errorFromLambda) {
span.recordException(errorFromLambda);
if (span.isRecording()) {
if (errorFromLambda) {
span.recordException(errorFromLambda);

span.setStatus({
code: SpanStatusCode.ERROR,
message: this._errorToString(errorFromLambda),
});
span.setStatus({
code: SpanStatusCode.ERROR,
message: this._errorToString(errorFromLambda),
});

span.end();
return;
}
span.end();
return;
}

if (
this.triggerOrigin !== undefined &&
[TriggerOrigin.API_GATEWAY_REST, TriggerOrigin.API_GATEWAY_HTTP].includes(
this.triggerOrigin
)
) {
finalizeSpan(config, this.triggerOrigin, span, lambdaResponse);
if (
this.triggerOrigin !== undefined &&
[TriggerOrigin.API_GATEWAY_REST, TriggerOrigin.API_GATEWAY_HTTP].includes(
this.triggerOrigin
)
) {
finalizeSpan(config, this.triggerOrigin, span, lambdaResponse);
}
span.end();
} else {
diag.debug('Ending wrapper span for the second time');
}
span.end();
}

private _wrapCallback(
Expand Down Expand Up @@ -508,18 +512,22 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
}

private _endSpan(span: Span, err: string | Error | null | undefined) {
if (err) {
span.recordException(err);
}
if (span.isRecording()) {
if (err) {
span.recordException(err);
}

const errMessage = this._errorToString(err);
if (errMessage) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: errMessage,
});
const errMessage = this._errorToString(err);
if (errMessage) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: errMessage,
});
}
span.end();
} else {
diag.debug('Ending span for the second time');
}
span.end();
}

private _errorToString(err: string | Error | null | undefined) {
Expand Down

0 comments on commit 68f7d95

Please sign in to comment.