pydantic/monty · error · Error

at least one OpenTelemetry component is required

Error message

at least one OpenTelemetry component is required

What it means

`instrumentTelemetry` requires at least one OpenTelemetry component: a tracer, a meter, or a logger. If all three are undefined the call is a no-op configuration, so the function throws this Error to signal the misconfiguration rather than installing nothing.

Source

Thrown at crates/monty-js/ts/telemetry.ts:176

    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()
  }
}

/**
 * OpenTelemetry instrumentation for use with `NodeSDK` and compatible SDKs.
 *
 * Adding an instance to an SDK's `instrumentations` array explicitly enables

View on GitHub (pinned to adc986b362)

Solutions

  1. Pass at least one component: `instrumentTelemetry({ tracer, meter, logger })` with at least one defined.
  2. If telemetry is optional, skip the call entirely when no components are configured instead of calling it with an empty object.
  3. Verify the property names (`tracer`, `meter`, `logger`) match your constructed components; renamed variables silently leave all fields undefined.

Example fix

// before
instrumentTelemetry({}) // throws

// after
const components = { tracer: getTracer() }
if (components.tracer || components.meter || components.logger) {
  instrumentTelemetry(components)
}
Defensive patterns

Strategy: validation

Validate before calling

function hasAnyComponent(v: TelemetryComponents): boolean {
  return v.tracer !== undefined || v.meter !== undefined || v.logger !== undefined
}
// call only if hasAnyComponent(components)

Type guard

function isTelemetryComponentsConfigured(v: TelemetryComponents): boolean {
  return [v.tracer, v.meter, v.logger].some(c => c !== undefined)
}

Try / catch

try {
  instrumentTelemetry(components)
} catch (err) {
  if (err instanceof Error && err.message === 'at least one OpenTelemetry component is required') {
    console.warn('telemetry disabled: no components configured')
  } else {
    throw err
  }
}

Prevention

When it happens

Trigger: Calling `instrumentTelemetry({})` or passing an object whose `tracer`, `meter`, and `logger` properties are all undefined — e.g. building the object conditionally from environment variables where none were set.

Common situations: Config-driven setup where `OTEL_TRACER`/`OTEL_METER`/`OTEL_LOGGER` flags are all absent or disabled; a refactor that renamed the component keys so the values no longer land on `tracer`/`meter`/`logger`; passing `undefined` from an optional getter.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of pydantic/monty@adc986b362 (2026-09-13). Data as JSON: /api/errors/81541a2d9c9988fc. Report an issue: GitHub.