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

Clear timer on handover #124

Merged
merged 1 commit into from
Sep 12, 2023
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
13 changes: 13 additions & 0 deletions packages/autometrics/src/temporaryMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export class TemporaryMeter implements Meter {
* their newly created counterparts, as consumers might be holding on to the
* instances created by the temporary exporter.
*
* Do NOT create new metrics from this meter after the handover! It will only
* yield noop metrics from that moment on.
*
* @internal
*/
handover(meter: Meter) {
Expand Down Expand Up @@ -235,6 +238,11 @@ export class TemporaryMeter implements Meter {
this._createdObservableGauges = [];
this._createdObservableUpDownCounters = [];
this._registeredBatchObservableCallbacks = [];

if (this._timer) {
clearTimeout(this._timer);
this._timer = false;
}
}

metricsRecorded() {}
Expand All @@ -250,6 +258,11 @@ export class TemporaryMeter implements Meter {
* shooting themselves in the foot, we will log a warning if the timer expires
* and stop the collecting of metrics when that happens.
*
* The timer remains `undefined` as long as no metrics are registered and is
* only initialized on the first metric registration. A value of `false` means
* a timer was created, but has already expired, in which case no new timer
* should be scheduled.
*
* @internal
*/
private _timer: ReturnType<typeof setTimeout> | false | undefined;
Expand Down