clabe.logging.otel ¶
AindOtelSettings ¶
Bases: OtelSettings
AIND log-schema profile: tags runs with the fields from log-schema.
Every field is optional and settable in clabe.yml. Fields left unset are auto-populated
at creation time where a default exists (hostname, rig_id, software_version);
subject_id and user_id stay None until the session is registered. Any field
can also be overridden at any time via clabe.logging.otel.enrich_attribute (this is also
how one-off attributes such as instrument_id are set — they have no dedicated field).
See https://github.com/AllenNeuralDynamics/log-schema for the field definitions.
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/settings.py
resolved_service_name ¶
resolved_service_name() -> str
Use the log-schema software_name as the "Service", falling back to service_name.
software_name is the producing application, which is exactly what service.name
should identify. It is also emitted as the explicit software_name attribute (see
initial_attributes) for log-schema consumers that key on that field by name.
Source code in src/clabe/logging/otel/_settings.py
initial_attributes ¶
Resolve the log-schema fields, applying auto-defaults to any left unset in config.
Source code in src/clabe/logging/otel/_settings.py
session_attributes ¶
Fill subject_id and user_id from the session (plus the base session name).
Source code in src/clabe/logging/otel/_settings.py
OtelSettings ¶
Bases: ServiceSettings
OpenTelemetry transport settings read from the otel section of clabe.yml.
The base class is backend-agnostic: it configures how telemetry is shipped and tags a run with only its name. A profile enriches the run with domain identity by overriding the two population hooks:
initial_attributes— values known at process start (config + auto-defaults).session_attributes— values derived from the session, once it is registered.
Both feed a single attribute bag that is stamped on every span and log. Attributes may
also be set at any time during a run via clabe.logging.otel.enrich_attribute.
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/settings.py
resolved_service_name ¶
resolved_service_name() -> str
The service.name resource attribute — the "Service" every span and log is tagged with.
initial_attributes ¶
Attributes known at process start: config values plus auto-resolved defaults.
This is stages 1 and 2 of population. Auto-defaults fill only fields left None in
config, so an explicit clabe.yml value is never overwritten. The base profile adds
nothing; keys whose resolved value is None are omitted.
Source code in src/clabe/logging/otel/_settings.py
session_attributes ¶
Attributes derived from the session, bound once the launcher registers it.
This is stage 3 of population and overrides any same-named value set earlier.
Source code in src/clabe/logging/otel/_settings.py
record_exception ¶
record_exception(exception: BaseException) -> None
Record an exception on the current span and mark it as failed.
Takes BaseException so interrupts (KeyboardInterrupt), which OTel's own span
handling skips, can be recorded as failures too.
Source code in src/clabe/logging/otel/_api.py
span ¶
Open a span nested under the current experiment trace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the span. |
required |
attributes
|
Attributes
|
Optional attributes set when the span starts. |
None
|
Yields:
| Type | Description |
|---|---|
Span
|
The started span, so callers can enrich it further. |
Source code in src/clabe/logging/otel/_api.py
run_span ¶
Instrument a launcher run: install telemetry if enabled, then open the root span.
Reads AindOtelSettings from clabe.yml. When enabled, the SDK is configured
before the span opens (so @runnable app spans nest under it) and the OTLP log bridge
is attached. The run's attribute bag is seeded from the profile's config-and-defaults
(initial_attributes) before the root span
starts, so the root span and every child carry it. Telemetry is best effort — a missing
SDK or bad config is logged and the run proceeds untraced. The span is ended and exported
on exit, before the caller's cleanup, so a caller that then blocks (or is killed) cannot
strand it; an atexit fallback covers orderly interpreter teardown that skips this
finally without replacing the host application's signal handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
launcher
|
Launcher
|
The launcher being instrumented. |
required |
experiment_name
|
str | None
|
Name of the workflow being run, used when
|
None
|
Yields:
| Type | Description |
|---|---|
Span
|
The root span for the run. |
Source code in src/clabe/logging/otel/__init__.py
bind_session ¶
Enrich the active run with the session identity, as soon as it is registered.
Called by the launcher from register_session, this is
the first point the session (subject, experimenter, ...) is known — stage 3 of attribute
population. A no-op outside a run or when telemetry is off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session model just registered with the launcher. |
required |
Source code in src/clabe/logging/otel/__init__.py
enrich_attribute ¶
enrich_attribute(name: str, value: AttributeValue) -> None
Set or override a single telemetry attribute at any point during a run.
Stage 4 of attribute population: the escape hatch for values that have no dedicated
config field (e.g. instrument_id) or that become known mid-run. The attribute is
added to the run's bag — so it appears on every subsequent span and log — and stamped on
the currently open root span immediately. A no-op outside a run or when telemetry is off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute key, emitted verbatim (use log-schema snake_case, e.g. |
required |
value
|
AttributeValue
|
The attribute value. |
required |