libo11y 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. libo11y-0.1.0/.gitignore +27 -0
  2. libo11y-0.1.0/CHANGELOG.md +26 -0
  3. libo11y-0.1.0/PKG-INFO +137 -0
  4. libo11y-0.1.0/README.md +97 -0
  5. libo11y-0.1.0/pyproject.toml +120 -0
  6. libo11y-0.1.0/src/libo11y/__init__.py +67 -0
  7. libo11y-0.1.0/src/libo11y/_internal/__init__.py +3 -0
  8. libo11y-0.1.0/src/libo11y/_internal/endpoint.py +421 -0
  9. libo11y-0.1.0/src/libo11y/_internal/env.py +103 -0
  10. libo11y-0.1.0/src/libo11y/_internal/exporters.py +278 -0
  11. libo11y-0.1.0/src/libo11y/_internal/http_common.py +269 -0
  12. libo11y-0.1.0/src/libo11y/_internal/identity.py +30 -0
  13. libo11y-0.1.0/src/libo11y/_internal/logging_handler.py +292 -0
  14. libo11y-0.1.0/src/libo11y/_internal/logs_bridge.py +174 -0
  15. libo11y-0.1.0/src/libo11y/_internal/metrics_bridge.py +337 -0
  16. libo11y-0.1.0/src/libo11y/_internal/pii.py +202 -0
  17. libo11y-0.1.0/src/libo11y/_internal/policy.py +267 -0
  18. libo11y-0.1.0/src/libo11y/_internal/propagators.py +88 -0
  19. libo11y-0.1.0/src/libo11y/_internal/resource.py +199 -0
  20. libo11y-0.1.0/src/libo11y/_internal/runtime_metrics.py +122 -0
  21. libo11y-0.1.0/src/libo11y/_internal/sqltext.py +441 -0
  22. libo11y-0.1.0/src/libo11y/_internal/trace_bridge.py +225 -0
  23. libo11y-0.1.0/src/libo11y/_internal/yamlv3.py +523 -0
  24. libo11y-0.1.0/src/libo11y/asgi.py +303 -0
  25. libo11y-0.1.0/src/libo11y/buildinfo.py +96 -0
  26. libo11y-0.1.0/src/libo11y/connect.py +546 -0
  27. libo11y-0.1.0/src/libo11y/dbapi.py +435 -0
  28. libo11y-0.1.0/src/libo11y/detached.py +330 -0
  29. libo11y-0.1.0/src/libo11y/errors.py +83 -0
  30. libo11y-0.1.0/src/libo11y/grpc.py +913 -0
  31. libo11y-0.1.0/src/libo11y/httpx.py +197 -0
  32. libo11y-0.1.0/src/libo11y/options.py +137 -0
  33. libo11y-0.1.0/src/libo11y/proc.py +122 -0
  34. libo11y-0.1.0/src/libo11y/py.typed +0 -0
  35. libo11y-0.1.0/src/libo11y/record.py +87 -0
  36. libo11y-0.1.0/src/libo11y/redact.py +267 -0
  37. libo11y-0.1.0/src/libo11y/requests.py +168 -0
  38. libo11y-0.1.0/src/libo11y/signals.py +102 -0
  39. libo11y-0.1.0/src/libo11y/spec/__init__.py +269 -0
  40. libo11y-0.1.0/src/libo11y/spec/_generated/__init__.py +3 -0
  41. libo11y-0.1.0/src/libo11y/spec/_generated/goprint.py +1430 -0
  42. libo11y-0.1.0/src/libo11y/spec/_generated/spec.py +246 -0
  43. libo11y-0.1.0/src/libo11y/spec/_generated/tables.py +784 -0
  44. libo11y-0.1.0/src/libo11y/spec/_goquote.py +44 -0
  45. libo11y-0.1.0/src/libo11y/spec/appregistry.py +524 -0
  46. libo11y-0.1.0/src/libo11y/telemetry.py +553 -0
  47. libo11y-0.1.0/src/libo11y/testing/__init__.py +19 -0
  48. libo11y-0.1.0/src/libo11y/testing/_pytest_plugin.py +20 -0
  49. libo11y-0.1.0/src/libo11y/testing/receivers.py +257 -0
  50. libo11y-0.1.0/src/libo11y/testing/recorder.py +337 -0
  51. libo11y-0.1.0/src/libo11y/wsgi.py +330 -0
