nemo_rl.telemetry.setup#
Process-global nemo-lens telemetry lifecycle for NeMo-RL.
Two entry points, mirroring Megatron’s global_vars._set_telemetry /
get_telemetry_handle pattern but adapted to NeMo-RL’s Ray driver + worker process
model:
- func:
init_telemetry_driver— called once on the driver, beforeinit_ray(). It reads thetelemetry:config block, exports the settings asNEMO_RL_OTEL_*env vars so every Ray worker inherits them, and sets up the driver’s own telemetry (the training loop and the metrics logger run here, so the driver always exports).
- func:
init_telemetry_worker— called once inside each Ray actor process, from the worker’s__init__(policy, value and vLLM generation workers). It reads the propagated env and sets up that worker’s telemetry, then- func:
shutdown_telemetryflushes it from the worker’sshutdown.__init__rather thanpost_init, because somepost_initfan-outs run on only one rank per parallel group, while OTel providers have to be set up in every actor process.
nemo-lens is a base dependency, so telemetry.enabled is the only switch:
when it is false the init functions return None and every instrumentation
site is a ~0-cost no-op. Lens imports stay function-local to keep the cost off
the import path of modules that never emit anything.
Module Contents#
Functions#
Return True if env var |
|
Whether |
|
Whether |
|
Translate a |
|
Best-effort nested lookup that works for both dicts and objects. |
|
Build process-lifetime resource attributes (Jaeger “Process” tags). |
|
Export-strategy override for singleton processes: always export. |
|
Disable rank-based span filtering for a process that has no real rank. |
|
Initialise driver-side telemetry (call once, before |
|
Build resource attributes identifying this worker process. |
|
Initialise telemetry inside a Ray actor (call once per worker process). |
|
Return the process-global telemetry handle ( |
|
Flush and shut down telemetry providers. |
Data#
API#
- nemo_rl.telemetry.setup.logger#
‘getLogger(…)’
- nemo_rl.telemetry.setup._TELEMETRY_HANDLE: Optional[nemo.lens.TelemetryHandle]#
None
- nemo_rl.telemetry.setup._TELEMETRY_INITIALISED#
False
- nemo_rl.telemetry.setup._OTEL_PREFIX#
‘NEMO_RL_OTEL’
- nemo_rl.telemetry.setup._OTEL_FALLBACK_PREFIX#
‘NEMO_LENS’
- nemo_rl.telemetry.setup._RUN_ID_ENV#
None
- nemo_rl.telemetry.setup._WORKER_GROUP_ENV#
‘NRL_WORKER_GROUP’
- nemo_rl.telemetry.setup._ENV_FIELD_MAP#
None
- nemo_rl.telemetry.setup._SERVICE_NAME_ENV#
‘OTEL_SERVICE_NAME’
- nemo_rl.telemetry.setup._is_env_truthy(name: str) bool#
Return True if env var
nameis set to a truthy value.
- nemo_rl.telemetry.setup.telemetry_enabled_in_env() bool#
Whether
telemetry.enabledreached this process as truthy.Exists for instrumentation that never asks for a handle: vLLM’s native tracing runs on vLLM’s own exporter, so :func:
get_telemetry_handlewould not gate it and the master switch would not reach it. Reads the environment rather than a config object because that is the only channel a worker process has.
- nemo_rl.telemetry.setup.vllm_native_tracing_requested() bool#
Whether
telemetry.vllm_native_tracingreached this process as truthy.Callers must also honour :func:
telemetry_enabled_in_env; this reports only the one field.
- nemo_rl.telemetry.setup._config_to_env(tel: Any) None#
Translate a
TelemetryConfigintoNEMO_RL_OTEL_*env vars.Uses
os.environ.setdefaultso raw env vars always win over YAML. Runs on the driver beforeinit_ray(), so the resulting environment is snapshotted into the Rayruntime_envand inherited by every worker process.
- nemo_rl.telemetry.setup._dig(obj: Any, *path: str) Any#
Best-effort nested lookup that works for both dicts and objects.
Returns
Noneas soon as any level is missing. Used to pull resource attributes out of aMasterConfigwhose nested nodes may be pydantic models (attribute access) or TypedDict-derived dicts (key access).
- nemo_rl.telemetry.setup._build_resource_attributes(
- master_config: Any,
- algorithm: str,
Build process-lifetime resource attributes (Jaeger “Process” tags).
Only stable-for-the-run values belong here (algorithm, model, precision, parallelism). Per-step values are span tags; time-series values are metrics. Best-effort: a missing key simply omits that attribute — never raises.
dl.rank/dl.world_sizeare set by lens from the setup call, not here.
- nemo_rl.telemetry.setup._always_export(
- config: nemo.lens.NemoLensConfig,
- rank: int,
- world_size: int,
Export-strategy override for singleton processes: always export.
- nemo_rl.telemetry.setup._unrank(config: nemo.lens.NemoLensConfig) Any#
Disable rank-based span filtering for a process that has no real rank.
The driver and singleton actors such as
AsyncTrajectoryCollectorare not members of a distributed group, so they pass a syntheticrank=0/world_size=1. Both of lens’s rank filters then misfire on that made-up rank, and the two are independent, so both have to be neutralised:export_strategydecides whether this process exports at all. A strategy that selects among the ranks of a group has no meaning for a singleton, and mutes it outright for anyexport_rank >= 1.sampler_enabledinstalls aRankAwareSampleron the tracer provider, which drops every span on ranks whosemd5(rank)bucket lands aboveexport_sample_rate. Rank 0’s bucket is 0.785, so any sample rate at or below that discards the process’s spans before the export decision is ever consulted.
The driver hosts the training loop and the metrics logger, and the collector generates every async rollout, so either filter silently drops the telemetry that matters most.
Mutating
confighere is process-local: it is rebuilt from the environment in each process, and the propagatedNEMO_RL_OTEL_*vars are untouched, so ranked workers still honour what the user configured.Returns the export-strategy override to hand to
setup_telemetry.
- nemo_rl.telemetry.setup.init_telemetry_driver(
- master_config: Any,
- algorithm: str,
Initialise driver-side telemetry (call once, before
init_ray()).Reads
master_config.telemetry, exports the resolved settings asNEMO_RL_OTEL_*env vars (so workers inherit them), and sets up the driver’s OTel providers. The driver always exports (it hosts the training loop and the metrics logger).Returns the :class:
TelemetryHandle, orNoneif telemetry is disabled. Idempotent.- Raises:
ValueError – if
telemetry.export_strategynames a strategy lens does not have. Deliberately fatal on the driver, where the user sees it.
- nemo_rl.telemetry.setup._worker_resource_attributes(
- extra: Optional[dict[str, Any]],
Build resource attributes identifying this worker process.
RANKis group-local — the policy group and the generation group each number their workers from zero — sodl.rankalone cannot tell their spans apart.rl.worker_groupcarries the group’sname_prefix(lm_policy,vllm_policy, …), whichRayWorkerGroupexports asNRL_WORKER_GROUP. Explicitextraattributes win.
- nemo_rl.telemetry.setup.init_telemetry_worker(
- rank: Optional[int] = None,
- world_size: Optional[int] = None,
- resource_attributes: Optional[dict[str, Any]] = None,
- always_export: bool = False,
Initialise telemetry inside a Ray actor (call once per worker process).
Reads the
NEMO_RL_OTEL_*env propagated from the driver via the Rayruntime_env.rank/world_sizedefault to theRANK/WORLD_SIZEenv vars the worker was launched with, which — together with the export strategy — decide whether this worker exports.- Parameters:
rank – This process’s rank. Defaults to the
RANKenv var.world_size – Size of this process’s group. Defaults to
WORLD_SIZE.resource_attributes – Extra resource attributes for this process.
always_export – Bypass the configured rank filters for this process, the way the driver does (see :func:
_unrank). Set it for a singleton actor passing a syntheticrank/world_size: the filters select among the ranks of a distributed group, so applying them to a made-up rank has no meaning and silently mutes the actor — e.g.export_rank: 3never matches a synthetic rank 0. Ranked members of a real worker group must leave this false.
Never raises: unlike the driver, a worker must not fail a training run over optional observability, and the driver has already validated the same config before any worker starts — so a genuine misconfiguration surfaces there, loudly, rather than here.
Returns the :class:
TelemetryHandle, orNoneif telemetry is disabled or setup failed. Idempotent per process.
- nemo_rl.telemetry.setup.get_telemetry_handle() Optional[nemo.lens.TelemetryHandle]#
Return the process-global telemetry handle (
Noneif uninitialised).Named for the handle rather than the telemetry because callers reach through it –
.tracer,.meter,.is_exporting– rather than using the return value as a value.
- nemo_rl.telemetry.setup.shutdown_telemetry(timeout_ms: int = 5000) None#
Flush and shut down telemetry providers.
Call on the driver at job end, and in each Ray actor’s
shutdown: span and metric processors buffer in the background, so an actor that exits without flushing silently drops whatever it had not exported yet. A no-op when this process never initialised telemetry.