Skip to content

feat(eval): add otel.vllm_traces to join vLLM request spans to rollout traces - #4749

Merged
iguehring-nvidia merged 3 commits into
mainfrom
iguehring/vllm-otlp-traces
Oct 20, 2026
Merged

iguehring-nvidia merged 3 commits into
mainfrom
iguehring/vllm-otlp-traces

Conversation

@iguehring-nvidia

@iguehring-nvidia iguehring-nvidia commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds otel.vllm_traces to the eval-submit collector config. When set, each vLLM service whose API server runs on the collector's node is started with --otlp-traces-endpoint http://localhost:4318/v1/traces, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf and OTEL_SERVICE_NAME=<component>/<service>. vLLM then exports one llm_request span per request, carrying queue, prefill, decode and end-to-end time, time to first token and prompt/completion token counts. Because Gym's model server already injects traceparent and vLLM adopts it once tracing is enabled, every engine span lands as a child of the Gym model call inside the rollout's trace, with no change to Gym's own instrumentation.

Why: a rollout's duration was one number. With the engine spans in the same trace, a slow rollout can be split into engine queue, prefill and decode versus Gym-side time, per call.

Details:

  • The flag and env go through the service's own extra_args and env, so the plain, multi-node Ray, data-parallel, Ray Serve and prefill/decode builders all carry them without knowing about tracing. An explicit OTEL_SERVICE_NAME in the service's env wins.
  • Headless data-parallel workers get the flag stripped, the same way --api-server-count is stripped: request spans come from the head's API server, and a worker has no collector on its node.
  • A prefill/decode tier pinned to a pool whose head is not the collector's node is left untraced rather than pointed at an unreachable endpoint.
  • Off by default. It roughly doubles a run's span volume, and the vLLM image must include the OpenTelemetry SDK (the vllm/vllm-openai images do) or vllm serve refuses to start.

No issue; this is a small addition to the collector config that follows #3610.

Validation

  • pytest tests/unit_tests/test_orchestration_otel.py tests/unit_tests/test_slurm_script.py tests/unit_tests/test_orchestration_api.py: 346 passed. New tests cover the default (off), the rendered flag and env, precedence of the service's own flags and env, the collector-disabled case, the prefill/decode tier placement rule, and the headless-worker strip.
  • pre-commit run --files <changed files>: passed.
  • End to end on a Slurm cluster with the same flag and env set by hand on the vLLM service (vLLM 0.26.0, 2 GPUs TP2, 16 scicode rollouts): 72 of 72 llm_request spans arrived at the collector as children of the policy model's client span, all inside a gym.rollout, with gen_ai.latency.* and gen_ai.usage.* populated; collector log clean; the job's own spans and metrics unchanged.

Rollout evidence

The end-to-end run above (16 rollouts, all scored). The change affects only the vllm serve command line and its environment when the option is on; rollout behaviour is unchanged.

Combined end-to-end run (added after opening)

Run on a Slurm cluster from a temporary branch merging #4749, #4750 and #4751 on top of main (7719379), with otel.vllm_traces: true and no hand-set flags: Nano 3.5 on vLLM 0.26.0, 2 GPUs (TP2), 16 scicode rollouts, 8 in parallel. Completed in 8 min 31 s, 16 of 16 scored, collector log clean, no token in the job directory.

Review follow-up

The automated review found two placements where the service-wide guard handed a localhost endpoint to an API process that does not share the collector's node: an unpinned multi-node service (API on node 0) when the collector follows the driver to the policy's later pool, and layouts with one API per node (a server_per_node tier, multi-node Ray Serve replicas). The guard now resolves the node of a service's single API server the same way the builders and _service_nodelist place it, returns "many" for per-node layouts, and traces only when that node is the collector's. Tests added for each case; pytest tests/unit_tests/test_slurm_script.py tests/unit_tests/test_orchestration_otel.py: 294 passed.

Sandboxed end-to-end run (added after opening)

Terminal-bench 4 miniswe on OpenSandbox sandboxes, 8 tasks, with the placement fix (db4cc8f): the rendered flag reached vLLM and 321 llm_request spans arrived at the collector with timings and token counts; collector log clean.

…t traces

With `otel.vllm_traces: true`, every vLLM service whose API server runs on
the collector's node is started with
`--otlp-traces-endpoint http://localhost:4318/v1/traces`,
`OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf` (vLLM defaults to gRPC)
and `OTEL_SERVICE_NAME=<component>/<service>`, so vLLM exports one
`llm_request` span per request (queue, prefill, decode, end-to-end time,
time to first token, token counts) to the per-job collector. Gym's model
server already injects `traceparent`, and vLLM adopts it when tracing is
on, so each engine span becomes a child of the model call inside the
rollout's trace.

