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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yaol-0.2.0.tar.gz.
File metadata
- Download URL: yaol-0.2.0.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8da5f8719eec3b838ba7b756944e356c670fa5a4b10402b5a533eb118b3523cc
|
|
| MD5 |
a7815af0cc5ae14f2570fac333a907af
|
|
| BLAKE2b-256 |
8370d34cfe70e04cab62d3dba64e6d965e1736a9dbb733ca0a3050699f9654f8
|
File details
Details for the file yaol-0.2.0-py3-none-any.whl.
File metadata
- Download URL: yaol-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
750b8b4e848ffdf882a2cac530bcb9b9dd9c803a3da002265e0ebe2e5a9d8b62
|
|
| MD5 |
2f5256535d1996a9241eff2fa5fd2c66
|
|
| BLAKE2b-256 |
e77e8868e2c11397703d4f5521f321f81fd31058dfe4d1ced0532ba84a9a7df5
|