Files
Compass/backend/shared/src/monitoring/context.ts
Martin Braquet ba9b3cfb06 Add pretty formatting (#29)
* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
2026-02-20 17:32:27 +01:00

29 lines
716 B
TypeScript

// Shared contextual information that metrics and logging can use, e.g.
// the scheduler job or HTTP request endpoint currently running.
import {AsyncLocalStorage} from 'node:async_hooks'
export type ContextDetails = Record<string, string>
export type JobContext = ContextDetails & {
job: string
traceId: string
}
export type RequestContext = ContextDetails & {
endpoint: string
traceId: string
}
export type MonitoringContext = JobContext | RequestContext
export const STORE = new AsyncLocalStorage<MonitoringContext>()
export function withMonitoringContext<R>(ctx: MonitoringContext, fn: () => R) {
return STORE.run(ctx, fn)
}
export function getMonitoringContext() {
return STORE.getStore()
}