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

Avoid flushing metrics when sending early spans #17

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 @@ -309,7 +309,7 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
earlyTrigger.end();
}

await this._flush();
await this._flush_trace();
}

private _createEarlySpan(
Expand Down Expand Up @@ -420,28 +420,35 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
}

private async _flush() {
const flushers = [];
try {
await Promise.all([
this._flush_trace(),
this._flush_metric()
]);
} catch (e) {
// We must not fail this call, but we may log it
diag.error('Error while flushing the lambda', e);
}
}

private async _flush_trace() {
if (this._traceForceFlusher) {
flushers.push(this._traceForceFlusher());
await this._traceForceFlusher();
} else {
diag.error(
'Spans may not be exported for the lambda function because we are not force flushing before callback.'
);
}
}

private async _flush_metric() {
if (this._metricForceFlusher) {
flushers.push(this._metricForceFlusher());
await this._metricForceFlusher();
} else {
diag.error(
'Metrics may not be exported for the lambda function because we are not force flushing before callback.'
);
}

try {
await Promise.all(flushers);
} catch (e) {
// We must not fail this call, but we may log it
diag.error('Error while flushing the lambda', e);
}
}

private _endSpan(span: Span, err: string | Error | null | undefined) {
Expand Down
Loading