{"record":{"id":"1929ba32bf15c44b","repo":"pydantic/monty","slug":"monty-telemetry-is-already-configured","errorCode":null,"errorMessage":"Monty telemetry is already configured","messagePattern":"Monty telemetry is already configured","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/telemetry.ts","lineNumber":173,"sourceCode":"      return callback()\n    })\n  } catch (error) {\n    if (invoked) {\n      throw error\n    }\n    return callback()\n  }\n}\n\n/**\n * Instrument Monty with standard OpenTelemetry components.\n *\n * Installation is process-wide and must happen before creating a pool. Each\n * signal is independently optional.\n */\nexport function instrumentTelemetry(value: TelemetryComponents): void {\n  if (owner !== undefined) {\n    throw new Error('Monty telemetry is already configured')\n  }\n  if (value.tracer === undefined && value.meter === undefined && value.logger === undefined) {\n    throw new Error('at least one OpenTelemetry component is required')\n  }\n  activate(directOwner, value)\n}\n\n/** Wait until telemetry queued by the native pool has reached JavaScript. */\nexport async function flushTelemetry(): Promise<void> {\n  await flushNativeTelemetry()\n  if (!acceptingTelemetry) {\n    components = undefined\n    spans.clear()\n    instruments.clear()\n  }\n}\n\n/**","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/telemetry.ts#L155-L191","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ninstrumentTelemetry({ tracer })\n// ...later, same process\ninstrumentTelemetry({ tracer }) // throws\n\n// after\nif (!telemetryInstalled) {\n  telemetryInstalled = true\n  instrumentTelemetry({ tracer })\n}","handlingStrategy":"validation","validationCode":"let telemetryInstalled = false\nfunction setupTelemetryOnce(components: TelemetryComponents): void {\n  if (!telemetryInstalled) {\n    instrumentTelemetry(components)\n    telemetryInstalled = true\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  instrumentTelemetry({ tracer })\n} catch (err) {\n  if (err instanceof Error && err.message === 'Monty telemetry is already configured') {\n    // another module installed telemetry; keep existing config\n  } else {\n    throw err\n  }\n}","preventionTips":["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."],"tags":["typescript","telemetry","opentelemetry","double-initialization"],"backgroundTag":"double-initialization","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}