lens.state
Module-level span group state — importable anywhere without circular deps.
Holds a frozenset of enabled span groups so that any module can call
:func:is_span_group_enabled without importing the full nemo.lens package.
Two ways in, and the last one called wins:
-
:func:
set_span_group_specstores the raw user spec (e.g."default,step") and resolves it against :class:~nemo.lens.groups.SpanRegistry. It never raises: an entry naming nothing is warned about and kept pending, because this process’s registry is not the authority on a job-wide spec. Several processes in one job routinely share a spec while importing different libraries, so a name that resolves nowhere here may be perfectly valid next door.The spec is retained, so a library registering late still takes effect (:func:
refresh_enabled_span_groups) instead of silently emitting nothing. That path warns — seeSpanRegistry._warn_if_late. -
:func:
set_enabled_span_groupspins an explicit set and drops the spec, so a later registration cannot reopen it. This is how a disabled process stays disabled, and how a test enables exactly the groups it means to.
Before either is called every :func:is_span_group_enabled query returns
False.
Module Contents
Functions
Data
API
Warn about a spec that did not get the caller what they asked for.
Deliberately a warning and not an exception: see the module docstring. Carries what is registered, because that is what turns “I set SPAN_GROUPS and got nothing” into a diagnosis — either a typo, or a library this process never imported.
Everything reported comes from resolution, which was taken in a single registry hold. Building the message from a fresh query let a registration land in between, so a warning could call a group unresolved and also list it as registered.
The parts of a resolution the warning text depends on.
The groups currently enabled. Diagnostic; not for the hot path.
Return the current PP trace carrier, or None.
Return True if the named span group is currently enabled.
This is the primary check at every instrumentation site (~2ns overhead).
Returns False before any group has been enabled.
Spec entries that resolved to nothing. Diagnostic; not for the hot path.
Non-empty here is the usual explanation for “I set SPAN_GROUPS and got nothing”: either a typo, or a name belonging to a library this process never imported.
Re-resolve the stored spec. Called whenever the registry changes.
A no-op when the groups were pinned explicitly rather than from a spec.
Registration happens at import time, so the cost never lands on the hot
path — :func:is_span_group_enabled stays one frozenset membership test.
Pin the active span groups explicitly, discarding any stored spec.
Subsequent registrations will not change the set — use
:func:set_span_group_spec if you want it to track the registry.
Store the pipeline-parallel trace carrier for cross-stage linking.
Called from the training loop after :func:broadcast_trace_context.
Store the user’s span-group spec and resolve it against the registry.
Called from :func:~nemo.lens.handle.setup_telemetry. Never raises: an entry
that resolves to nothing is warned about and kept pending, because this
process’s registry is not the authority on a job-wide spec.