Skip to content

fix(telemetry): remove the unused aiohttp client instrumentation - #4485

Closed
ananthsub wants to merge 2 commits into
mainfrom
ananthsub/telemetry-inert-instrument-aiohttp
Closed

ananthsub wants to merge 2 commits into
mainfrom
ananthsub/telemetry-inert-instrument-aiohttp

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

TelemetryConfig.instrument_aiohttp (default true) and its NEMO_GYM_OTEL_INSTRUMENT_AIOHTTP entry in _ENV_FIELD_MAP had no effect. Nothing in Gym or in nemo-lens calls nemo.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 injects traceparent in nemo_gym/server_utils.py (request -> _traced_request), and that span is gated on the http_client span group.

For the same reason, opentelemetry-instrumentation-aiohttp-client was installed but never used. It only backs instrument_aiohttp_client.

This PR:

  • Removes the instrument_aiohttp field from TelemetryConfig.
  • Removes its entry from _ENV_FIELD_MAP and updates the comments that described it.
  • Removes opentelemetry-instrumentation-aiohttp-client from the telemetry extra in pyproject.toml and uv.lock.
  • Removes the same package from _SERVER_TELEMETRY_PACKAGES, so it is no longer installed into each server venv.
  • Adds a test showing that a config which still sets instrument_aiohttp loads, and that configure_telemetry_env no longer exports the variable.
  • Updates the server-requirements test to expect only the FastAPI instrumentation package.

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_strategy and export_rank were handled in #3890.

No issue was filed. This is a small cleanup found while reading the telemetry code.

Compatibility

  • Old configs: configs that still set instrument_aiohttp keep loading, because TelemetryConfig allows extra keys. The key has no effect, the same as before.
  • Environment variable: NEMO_GYM_OTEL_INSTRUMENT_AIOHTTP is no longer written to server processes. Nothing read it.
  • Dependencies: the telemetry extra no longer installs opentelemetry-instrumentation-aiohttp-client. daytona still depends on it, so it remains in uv.lock for the sandbox extra. Anyone calling instrument_aiohttp_client themselves can install nemo-lens[aiohttp].
  • Docs: fern/versions/latest/pages/observability/configuration.mdx never listed the field or the variable, so it needs no change.
  • feat(telemetry): export per-server startup spans and metrics #4354: I trial-merged this branch with feat(telemetry): export per-server startup spans and metrics #4354, before the dependency change. There were no conflicts, and the telemetry tests passed on the result.

Validation

  • uv sync --extra dev --extra telemetry after the change: opentelemetry.instrumentation.aiohttp_client is no longer importable in the venv.
  • pytest -n 8 tests/unit_tests/telemetry tests/unit_tests/test_server_utils.py in that venv: passed. This includes the propagation tests, which check that traceparent is injected on outbound requests.
  • The new config test fails on main. There, the field is still declared and NEMO_GYM_OTEL_INSTRUMENT_AIOHTTP is exported.
  • grep of Gym and the installed nemo-lens package: the only reference to instrument_aiohttp_client is its definition in nemo/lens/contrib/aiohttp.py.
  • pre-commit run --files on the changed files: clean.

Rollout evidence

I ran example_single_tool_call with the simple agent and gpt-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 ran gym env start and then gym eval run --no-serve on the example data.

On the base commit, all four server venvs had opentelemetry-instrumentation-aiohttp-client installed. On this branch, none did. Each venv still had opentelemetry-instrumentation-fastapi.

Base commit This PR
Spans 238 238
Span types (name, kind, process) 49 49, identical set
Count of each span name identical
HTTP POST client spans 26 26
Traces 12 12
Traces that cross processes 4 4
Most processes in one trace 4 4
Server spans whose parent is a client span in another process 18 18
Rewards 0, 1, 1 0, 1, 1
  • All of Gym's spans are present in both runs: gym.rollout, gym.agent.responses, gym.model.responses and gym.verify. The FastAPI server spans are present on all four servers.
  • The last row shows that traceparent still joins each outbound request to the server span that handles it, without the aiohttp instrumentor installed.
  • Not covered by this run: sandbox spans, because this environment has no sandbox.

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]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

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]>
@ananthsub
ananthsub requested a review from a team as a code owner October 12, 2026 17:13
@ananthsub ananthsub changed the title fix(telemetry): remove the inert instrument_aiohttp setting fix(telemetry): remove the unused aiohttp client instrumentation Oct 12, 2026
@ananthsub

Copy link
Copy Markdown
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 ananthsub closed this Oct 12, 2026
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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant