Skip to content

Commit

Permalink
Avoid flushing metrics when sending early spans (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski authored Jul 30, 2024
1 parent 8b0bf41 commit 433fe34
Showing 1 changed file with 18 additions and 11 deletions.
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

0 comments on commit 433fe34

Please sign in to comment.