-
Notifications
You must be signed in to change notification settings - Fork 0
metrics
awekrx edited this page May 29, 2026
·
1 revision
import { metrics } from '@dev-suite/decorators/metrics'
method
Capture method duration and success/failure for observability.
- Manual timer and reporter calls in each method
- Inconsistent metric naming conventions
class ImportService {
async run(jobId: string) {
const start = performance.now();
try {
const result = await this.worker.run(jobId);
report({ name: 'import.run', ok: true, ms: performance.now() - start });
return result;
} catch (error) {
report({ name: 'import.run', ok: false, ms: performance.now() - start, error });
throw error;
}
}
}import { metrics } from '@dev-suite/decorators/metrics';
class ImportService {
@metrics({ reporter: report })
async run(jobId: string) {
return this.worker.run(jobId);
}
}- Metrics contract is reused and less error-prone.
- Method body stays domain-oriented.
class PdfService {
async render(id: string) {
const started = Date.now();
const result = await this.engine.render(id);
statsd.timing('pdf.render.ms', Date.now() - started);
return result;
}
}import { metrics } from '@dev-suite/decorators/metrics';
class PdfService {
@metrics({ reporter: ({ durationMs }) => statsd.timing('pdf.render.ms', durationMs) })
async render(id: string) {
return this.engine.render(id);
}
}- Reporter can map to existing telemetry backend cleanly.
- No per-method timing boilerplate.