The flag and env travel through the service's own `extra_args` and `env`,
so every command builder carries them; a service's explicit env wins.
Headless data-parallel workers have the flag stripped like
`--api-server-count`, and a prefill/decode tier pinned to a pool whose
head is another node is left untraced rather than pointed at a collector
it cannot reach.

Off by default: it roughly doubles a run's span volume, and the vLLM
image must ship the OpenTelemetry SDK or `vllm serve` refuses to start.

Signed-off-by: Ingo Guehring <[email protected]>
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

@iguehring-nvidia iguehring-nvidia added feature New capabilities, enhancements, or enablement work area:orchestration Job submission, deployment, services, and lifecycle management needs-review PR is ready for code review and waiting on a reviewer labels Oct 19, 2026
@iguehring-nvidia iguehring-nvidia self-assigned this Oct 19, 2026
@iguehring-nvidia

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOLD — automatic tracing can target nodes without a collector in supported multi-node layouts.

Two RISK findings below. Reviewed all six changed files and traced the affected placement, command-builder, and replica-startup paths. Static review only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex

if not (otel_active(config) and config.otel.vllm_traces and isinstance(service, VllmServiceConfig)):
return service
collector_node = driver_node if driver_node is not None else 0
if service.node_pool is not None and _pool_offsets(compute)[service.node_pool][0] != collector_node:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK — Check unpinned API placement when the collector moves to a later pool

Failure / blast radius: With a policy pinned to the second one-node pool, an unpinned ordinary vLLM judge, and otel.vllm_traces: true, the collector runs beside the policy on node 1, but the judge's API runs on allocation node 0. This guard checks only pinned services, so the judge receives http://localhost:4318/v1/traces on node 0, where this job has no collector; its request spans are lost. The placement distinction is already captured by the unpinned-judge regression case and collector placement. Automatic tracing should remain off for that off-node API, as it does for off-node pinned tiers.

Correction: For head-only builders, compare the actual API head with collector_node, including the unpinned allocation-head case. A narrow suggested addition after the existing pinned-pool guard is:

    if service.node_pool is None and collector_node != 0:
        total_nodes, _ = _node_totals(compute)
        gpus = [p.gpus_per_node for p in compute.node_pools.values() if p.gpus_per_node is not None]
        if not effective_ray_serve(service, total_nodes, gpus):
            return service

This follows the inspected unpinned plain/Ray-core/DP builders. It deliberately does not impose an allocation-head rule on Ray Serve replicas, which have runtime placement. Suggested code is unexecuted and must be verified before adoption.

Preservation / acceptance: Proposed regression: use the policy-on-second-pool plus unpinned-judge setup above; expect automatic tracing on the policy, none on the judge, and the judge still probed on localhost:9000. Move the collector/policy to node 0 and expect the unpinned judge to be traced. Retain tracing for a pinned policy beside a nonzero collector, skipping remote pinned services, and the existing off/disabled cases. Preserve the explicit service-name assertion: OTEL_SERVICE_NAME=mine, not the generated identity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and fixed in db4cc8f. The guard now resolves the node of a service's single API server the same way the builders and _service_nodelist place it (pinned: pool head; unpinned multi-node: node 0; unpinned single-node: beside the driver) and traces only when that node is the collector's. Regression tests: policy pinned to the second pool plus an unpinned judge, which is traced on the policy, not on the judge, with the judge still probed on localhost:9000; and the same layout with the collector on node 0, where the judge is traced. The explicit OTEL_SERVICE_NAME=mine assertion is kept.

collector_node = driver_node if driver_node is not None else 0
if service.node_pool is not None and _pool_offsets(compute)[service.node_pool][0] != collector_node:
return service
extra_args = f"{service.extra_args} {vllm_traces_flag()}".strip()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RISK — Select automatic tracing per API process, not per replicated service

Failure / blast radius: A vllm_pd service with server_per_node: true, a two-node prefill pool starting at node 0, and otel.vllm_traces: true passes the pool-head check. The resulting plain command contains the localhost tracing endpoint and is launched on both prefill nodes, although the collector runs only on node 0. Requests routed to the second prefill API therefore cannot export their spans. The per-node command sizing and srun sizing explicitly produce this topology.

The same service-wide assumption affects multi-node Ray Serve: with two one-GPU nodes, use_ray_serve: true and two TP1 instances, replicas are limited to one per node, but both subprocesses receive the same localhost endpoint. Replica placement and subprocess startup show that the gateway's node is not every vLLM API's node. This is localized telemetry loss for opt-in replicated layouts, not a demonstrated scoring failure.

Correction: Restore the invariant that an automatically injected localhost endpoint reaches this job's collector from the process receiving it. Keep the automatic tracing setting separate from user extra_args: select it per task for server_per_node, and pass collector identity through _build_vllm_ray_serve_command so VLLMInstance.__init__ can select it using the replica's actual node. A service-wide guard cannot preserve tracing for colocated APIs while excluding remote replicas. The runtime node-identity plumbing is an implementation choice, so I cannot provide a safe drop-in service-only replacement.

