diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 22:39:18 -0800 |
| commit | 666674327f009e9b1013218fc384f193b64c6997 (patch) | |
| tree | acebae7b425b469584eb0a5bec396899c2739501 /lib/trace | |
| parent | 594ce452693a71b501d3aff3f35ef3732c06c341 (diff) | |
| download | pengueno-666674327f009e9b1013218fc384f193b64c6997.tar.gz pengueno-666674327f009e9b1013218fc384f193b64c6997.zip | |
Adds unit tests
Diffstat (limited to 'lib/trace')
| -rw-r--r-- | lib/trace/metric/trace.ts | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/trace/metric/trace.ts b/lib/trace/metric/trace.ts index b28d828..396bd9c 100644 --- a/lib/trace/metric/trace.ts +++ b/lib/trace/metric/trace.ts @@ -16,9 +16,16 @@ export class MetricsTrace implements ITrace<MetricsTraceSupplier> { public traceScope(trace: MetricsTraceSupplier): MetricsTrace { const now = Date.now(); const metricsToTrace = (Array.isArray(trace) ? trace : [trace]).filter(isIMetric); - const initialTraces = new Map(metricsToTrace.map((metric) => [metric.name, now])); - return new MetricsTrace(this.metricConsumer, initialTraces, this.completedTraces); + // Inherit existing active traces across scopes. + const nextActiveTraces = new Map(this.activeTraces); + for (const metric of metricsToTrace) { + if (!nextActiveTraces.has(metric.name)) { + nextActiveTraces.set(metric.name, now); + } + } + + return new MetricsTrace(this.metricConsumer, nextActiveTraces, this.completedTraces); } public trace(metrics: MetricsTraceSupplier): MetricsTrace { |