@@ -0,0 +1,27 @@
1
+ # Build artifacts
2
+ bin/
3
+ dist/
4
+
5
+ # Test and coverage output
6
+ *.out
7
+ coverage.html
8
+
9
+ # Editor state
10
+ *.swp
11
+ .DS_Store
12
+
13
+ # Bun and Node dependencies
14
+ node_modules/
15
+
16
+ # Zig build outputs and fetched packages
17
+ .zig-cache/
18
+ zig-out/
19
+ zig-pkg/
20
+
21
+ # Python virtual environments, caches, and coverage
22
+ .venv/
23
+ __pycache__/
24
+ .pytest_cache/
25
+ .ruff_cache/
26
+ .coverage
27
+ .coverage.*
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to the Python `libo11y` package are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-11-27
11
+
12
+ ### Added
13
+
14
+ - Core SDK (`libo11y.setup`, `libo11y.init`, `Options`, `HERMETIC`, `Telemetry`, typed `O11yError` hierarchy) on `opentelemetry-sdk==1.45.*` for CPython 3.12, 3.13, and 3.14.
15
+ - Generated specification package (`libo11y.spec`) for spec 1.2.0, conformance vector implementations (`service.instance.id`, endpoint sanitization, HMAC-SHA256 PII tokens), and strict `yaml.v3`-compatible application attribute registry validator passing all 46 shared conformance cases.
16
+ - Unified key-based `SensitivityPolicy` across traces, metrics (pre-SDK `PolicyMeterProvider` with 2000-series cardinality caps and trace-based exemplars), logs (stdlib `logging.Handler` + isolated `_logs` bridge), and resources.
17
+ - Capture-time redaction types (`libo11y.redact.Secret`, `Masked`, `@redacted` dataclass decorator with definition-time tag validation).
18
+ - Bounded concurrent shutdown (`shutdown`, `ashutdown`, `shutdown_on_signals`, `ashutdown_on_signals`), startup canary + `effective_config()`, `event()` / `Record` wide events, `libo11y.buildinfo` CLI/reader, and zero-dependency CPython/process runtime metrics.
19
+ - Testing harness (`libo11y.testing`): hermetic `Recorder`, `assert_conforms()`, in-process `OTLPHTTPReceiver` and `OTLPGRPCReceiver`, `o11y_recorder` pytest plugin fixture, and parity suite.
20
+ - Detached and process propagation (`libo11y.detached` `Carrier`, `capture`, `start_linked`, `copy_context`; `libo11y.proc` `TRACEPARENT`/`TRACESTATE` env carriers and framed map helpers).
21
+ - HTTP integrations: `libo11y.asgi` (Starlette, FastAPI, Django), `libo11y.wsgi` (Flask, Django), `libo11y.httpx` (`SyncTransport`, `AsyncTransport`), and `libo11y.requests` (`HTTPAdapter`, `mount` without global patching).
22
+ - RPC integrations: `libo11y.grpc` (sync and `grpc.aio` server/client interceptors) and `libo11y.connect` (`connectrpc` async/sync interceptors with canonical log lines).
23
+ - Database integration: `libo11y.dbapi` DB-API 2 connection/cursor wrapper with parent-gated client spans, SQL literal sanitization for PostgreSQL/SQLite/MySQL/MariaDB, `db.client.operation.duration` with exemplars, and `psycopg_pool` connection pool metrics.
24
+
25
+ [Unreleased]: https://github.com/jamesainslie/libo11y/compare/python/v0.1.0...HEAD
26
+ [0.1.0]: https://github.com/jamesainslie/libo11y/releases/tag/python/v0.1.0
libo11y-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.5
2
+ Name: libo11y
3
+ Version: 0.1.0
4
+ Summary: Opinionated, elegant observability for Python built purely on OpenTelemetry.
5
+ Project-URL: Homepage, https://o11y.ing
6
+ Project-URL: Repository, https://github.com/jamesainslie/libo11y
7
+ Project-URL: Documentation, https://o11y.ing/docs/
8
+ Author: James Ainslie
9
+ License-Expression: Apache-2.0
10
+ Keywords: logging,metrics,observability,opentelemetry,otlp,telemetry,tracing
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: opentelemetry-api==1.45.*
22
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http==1.45.*
23
+ Requires-Dist: opentelemetry-sdk==1.45.*
24
+ Requires-Dist: pyyaml>=6.0.2
25
+ Provides-Extra: connect
26
+ Requires-Dist: connectrpc>=0.13.0; extra == 'connect'
27
+ Provides-Extra: grpc
28
+ Requires-Dist: grpcio>=1.75.1; extra == 'grpc'
29
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc==1.45.*; extra == 'grpc'
30
+ Provides-Extra: httpx
31
+ Requires-Dist: httpx>=0.28; extra == 'httpx'
32
+ Provides-Extra: psycopg
33
+ Requires-Dist: psycopg-pool>=3.2; extra == 'psycopg'
34
+ Requires-Dist: psycopg>=3.2; extra == 'psycopg'
35
+ Provides-Extra: requests
36
+ Requires-Dist: requests>=2.32; extra == 'requests'
37
+ Provides-Extra: test
38
+ Requires-Dist: pytest>=8.3; extra == 'test'
39
+ Description-Content-Type: text/markdown
40
+
41
+ # libo11y (Python)
42
+
43
+ Opinionated, elegant observability for Python built purely on OpenTelemetry (`opentelemetry-sdk==1.45.*`). Requires CPython 3.12, 3.13, or 3.14.
44
+
45
+ One PyPI distribution (`libo11y`) ships the core SDK, generated specification tables, sensitivity policy, redaction helpers, detached/process propagation, and ASGI/WSGI/SQLite instrumentation. Optional third-party integrations install as extras.
46
+
47
+ ## Installation
48
+
49
+ ```sh
50
+ pip install libo11y # core, logging, asgi, wsgi, sqlite3 dbapi, detached, proc, redact, spec
51
+ pip install "libo11y[httpx]" # sync and async httpx transports
52
+ pip install "libo11y[requests]" # requests.HTTPAdapter (no global patching)
53
+ pip install "libo11y[grpc]" # grpcio sync/aio interceptors + OTLP/gRPC exporter
54
+ pip install "libo11y[connect]" # connectrpc async/sync interceptors
55
+ pip install "libo11y[psycopg]" # psycopg 3 + psycopg_pool metrics
56
+ pip install "libo11y[test]" # pytest plugin (o11y_recorder fixture) + in-process OTLP receivers
57
+ ```
58
+
59
+ With `uv`:
60
+
61
+ ```sh
62
+ uv add libo11y
63
+ ```
64
+
65
+ ## Quick start
66
+
67
+ ```python
68
+ import logging
69
+ from opentelemetry import trace
70
+ import libo11y
71
+ from libo11y.spec import Environment
72
+
73
+ with libo11y.setup(
74
+ service_name="checkout",
75
+ version="1.2.0",
76
+ environment=Environment.PRODUCTION,
77
+ ) as tel:
78
+ tracer = trace.get_tracer("checkout")
79
+ logger = logging.getLogger("checkout")
80
+ with tracer.start_as_current_span("startup"):
81
+ logger.info("ready", extra={"checkout.items": 3}) # correlated with the span
82
+ ```
83
+
84
+ `setup()` installs the tracer, meter, and logger providers globally, wires a structured `logging.Handler` on the root logger (JSON console + OTLP log export), installs the W3C TraceContext + Baggage propagator wrapped in the baggage egress filter, and runs the startup canary (`o11y.telemetry.configured`). Leaving the `with` block runs bounded concurrent shutdown across all three signals.
85
+
86
+ For explicit non-global SDKs (tests, multi-tenant processes, embedded libraries), use `libo11y.init(...)` instead: it installs no globals, runs no canary, and exposes `tel.tracer_provider`, `tel.meter_provider`, `tel.logger_provider`, `tel.propagator`, and `tel.logging_handler()`.
87
+
88
+ ### Graceful shutdown on signals
89
+
90
+ ```python
91
+ report = libo11y.shutdown_on_signals(tel, before_shutdown=server.stop)
92
+ # Or inside asyncio:
93
+ report = await libo11y.ashutdown_on_signals(tel, before_shutdown=server.aclose)
94
+ ```
95
+
96
+ ### Build info
97
+
98
+ Python packages carry no embedded VCS revision. Capture git metadata at image build time:
99
+
100
+ ```sh
101
+ python -m libo11y.buildinfo buildinfo.json
102
+ ```
103
+
104
+ Then pass `build_info="buildinfo.json"` (or `distribution="my-package"` to read `service.version` from `importlib.metadata`) to `setup()` / `init()`.
105
+
106
+ ## Integrations
107
+
108
+ | Module | Extra | Notes |
109
+ |---|---|---|
110
+ | `libo11y.asgi` | none | ASGI 3 middleware; route templates for Starlette, FastAPI, Django; `http.server.request.duration` with exemplars; `public_endpoint`, `ignore_paths`, `filter`, `canonical_line`, `server_timing` |
111
+ | `libo11y.wsgi` | none | WSGI middleware; route templates for Flask and Django; same feature set |
112
+ | `libo11y.httpx` | `httpx` | `SyncTransport` / `AsyncTransport` wrapping inner transports; `http.client.request.duration` with exemplars; strips URL credentials |
113
+ | `libo11y.requests` | `requests` | `HTTPAdapter` / `mount(session)`; never patches `requests` globally so OTLP/HTTP export is never instrumented |
114
+ | `libo11y.grpc` | `grpc` | Sync and `grpc.aio` server/client interceptors; `rpc.server.duration`, `rpc.client.duration`, `public_endpoint`, `ignore_health_checks` |
115
+ | `libo11y.connect` | `connect` | Async and sync `connectrpc` interceptors (`MetadataInterceptor`); canonical log line matching `go/o11yconnect` |
116
+ | `libo11y.dbapi` | none / `psycopg` | DB-API 2 connection/cursor wrapper; client spans only under an active parent span; SQL literal sanitization for PostgreSQL, SQLite, MySQL, MariaDB; `db.client.operation.duration` with exemplars; `register_pool_metrics` for `psycopg_pool` |
117
+ | `libo11y.detached` | none | `copy_context`, 32 KiB text `Carrier`, `capture`, `start_linked` |
118
+ | `libo11y.proc` | none | `TRACEPARENT`/`TRACESTATE` env carriers (never baggage) and framed map inject/extract |
119
+ | `libo11y.redact` | none | `Secret[T]`, `Masked[T]`, `@redacted` dataclass decorator (unknown `Annotated` tags fail at class definition time with `TypeError`) |
120
+ | `libo11y.testing` | `test` | Hermetic `Recorder`, `o11y_recorder` pytest fixture, `assert_conforms()`, in-process `OTLPHTTPReceiver` and `OTLPGRPCReceiver` |
121
+
122
+ ## Per-signal guarantees
123
+
124
+ - **Traces:** `SensitivityPolicy` wraps the span exporter to classify span, event, and link attributes before leaving the process. Secret attributes are always dropped; PII is dropped by default, HMAC-SHA256 tokenized under `PIIMode.HASH` (key >= 32 bytes), or kept under `PIIMode.KEEP`.
125
+ - **Metrics:** `PolicyMeterProvider` classifies attributes before SDK recording (covering derived Views and exemplars). PII is always dropped on metrics even under `PIIMode.HASH`. Per-instrument cardinality is capped at 2000 series. Trace-based exemplars are enabled by default.
126
+ - **Logs:** Standard `logging` records pass through the user `attr_replacer` and then `SensitivityPolicy` on both console and OTLP legs, with nested walk depth limit 16, cycle detection, and 2048-node budget failing closed. Direct OTel `_logs` API records are classified by `PolicyLogRecordProcessor`.
127
+ - **Resource:** Classified once at construction against the same policy. Tier-0 identity (`service.name`, `deployment.environment.name`, `service.version`, `service.instance.id`) and `spec.SCHEMA_URL` are stamped on the resource.
128
+ - **Runtime metrics:** On by default (`runtime_metrics=False` disables). Reports `cpython.gc.*` and `process.*` (`cpu.time`, `memory.usage`, `thread.count`, `unix.file_descriptor.count`) using only stdlib (`gc`, `resource`, `threading`, `/proc`).
129
+
130
+ ## Documented gaps and caveats
131
+
132
+ - **Policy scope (shared with Go, TypeScript, and Zig):** Key-based classification does not inspect log message bodies, span names, span status descriptions, span event names, instrumentation scope attributes, map-valued members on spans/metrics, attributes read at `on_start`, or baggage. Use `libo11y.redact` (`Secret`, `Masked`, `@redacted`) for capture-time protection of sensitive values under unclassified keys.
133
+ - **Shutdown threads past deadline:** Python cannot cancel a blocked OS thread. If a signal exporter misses the `shutdown_timeout` (default 5 seconds), `shutdown()` returns immediately with a timeout error in `ShutdownReport` while the flush continues on a daemon thread (the interpreter exits without waiting for it).
134
+ - **Hermetic mode upstream SDK reads:** Passing `env=libo11y.HERMETIC` passes every configurable setting explicitly so ambient `OTEL_*` variables cannot leak into tests. Two reads inside `opentelemetry-sdk==1.45.*` cannot be overridden via arguments:
135
+ 1. `LoggerProvider` reads `OTEL_SDK_DISABLED`; a hermetic SDK detects if `OTEL_SDK_DISABLED=true` disabled its logger provider and raises `O11yError` rather than silently dropping logs.
136
+ 2. OTLP exporters read `OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED`, which only adds SDK self-metrics and changes no application telemetry.
137
+ - **Private logs SDK:** `opentelemetry.sdk._logs` is private in OTel Python 1.45.x. All usage is isolated behind `libo11y._internal.logs_bridge` and `opentelemetry-sdk` is pinned to `==1.45.*`.
@@ -0,0 +1,97 @@
1
+ # libo11y (Python)
2
+
3
+ Opinionated, elegant observability for Python built purely on OpenTelemetry (`opentelemetry-sdk==1.45.*`). Requires CPython 3.12, 3.13, or 3.14.
4
+
5
+ One PyPI distribution (`libo11y`) ships the core SDK, generated specification tables, sensitivity policy, redaction helpers, detached/process propagation, and ASGI/WSGI/SQLite instrumentation. Optional third-party integrations install as extras.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pip install libo11y # core, logging, asgi, wsgi, sqlite3 dbapi, detached, proc, redact, spec
11
+ pip install "libo11y[httpx]" # sync and async httpx transports
12
+ pip install "libo11y[requests]" # requests.HTTPAdapter (no global patching)
13
+ pip install "libo11y[grpc]" # grpcio sync/aio interceptors + OTLP/gRPC exporter
14
+ pip install "libo11y[connect]" # connectrpc async/sync interceptors
15
+ pip install "libo11y[psycopg]" # psycopg 3 + psycopg_pool metrics
16
+ pip install "libo11y[test]" # pytest plugin (o11y_recorder fixture) + in-process OTLP receivers
17
+ ```
18
+
19
+ With `uv`:
20
+
21
+ ```sh
22
+ uv add libo11y
23
+ ```
24
+
25
+ ## Quick start
26
+
27
+ ```python
28
+ import logging
29
+ from opentelemetry import trace
30
+ import libo11y
31
+ from libo11y.spec import Environment
32
+
33
+ with libo11y.setup(
34
+ service_name="checkout",
35
+ version="1.2.0",
36
+ environment=Environment.PRODUCTION,
37
+ ) as tel:
38
+ tracer = trace.get_tracer("checkout")
39
+ logger = logging.getLogger("checkout")
40
+ with tracer.start_as_current_span("startup"):
41
+ logger.info("ready", extra={"checkout.items": 3}) # correlated with the span
42
+ ```
43
+
44
+ `setup()` installs the tracer, meter, and logger providers globally, wires a structured `logging.Handler` on the root logger (JSON console + OTLP log export), installs the W3C TraceContext + Baggage propagator wrapped in the baggage egress filter, and runs the startup canary (`o11y.telemetry.configured`). Leaving the `with` block runs bounded concurrent shutdown across all three signals.
45
+
46
+ For explicit non-global SDKs (tests, multi-tenant processes, embedded libraries), use `libo11y.init(...)` instead: it installs no globals, runs no canary, and exposes `tel.tracer_provider`, `tel.meter_provider`, `tel.logger_provider`, `tel.propagator`, and `tel.logging_handler()`.
47
+
48
+ ### Graceful shutdown on signals
49
+
50
+ ```python
51
+ report = libo11y.shutdown_on_signals(tel, before_shutdown=server.stop)
52
+ # Or inside asyncio:
53
+ report = await libo11y.ashutdown_on_signals(tel, before_shutdown=server.aclose)
54
+ ```
55
+
56
+ ### Build info
57
+
58
+ Python packages carry no embedded VCS revision. Capture git metadata at image build time:
59
+
60
+ ```sh
61
+ python -m libo11y.buildinfo buildinfo.json
62
+ ```
63
+
64
+ Then pass `build_info="buildinfo.json"` (or `distribution="my-package"` to read `service.version` from `importlib.metadata`) to `setup()` / `init()`.
65
+
66
+ ## Integrations
67
+
68
+ | Module | Extra | Notes |
69
+ |---|---|---|
70
+ | `libo11y.asgi` | none | ASGI 3 middleware; route templates for Starlette, FastAPI, Django; `http.server.request.duration` with exemplars; `public_endpoint`, `ignore_paths`, `filter`, `canonical_line`, `server_timing` |
71
+ | `libo11y.wsgi` | none | WSGI middleware; route templates for Flask and Django; same feature set |
72
+ | `libo11y.httpx` | `httpx` | `SyncTransport` / `AsyncTransport` wrapping inner transports; `http.client.request.duration` with exemplars; strips URL credentials |
73
+ | `libo11y.requests` | `requests` | `HTTPAdapter` / `mount(session)`; never patches `requests` globally so OTLP/HTTP export is never instrumented |
74
+ | `libo11y.grpc` | `grpc` | Sync and `grpc.aio` server/client interceptors; `rpc.server.duration`, `rpc.client.duration`, `public_endpoint`, `ignore_health_checks` |
75
+ | `libo11y.connect` | `connect` | Async and sync `connectrpc` interceptors (`MetadataInterceptor`); canonical log line matching `go/o11yconnect` |
76
+ | `libo11y.dbapi` | none / `psycopg` | DB-API 2 connection/cursor wrapper; client spans only under an active parent span; SQL literal sanitization for PostgreSQL, SQLite, MySQL, MariaDB; `db.client.operation.duration` with exemplars; `register_pool_metrics` for `psycopg_pool` |
77
+ | `libo11y.detached` | none | `copy_context`, 32 KiB text `Carrier`, `capture`, `start_linked` |
78
+ | `libo11y.proc` | none | `TRACEPARENT`/`TRACESTATE` env carriers (never baggage) and framed map inject/extract |
79
+ | `libo11y.redact` | none | `Secret[T]`, `Masked[T]`, `@redacted` dataclass decorator (unknown `Annotated` tags fail at class definition time with `TypeError`) |
80
+ | `libo11y.testing` | `test` | Hermetic `Recorder`, `o11y_recorder` pytest fixture, `assert_conforms()`, in-process `OTLPHTTPReceiver` and `OTLPGRPCReceiver` |
81
+
82
+ ## Per-signal guarantees
83
+
84
+ - **Traces:** `SensitivityPolicy` wraps the span exporter to classify span, event, and link attributes before leaving the process. Secret attributes are always dropped; PII is dropped by default, HMAC-SHA256 tokenized under `PIIMode.HASH` (key >= 32 bytes), or kept under `PIIMode.KEEP`.
85
+ - **Metrics:** `PolicyMeterProvider` classifies attributes before SDK recording (covering derived Views and exemplars). PII is always dropped on metrics even under `PIIMode.HASH`. Per-instrument cardinality is capped at 2000 series. Trace-based exemplars are enabled by default.
86
+ - **Logs:** Standard `logging` records pass through the user `attr_replacer` and then `SensitivityPolicy` on both console and OTLP legs, with nested walk depth limit 16, cycle detection, and 2048-node budget failing closed. Direct OTel `_logs` API records are classified by `PolicyLogRecordProcessor`.
87
+ - **Resource:** Classified once at construction against the same policy. Tier-0 identity (`service.name`, `deployment.environment.name`, `service.version`, `service.instance.id`) and `spec.SCHEMA_URL` are stamped on the resource.
88
+ - **Runtime metrics:** On by default (`runtime_metrics=False` disables). Reports `cpython.gc.*` and `process.*` (`cpu.time`, `memory.usage`, `thread.count`, `unix.file_descriptor.count`) using only stdlib (`gc`, `resource`, `threading`, `/proc`).
89
+
90
+ ## Documented gaps and caveats
91
+
92
+ - **Policy scope (shared with Go, TypeScript, and Zig):** Key-based classification does not inspect log message bodies, span names, span status descriptions, span event names, instrumentation scope attributes, map-valued members on spans/metrics, attributes read at `on_start`, or baggage. Use `libo11y.redact` (`Secret`, `Masked`, `@redacted`) for capture-time protection of sensitive values under unclassified keys.
93
+ - **Shutdown threads past deadline:** Python cannot cancel a blocked OS thread. If a signal exporter misses the `shutdown_timeout` (default 5 seconds), `shutdown()` returns immediately with a timeout error in `ShutdownReport` while the flush continues on a daemon thread (the interpreter exits without waiting for it).
94
+ - **Hermetic mode upstream SDK reads:** Passing `env=libo11y.HERMETIC` passes every configurable setting explicitly so ambient `OTEL_*` variables cannot leak into tests. Two reads inside `opentelemetry-sdk==1.45.*` cannot be overridden via arguments:
95
+ 1. `LoggerProvider` reads `OTEL_SDK_DISABLED`; a hermetic SDK detects if `OTEL_SDK_DISABLED=true` disabled its logger provider and raises `O11yError` rather than silently dropping logs.
96
+ 2. OTLP exporters read `OTEL_PYTHON_SDK_INTERNAL_METRICS_ENABLED`, which only adds SDK self-metrics and changes no application telemetry.
97
+ - **Private logs SDK:** `opentelemetry.sdk._logs` is private in OTel Python 1.45.x. All usage is isolated behind `libo11y._internal.logs_bridge` and `opentelemetry-sdk` is pinned to `==1.45.*`.
@@ -0,0 +1,120 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "libo11y"
7
+ version = "0.1.0"
8
+ description = "Opinionated, elegant observability for Python built purely on OpenTelemetry."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.12"
12
+ authors = [{ name = "James Ainslie" }]
13
+ keywords = ["opentelemetry", "observability", "telemetry", "otlp", "logging", "tracing", "metrics"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Typing :: Typed",
24
+ ]
25
+ dependencies = [
26
+ "opentelemetry-api==1.45.*",
27
+ "opentelemetry-sdk==1.45.*",
28
+ "opentelemetry-exporter-otlp-proto-http==1.45.*",
29
+ "PyYAML>=6.0.2",
30
+ ]
31
+
32
+ [project.urls]
33
+ Homepage = "https://o11y.ing"
34
+ Repository = "https://github.com/jamesainslie/libo11y"
35
+ Documentation = "https://o11y.ing/docs/"
36
+
37
+ [project.entry-points.pytest11]
38
+ libo11y = "libo11y.testing._pytest_plugin"
39
+
40
+ [project.optional-dependencies]
41
+ test = [
42
+ "pytest>=8.3",
43
+ ]
44
+ httpx = [
45
+ "httpx>=0.28",
46
+ ]
47
+ requests = [
48
+ "requests>=2.32",
49
+ ]
50
+ grpc = [
51
+ "grpcio>=1.75.1",
52
+ "opentelemetry-exporter-otlp-proto-grpc==1.45.*",
53
+ ]
54
+ connect = [
55
+ "connectrpc>=0.13.0",
56
+ ]
57
+ psycopg = [
58
+ "psycopg>=3.2",
59
+ "psycopg-pool>=3.2",
60
+ ]
61
+
62
+ [dependency-groups]
63
+ dev = [
64
+ "pytest>=8.3",
65
+ "pytest-asyncio>=0.25",
66
+ "pytest-cov>=6.0",
67
+ "pytest-xdist>=3.6",
68
+ "hypothesis>=6.120",
69
+ "ruff>=0.15.14",
70
+ "pyright>=1.1.400",
71
+ "types-PyYAML>=6.0.12",
72
+ "types-requests>=2.32",
73
+ "starlette>=0.40",
74
+ "fastapi>=0.115",
75
+ "flask>=3.1",
76
+ "django>=5.1",
77
+ "psycopg[binary]>=3.2",
78
+ ]
79
+
80
+ [tool.hatch.build.targets.wheel]
81
+ packages = ["src/libo11y"]
82
+
83
+ [tool.hatch.build.targets.sdist]
84
+ include = [
85
+ "src/libo11y",
86
+ "README.md",
87
+ "CHANGELOG.md",
88
+ "pyproject.toml",
89
+ ]
90
+
91
+ [tool.ruff]
92
+ target-version = "py312"
93
+ line-length = 100
94
+ src = ["src", "tests"]
95
+
96
+ [tool.ruff.lint]
97
+ select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "W", "N", "T20"]
98
+
99
+ [tool.ruff.lint.per-file-ignores]
100
+ "tests/**" = ["T20"]
101
+
102
+ [tool.pyright]
103
+ pythonVersion = "3.12"
104
+ typeCheckingMode = "strict"
105
+ include = ["src", "tests"]
106
+ venvPath = "."
107
+ venv = ".venv"
108
+
109
+ [tool.pytest.ini_options]
110
+ testpaths = ["tests"]
111
+ asyncio_mode = "auto"
112
+ asyncio_default_fixture_loop_scope = "function"
113
+ addopts = "--strict-markers --strict-config"
114
+
115
+ [tool.coverage.run]
116
+ branch = true
117
+ source = ["libo11y"]
118
+
119
+ [tool.coverage.report]
120
+ show_missing = true
@@ -0,0 +1,67 @@
1
+ """Opinionated, elegant observability for Python built purely on OpenTelemetry."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from libo11y import buildinfo, detached, proc, redact, spec
6
+ from libo11y._internal.logging_handler import force_emit
7
+ from libo11y.errors import (
8
+ AlreadySetup,
9
+ CanaryRejected,
10
+ ExporterError,
11
+ InvalidAppRegistry,
12
+ InvalidCarrier,
13
+ InvalidEnvironment,
14
+ NoEnvironment,
15
+ NoServiceName,
16
+ O11yError,
17
+ PIIHashKey,
18
+ UnsupportedProtocol,
19
+ )
20
+ from libo11y.options import (
21
+ HERMETIC,
22
+ AttrReplacer,
23
+ BaggagePredicate,
24
+ ConsoleFormat,
25
+ ErrorHandler,
26
+ Options,
27
+ PIIMode,
28
+ )
29
+ from libo11y.record import Record, current_record, start_record
30
+ from libo11y.signals import ashutdown_on_signals, shutdown_on_signals
31
+ from libo11y.telemetry import ShutdownReport, Telemetry, init, setup
32
+
33
+ __all__ = [
34
+ "HERMETIC",
35
+ "AlreadySetup",
36
+ "AttrReplacer",
37
+ "BaggagePredicate",
38
+ "CanaryRejected",
39
+ "ConsoleFormat",
40
+ "ErrorHandler",
41
+ "ExporterError",
42
+ "InvalidAppRegistry",
43
+ "InvalidCarrier",
44
+ "InvalidEnvironment",
45
+ "NoEnvironment",
46
+ "NoServiceName",
47
+ "O11yError",
48
+ "Options",
49
+ "PIIHashKey",
50
+ "PIIMode",
51
+ "Record",
52
+ "ShutdownReport",
53
+ "Telemetry",
54
+ "UnsupportedProtocol",
55
+ "ashutdown_on_signals",
56
+ "buildinfo",
57
+ "current_record",
58
+ "detached",
59
+ "force_emit",
60
+ "init",
61
+ "proc",
62
+ "redact",
63
+ "setup",
64
+ "shutdown_on_signals",
65
+ "spec",
66
+ "start_record",
67
+ ]
@@ -0,0 +1,3 @@
1
+ """Internal implementation modules for libo11y (not public API)."""
2
+
3
+ from __future__ import annotations