Preservation / acceptance: Proposed checks: render/inspect final argv for the two per-node prefill tasks—only the collector-node task gets the generated endpoint; the remote decode tier remains unchanged. For Ray Serve, mock replica placement on collector/noncollector nodes and inspect Popen argv: generated endpoint present only for the colocated replica; single-node Serve still gets tracing. Keep user-provided flags/env intact on both nodes rather than indiscriminately stripping tracing options. Retain ordinary DP's traced head and untraced headless worker, including --max-model-len 8192 on the worker (new regression assertions). Any added shell branching must also retain the existing API-server-count and JSON-argument checks: neighboring flags survive and the JSON reaches the command as one argument. These are proposed checks, not executed results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in db4cc8f, by exclusion rather than per-process selection: a server_per_node tier over more than one node and a multi-node Ray Serve service are left untraced, since a localhost endpoint reaches this job's collector from one node only. Single-node Ray Serve is still traced. Per-task or per-replica selection would need collector identity plumbed into the per-node task and into VLLMInstance; that is more than this option should carry, and these layouts are opt-in. Documented in the collector page. Tests: per-node prefill/decode tiers untraced; two-node Ray Serve untraced, one-node Ray Serve traced; the DP head/worker and JSON-argument cases unchanged.

The guard compared pinned pools only. An unpinned multi-node service
answers on node 0 while the collector follows the driver to the policy's
pool, a server-per-node tier runs one API on every pool node, and
multi-node Ray Serve places replicas across nodes; all of them were handed
a localhost endpoint that reaches a collector only from one node.

_vllm_api_node mirrors the placement the builders and _service_nodelist
produce and returns None for multi-API layouts; tracing is applied only
when that node is the collector's. Tests cover the unpinned API with the
collector on a later pool and on node 0, the per-node tier, and single-
versus multi-node Ray Serve.

Signed-off-by: Ingo Guehring <[email protected]>
@iguehring-nvidia

Copy link
Copy Markdown
Contributor Author

/review

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP — both prior placement failures are resolved; no eligible findings remain.

  • The placement guard now excludes an unpinned node-0 API when the collector runs in a later pool. The regression cases retain tracing when the API and collector are colocated.
  • Multi-node per-node tiers and Ray Serve are now excluded from automatic tracing, removing the unreachable localhost endpoints. Single-node Serve remains eligible, with regression coverage and the narrowed behavior documented.

Inspected all six changed files. Follow-up review compared the fixes against the previous reviewed tree and traced the directly affected placement and command-builder paths; it did not restart broad defect discovery. Static review only; tests were not executed.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex

@yaoyu-33 yaoyu-33 added the complexity:medium Single-domain change with interacting parts or a moderate review surface label Oct 19, 2026

@prokotg prokotg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge as-is to ship the feature but this needs to be refactor to shift otel modification responsibilities to services. I think it would be best if a follow-up MR is opened after automatic GPU placement and service wiring improvement is merged. Right now _with_vllm_traces special-cases VllmServiceConfig in the Slurm renderer. Every new service type or executor (k8s) would repeat that. Proposal: the service owns how it adapts to a collector, and the renderer stays generic.

class ServiceOtel(_StrictModel):
    enabled: bool = True

class VllmOtel(ServiceOtel):
    traces: bool = False

class Observable(BaseModel):
    @classmethod
    def __pydantic_init_subclass__(cls, **kw):
        super().__pydantic_init_subclass__(**kw)
        if "otel" not in cls.model_fields:
            raise TypeError(f"{cls.__name__} must declare an `otel` field")

    def with_otel(self, ctx: OtelContext) -> Self:
        """Return a copy adapted to the collector; never mutate self."""

class VllmServiceConfig(Observable, ServiceConfigBase):
    otel: VllmOtel = VllmOtel()

    def with_otel(self, ctx):
        ...  # fill typed otel state; the builder renders the flag/env

Renderer: service = service.with_otel(ctx) if isinstance(service, Observable) else service.

@iguehring-nvidia
iguehring-nvidia added this pull request to the merge queue Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/39400826081

Merged via the queue into main with commit d96b337 Oct 20, 2026
51 of 56 checks passed
@iguehring-nvidia
iguehring-nvidia deleted the iguehring/vllm-otlp-traces branch October 20, 2026 09:41

This branch was previously deployed

1 inactive deployment
public — db4cc8fe Deployed Oct 19, 2026 by copy-pr-bot[bot] via release / finalize / notify #5803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:orchestration Job submission, deployment, services, and lifecycle management complexity:medium Single-domain change with interacting parts or a moderate review surface feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants