Repository navigation
Conversation
TelemetryConfig.instrument_aiohttp and its NEMO_GYM_OTEL_INSTRUMENT_AIOHTTP env mapping changed nothing: neither Gym nor nemo-lens calls instrument_aiohttp_client or reads the variable. Gym's outbound CLIENT span and traceparent injection come from server_utils.request, gated on the http_client span group, so the docstring's claim was wrong too. Configs that still set the key keep loading because TelemetryConfig allows extra keys, matching the earlier export_strategy/export_rank removal. Signed-off-by: Ananth Subramaniam <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
opentelemetry-instrumentation-aiohttp-client only backs nemo-lens's instrument_aiohttp_client, which nothing calls. Remove it from the telemetry extra and from the packages installed into server venvs. server_utils.request already makes the outbound CLIENT span and injects traceparent without it. Signed-off-by: Ananth Subramaniam <[email protected]>
Contributor
Author
|
Folded into #4481, which carries both commits unchanged on top of current main, along with this PR's validation and rollout evidence. Both PRs remove telemetry instrumentation that exports nothing, so they are easier to review together. |
ananthsub
added a commit
that referenced
this pull request
Oct 14, 2026
> **Stack:** telemetry lands before the optimizations, so the optimizations can be measured with it. > 1. #4474: event-loop, process, request, driver, and resources-operation metrics (merged) > 2. #4481: drop instrumentation that exports nothing (base `main`) > 3. #2890: replace the HTTP middleware wrappers with ASGI (base #4481) ## What changed With `traces_enabled: false`, nemo-lens still enables the configured span groups, so instrumentation whose only output is spans kept running on every request against a tracer that records nothing. This PR skips that work while traces are off: - `init_telemetry` records whether the process exports traces, and `nemo_gym.telemetry.setup.is_trace_exporter_active()` reports it. When Gym reuses providers another library set up, it checks for a real SDK tracer provider, as it already does for metrics. - `SimpleServer.instrument_app_for_telemetry` installs the FastAPI instrumentor only while traces export. - `server_utils.request` opens the outbound CLIENT span and injects `traceparent` only while traces export. - The `telemetry.instrument_aiohttp` setting and its `NEMO_GYM_OTEL_INSTRUMENT_AIOHTTP` variable are removed. Nothing in Gym or nemo-lens calls `nemo.lens.contrib.aiohttp.instrument_aiohttp_client`, so the setting never did anything; its docstring described a CLIENT span that Gym in fact creates itself in `server_utils.request`. - `opentelemetry-instrumentation-aiohttp-client`, which only backs that unused helper, is dropped from the `telemetry` extra and from the packages installed into each server venv. Span groups that also drive metrics, such as `verify`, `rollout`, and `sandbox`, are unchanged, so `gym.verify.*`, `gym.rollout.*`, and the sandbox metrics still report in a metrics-only run. The FastAPI instrumentor is also the source of the `http.server.*` metrics. A metrics-only run no longer reports them, and the docs now say so. The docs also named metrics the pinned instrumentation does not export: a run exports `http.server.duration` (ms), `http.server.request.size`, `http.server.response.size`, and `http.server.active_requests`, keyed by `http.target`, `http.method`, and `http.status_code`, while `metrics.mdx`, `extending.mdx`, and the telemetry README listed `http.server.request.duration`. ## Why Measured on one workstation with tracing off, the FastAPI instrumentor adds about 63 µs to each inbound request (15 µs bare, 78 µs instrumented). The outbound path adds a no-op span and a header injection to every call between servers. Neither produces anything a metrics-only run can use. ## Issue Closes #4478. The issue also listed aiohttp client instrumentation at about 58 µs per outbound request. Nothing in Gym or nemo-lens installs that instrumentor; the outbound cost Gym pays comes from its own client span, which this PR gates, and the setting that appeared to control the instrumentor is removed. This PR absorbs #4485. ## Compatibility - Runs with `traces_enabled: false` and metrics on lose the `http.server.*` metrics. Turn traces on to keep them. - Runs with traces on are unchanged. - Configs that still set `instrument_aiohttp` keep loading, because `TelemetryConfig` allows extra keys; the key has no effect, as before. The setting is removed rather than deprecated, as `export_strategy` and `export_rank` were in #3890. - The `telemetry` extra no longer installs `opentelemetry-instrumentation-aiohttp-client`. `daytona` still depends on it, so it stays in `uv.lock` for the `sandbox` extra. Code that calls `instrument_aiohttp_client` itself can install `nemo-lens[aiohttp]`. - Builds on #4474, now merged. In `server_utils.request`, the trace gate chooses between the traced and untraced send, and #4474's outbound in-flight count wraps either one. ## Validation - `pytest tests/unit_tests/telemetry tests/unit_tests/test_server_utils.py tests/unit_tests/test_cli.py -n 12` with the `telemetry` extra installed. - `pytest tests/unit_tests -n 16`: the only failures are the same environment-dependent ones as on the base commit (`test_opensandbox_compose.py`, `test_reward_profile.py`, `test_dataset_orchestrator.py`, `test_sandbox_stop_retry.py`), and `test_exporters.py` needs `mlflow`. - `test_setup.py` covers the trace flag following `traces_enabled`, the flag for reused providers with and without an SDK tracer provider, and the FastAPI instrumentor installed only while traces export. - `test_config.py` checks that a config setting `instrument_aiohttp` still loads and that `configure_telemetry_env` no longer exports the variable; it fails on the base commit. - In a venv synced from this branch with the `telemetry` extra, `opentelemetry.instrumentation.aiohttp_client` is not importable, and the full unit suite runs with the same environment-dependent failures as the base commit, including passing propagation tests that check `traceparent` on outbound requests. - `uv lock --check` passes. - `test_propagation.py` serves two real FastAPI apps and checks that, with traces off, no CLIENT span is produced and no `traceparent` reaches the downstream server. - Removing either gate makes its test fail. - `pre-commit run` on the changed files. - An interleaved comparison through the CPU capacity simulator from #3156 (`fast_inference_burst`, near-instant inference so that Gym's own cost dominates, 2,048 rollouts per run, three runs per setting, engine, servers, and driver pinned to separate cores, traces off). Server CPU per rollout, median with range: | Setting | Server CPU per rollout | Rollouts per second | | --- | ---: | ---: | | Base commit, metrics on | 22.6 ms (22.6–22.7) | 100 (97–107) | | This PR, metrics on | 21.0 ms (21.0–21.1) | 106 (102–109) | | This PR, telemetry off | 19.7 ms (19.4–19.7) | 114 (110–114) | The cost of turning metrics on drops from about 2.9 ms to 1.3 ms per rollout. Both metrics-on runs exported the same `gym.*` metrics, including `gym.rollout.duration_ms` and the connection-pool metrics; only the `http.server.*` metrics are gone. No run had a failed rollout. ## Rollout evidence `example_single_tool_call` with the simple agent and `gpt-oss-20b` (3 tasks) ran from the dependency-removal commits and from the base commit `75bb53e6d`, both with `span_groups=all`, traces on, and console export, through `gym env start` and then `gym eval run --no-serve`. On the base commit every server venv had `opentelemetry-instrumentation-aiohttp-client`; with the change, none did, and each still had `opentelemetry-instrumentation-fastapi`. | | Base commit | Without the aiohttp package | | --- | --- | --- | | Spans | 238 | 238 | | Span types (name, kind, process) | 49 | 49, identical set | | `HTTP POST` client spans | 26 | 26 | | Traces | 12 | 12 | | Traces that cross processes | 4 | 4 | | Server spans whose parent is a client span in another process | 18 | 18 | | Rewards | 0, 1, 1 | 0, 1, 1 | `traceparent` still joins each outbound request to the server span that handles it. Sandbox spans are not covered, because this environment has no sandbox. The trace gate does not change agent, model, or verifier decisions; the capacity-simulator runs above exercise it through real rollouts with a mock inference engine. --------- Signed-off-by: Ananth Subramaniam <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
TelemetryConfig.instrument_aiohttp(defaulttrue) and itsNEMO_GYM_OTEL_INSTRUMENT_AIOHTTPentry in_ENV_FIELD_MAPhad no effect. Nothing in Gym or in nemo-lens callsnemo.lens.contrib.aiohttp.instrument_aiohttp_client, and nothing reads the environment variable. The field's docstring said it produced a CLIENT span per outbound request. In fact, Gym creates its own CLIENT span and injectstraceparentinnemo_gym/server_utils.py(request->_traced_request), and that span is gated on thehttp_clientspan group.For the same reason,
opentelemetry-instrumentation-aiohttp-clientwas installed but never used. It only backsinstrument_aiohttp_client.This PR:
instrument_aiohttpfield fromTelemetryConfig._ENV_FIELD_MAPand updates the comments that described it.opentelemetry-instrumentation-aiohttp-clientfrom thetelemetryextra inpyproject.tomlanduv.lock._SERVER_TELEMETRY_PACKAGES, so it is no longer installed into each server venv.instrument_aiohttploads, and thatconfigure_telemetry_envno longer exports the variable.I removed the field instead of deprecating it with a warning. The setting never did anything, so a warning would only tell users to delete a no-op line. Removing it also matches how
export_strategyandexport_rankwere handled in #3890.No issue was filed. This is a small cleanup found while reading the telemetry code.
Compatibility
instrument_aiohttpkeep loading, becauseTelemetryConfigallows extra keys. The key has no effect, the same as before.NEMO_GYM_OTEL_INSTRUMENT_AIOHTTPis no longer written to server processes. Nothing read it.telemetryextra no longer installsopentelemetry-instrumentation-aiohttp-client.daytonastill depends on it, so it remains inuv.lockfor thesandboxextra. Anyone callinginstrument_aiohttp_clientthemselves can installnemo-lens[aiohttp].fern/versions/latest/pages/observability/configuration.mdxnever listed the field or the variable, so it needs no change.Validation
uv sync --extra dev --extra telemetryafter the change:opentelemetry.instrumentation.aiohttp_clientis no longer importable in the venv.pytest -n 8 tests/unit_tests/telemetry tests/unit_tests/test_server_utils.pyin that venv: passed. This includes the propagation tests, which check thattraceparentis injected on outbound requests.main. There, the field is still declared andNEMO_GYM_OTEL_INSTRUMENT_AIOHTTPis exported.grepof Gym and the installed nemo-lens package: the only reference toinstrument_aiohttp_clientis its definition innemo/lens/contrib/aiohttp.py.pre-commit run --fileson the changed files: clean.Rollout evidence
I ran
example_single_tool_callwith the simple agent andgpt-oss-20b(3 tasks), once from this branch and once from its base commit (75bb53e6d). Both runs had every span group on (span_groups=all) and used console export. Each rangym env startand thengym eval run --no-serveon the example data.On the base commit, all four server venvs had
opentelemetry-instrumentation-aiohttp-clientinstalled. On this branch, none did. Each venv still hadopentelemetry-instrumentation-fastapi.HTTP POSTclient spansgym.rollout,gym.agent.responses,gym.model.responsesandgym.verify. The FastAPI server spans are present on all four servers.traceparentstill joins each outbound request to the server span that handles it, without the aiohttp instrumentor installed.sandboxspans, because this environment has no sandbox.