pydantic/monty · error · Error
Monty telemetry is already configured
Error message
Monty telemetry is already configured
What it means
`instrumentTelemetry` installs OpenTelemetry hooks (tracer/meter/logger) into the monty native pool, and installation is process-wide and single-shot. If telemetry was already configured — by a prior `instrumentTelemetry` call or the native side registering an owner — the function throws this Error instead of silently overwriting the active configuration.
Source
Thrown at crates/monty-js/ts/telemetry.ts:173
return callback()
})
} catch (error) {
if (invoked) {
throw error
}
return callback()
}
}
/**
* Instrument Monty with standard OpenTelemetry components.
*
* Installation is process-wide and must happen before creating a pool. Each
* signal is independently optional.
*/
export function instrumentTelemetry(value: TelemetryComponents): void {
if (owner !== undefined) {
throw new Error('Monty telemetry is already configured')
}
if (value.tracer === undefined && value.meter === undefined && value.logger === undefined) {
throw new Error('at least one OpenTelemetry component is required')
}
activate(directOwner, value)
}
/** Wait until telemetry queued by the native pool has reached JavaScript. */
export async function flushTelemetry(): Promise<void> {
await flushNativeTelemetry()
if (!acceptingTelemetry) {
components = undefined
spans.clear()
instruments.clear()
}
}
/**View on GitHub (pinned to adc986b362)
Solutions
- Call `instrumentTelemetry` exactly once per process, ideally at startup before creating any pool.
- Guard the call with an `isTelemetryConfigured()`-style check or your own module-level boolean.
- In tests, install telemetry once in a global setup file instead of per-test; if state is corrupted, reset module state or spawn a fresh process/worker.
Example fix
// before
instrumentTelemetry({ tracer })
// ...later, same process
instrumentTelemetry({ tracer }) // throws
// after
if (!telemetryInstalled) {
telemetryInstalled = true
instrumentTelemetry({ tracer })
} Defensive patterns
Strategy: validation
Validate before calling
let telemetryInstalled = false
function setupTelemetryOnce(components: TelemetryComponents): void {
if (!telemetryInstalled) {
instrumentTelemetry(components)
telemetryInstalled = true
}
} Try / catch
try {
instrumentTelemetry({ tracer })
} catch (err) {
if (err instanceof Error && err.message === 'Monty telemetry is already configured') {
// another module installed telemetry; keep existing config
} else {
throw err
}
} Prevention
- Install telemetry exactly once, at process startup, before creating any pool.
- Centralize setup in one module/function that all entry points share.
- In tests, use a global setup file rather than per-file instrumentation.
When it happens
Trigger: Calling `instrumentTelemetry(...)` more than once in the same process; calling it after a pool or module load already activated telemetry; duplicate setup in tests where module state persists across cases.
Common situations: Test suites importing the module in multiple files with a shared global `beforeAll` that installs telemetry each time; hot-reload or double-import of the telemetry module in bundlers; library code and app code both attempting to install hooks.
Related errors
- at least one OpenTelemetry component is required
- ClassInstance expects an object instance
- notCallableMessage(method)
- ClassInstance expects an instance of a class, not a null-pro
- classType does not match the instance's class
AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13).
Data as JSON: /api/errors/1929ba32bf15c44b.
Report an issue: GitHub.