Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Lambda Metric ForceFlush error msg #110

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
InstrumentationNodeModuleFile,
isWrapped,
} from '@opentelemetry/instrumentation';
import { diag } from '@opentelemetry/api';
import { diag, Span, SpanStatusCode } from '@opentelemetry/api';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
export class AwsLambdaInstrumentationPatch extends AwsLambdaInstrumentation {
override init() {
// Custom logic before calling the original implementation
Expand Down Expand Up @@ -117,4 +119,38 @@ export class AwsLambdaInstrumentationPatch extends AwsLambdaInstrumentation {
];
}
}

// Override the upstream private _endSpan method to remove the unnecessary metric force-flush error message
// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts#L358-L398
override _endSpan(span: Span, err: string | Error | null | undefined, callback: () => void) {
if (err) {
span.recordException(err);
}

let errMessage;
if (typeof err === 'string') {
errMessage = err;
} else if (err) {
errMessage = err.message;
}
if (errMessage) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: errMessage,
});
}

span.end();

const flushers = [];
if ((this as any)._traceForceFlusher) {
flushers.push((this as any)._traceForceFlusher());
} else {
diag.error(
'Spans may not be exported for the lambda function because we are not force flushing before callback.'
);
}

Promise.all(flushers).then(callback, callback);
}
}
Loading