Skip to main content

yaol

Yet another observability library. Wires OpenTelemetry traces, metrics and logs plus structlog and Pyroscope profiling from a single config object.

Usage

from yaol import ObservabilityConfig, setup, shutdown, instrument_asyncpg

config = ObservabilityConfig(
    service_name="bot",
    service_version="0.1.7",
    environment="prod",
    otlp_endpoint="http://172.17.0.1:4317",
    logger_levels={"sqlalchemy.engine": "WARNING"},
)

setup(config)
instrument_asyncpg()
...
shutdown()

from_env builds the same object from environment variables: ENV, OTEL_EXPORTER_OTLP_ENDPOINT, LOG_LEVEL, YAOL_JSON_LOGS, YAOL_EXPORT_TRACES, YAOL_EXPORT_LOGS, YAOL_EXPORT_METRICS, YAOL_METRIC_INTERVAL_MILLIS, YAOL_PROFILING_ENABLED, PYROSCOPE_ADDRESS, PYROSCOPE_SAMPLE_RATE, YAOL_TRACE_SAMPLE_RATIO, YAOL_SPAN_QUEUE_SIZE, YAOL_SPAN_SCHEDULE_DELAY_MILLIS, YAOL_SPAN_EXPORT_BATCH_SIZE.

Keeping a trace whole

A trace is only useful if it survives the places where work is handed off. Three of those places need help.

Errors that are handled. A span that catches an exception ends with an OK status, so the backend shows a green trace for a failed request. SHARED_PROCESSORS mirrors every log.error/log.exception onto the active span as an exception event plus an ERROR status, which covers handled errors without touching the call sites. Use record_exception or fail where there is no log line:

from yaol import fail, record_exception, span

with span("chat.pipeline"):
    try:
        await run()
    except Exception as error:
        record_exception(error)  # span is now ERROR, with a stack trace
        await tell_the_user(error)

span() also records cancellation, which the SDK deliberately ignores — work killed by a timeout or a shutdown would otherwise export as a healthy span.

Deferred work. asyncio copies the caller's context into every task, so a task created inside a span adopts it permanently. Long-lived workers must start clean, and deferred work must resume the context it was scheduled from:

from yaol import capture, spawn

worker = spawn(run_forever())  # clean context, its own traces
later = spawn(handle(batch), context=ctx)  # continues the captured trace

capture() takes the snapshot at scheduling time, attached() resumes it, and detached() drops the ambient trace. When several traces converge on one unit of work, parent it to the first and pass the rest as links(contexts).

Service boundaries. Instrumented clients propagate the trace themselves — instrument_httpx() covers SDKs that build their own client, the OpenAI SDK among them — and instrument_fastapi(app) continues the caller's trace on the receiving side. inject_headers/extract_context cover hops nothing instruments.

Signals

  • Traces — OTLP gRPC, BatchSpanProcessor.
  • Metrics — OTLP gRPC, PeriodicExportingMetricReader.
  • Logs — OTLP gRPC alongside the stdout handler; both are attached to the root logger.
  • Profiles — Pyroscope push, off by default.

shutdown() flushes every provider, which the previous ad-hoc setup did not do.

Metadata

Release files for yaol 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yaol 0.2.1
File Size Uploaded
yaol-0.2.1.tar.gz 68.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yaol 0.2.1
File Interpreter ABI Platform
yaol-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 80.3 kB

Release files / yaol-0.2.1.tar.gz

Download URL yaol-0.2.1.tar.gz
Size 68.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0c97be92ece776e5ab65959bea25832015295d0b2c64ccca5a4b024ce98aaef9
BLAKE2b-256 checksum
How to use checksums
daf4cd5a630fc87c97a615ac0762a17d364a88619b3b41091c9a7f61c004325c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / yaol-0.2.1-py3-none-any.whl

Download URL yaol-0.2.1-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24176e3fef87c79446e83722579810a0c008c78aa264e1cf020b683039eede8a
BLAKE2b-256 checksum
How to use checksums
7b279ee9808ef406545df788ce0f0a9ed9cbe5f7505db3f071b11c9090428150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page