-
Notifications
You must be signed in to change notification settings - Fork 0
construct metrics
awekrx edited this page May 29, 2026
·
1 revision
import { constructMetrics } from '@dev-suite/decorators/construct-metrics'
class
Measure constructor duration and success/failure for expensive object initialization.
- Manual timing/reporting blocks in constructors
- One-off metrics wrappers per class
class ModelCache {
constructor() {
const startedAt = performance.now();
try {
this.warmup();
metrics.report({ name: 'ModelCache', success: true, durationMs: performance.now() - startedAt });
} catch (error) {
metrics.report({ name: 'ModelCache', success: false, durationMs: performance.now() - startedAt, error });
throw error;
}
}
private warmup() {}
}import { constructMetrics } from '@dev-suite/decorators/construct-metrics';
@constructMetrics({ reporter: metrics.report })
class ModelCache {
constructor() {
this.warmup();
}
private warmup() {}
}- Metrics policy is centralized and reusable
- Constructor body is no longer polluted by telemetry boilerplate
class FeatureIndex {
constructor() {
const start = Date.now();
this.load();
statsd.timing('feature_index.construct.ms', Date.now() - start);
}
private load() {}
}import { constructMetrics } from '@dev-suite/decorators/construct-metrics';
@constructMetrics({
reporter: ({ className, durationMs, success }) => {
statsd.timing(className + '.construct.ms', durationMs);
statsd.increment(className + '.construct.' + (success ? 'ok' : 'fail'));
},
})
class FeatureIndex {
constructor() {
this.load();
}
private load() {}
}- One pattern supports both latency and outcome metrics
- Same metrics strategy can be applied to other classes quickly