Skip to content

Commit

Permalink
Clear timer on handover (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Sep 12, 2023
1 parent 311e43c commit 9c12c2d
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit 9c12c2d

Please sign in to comment.