fastapi-observer 1.2.0__tar.gz → 1.3.1__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.
- fastapi_observer-1.3.1/PKG-INFO +248 -0
- fastapi_observer-1.3.1/README.md +172 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/pyproject.toml +5 -0
- fastapi_observer-1.3.1/src/fastapi_observer.egg-info/PKG-INFO +248 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapi_observer.egg-info/SOURCES.txt +3 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/__init__.py +2 -1
- fastapi_observer-1.3.1/src/fastapiobserver/_version.py +1 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/fastapi.py +128 -16
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/endpoint.py +5 -1
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/prometheus/multiprocess.py +30 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/metrics.py +14 -2
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/request_logging.py +1 -0
- fastapi_observer-1.3.1/src/fastapiobserver/profiles.py +57 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_fastapi_install.py +130 -1
- fastapi_observer-1.3.1/tests/test_lifespan_teardown.py +53 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_metrics_contracts.py +71 -0
- fastapi_observer-1.3.1/tests/test_profiles.py +124 -0
- fastapi_observer-1.2.0/PKG-INFO +0 -1235
- fastapi_observer-1.2.0/README.md +0 -1159
- fastapi_observer-1.2.0/src/fastapi_observer.egg-info/PKG-INFO +0 -1235
- fastapi_observer-1.2.0/src/fastapiobserver/_version.py +0 -1
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/LICENSE +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/setup.cfg +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapi_observer.egg-info/dependency_links.txt +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapi_observer.egg-info/requires.txt +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapi_observer.egg-info/top_level.txt +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/audit/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/audit/formatter.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/audit/providers.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/audit/verify.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/config.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/control_plane.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/db_tracing.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/integrations/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/integrations/strawberry.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/circuit_breaker.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/filters.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/formatter.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/queueing.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/setup.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/logging/state.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/loguru.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/builder.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/contracts.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/noop.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/pathing.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/prometheus/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/prometheus/backend.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/prometheus/client.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/prometheus/collector.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/prometheus/exemplars.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/metrics/registry.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/body_capture.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/context.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/events.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/headers.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/ip.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/middleware/span_errors.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/lifecycle.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/logs.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/metrics.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/resource.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/settings.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/tracing.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/otel/types.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/plugins.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/propagation.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/py.typed +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/request_context.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/security/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/security/normalize.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/security/policy.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/security/proxies.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/security/redaction.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/builtin.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/discovery.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/factory.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/logtail/__init__.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/logtail/dlq.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/logtail/handler.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/logtail/sink.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/protocol.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/registry.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/sinks/stats.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/src/fastapiobserver/utils.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_audit_chain.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_body_media_allowlist.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_config_settings.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_db_tracing.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_dx_parity.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_excluded_url_precedence.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_graphql_integrations.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_log_queue_controls.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_logging_schema_contract.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_logtail_dlq.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_loguru_bridge.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_metrics_optional_dependency.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_middleware.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_negotiate_content_type.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otel_integration.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otel_lifecycle.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otel_log_correlation.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otel_logs_from_env.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otel_logs_pipeline.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otel_metrics_from_env.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_otlp_export_integration.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_plugin_isolation.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_propagation.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_redaction_presets.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_route_template_cardinality.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_runtime_control_auth.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_security_audit_fixes.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_security_redaction.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_sink_circuit_breaker.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_sinks.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_trust_boundary.py +0 -0
- {fastapi_observer-1.2.0 → fastapi_observer-1.3.1}/tests/test_utils_refactors.py +0 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-observer
|
|
3
|
+
Version: 1.3.1
|
|
4
|
+
Summary: Zero-glue FastAPI observability with security presets and runtime controls
|
|
5
|
+
Author-email: Vitaee <opensource@vitaee.dev>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Vitaee/FastapiObserver
|
|
8
|
+
Project-URL: Documentation, https://github.com/Vitaee/FastapiObserver#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/Vitaee/FastapiObserver.git
|
|
10
|
+
Project-URL: Issues, https://github.com/Vitaee/FastapiObserver/issues
|
|
11
|
+
Project-URL: Funding, https://buymeacoffee.com/FYbPCSu
|
|
12
|
+
Keywords: fastapi,observability,logging,metrics,opentelemetry
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Framework :: FastAPI
|
|
23
|
+
Classifier: Topic :: System :: Logging
|
|
24
|
+
Classifier: Topic :: System :: Monitoring
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: <3.15,>=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: fastapi>=0.129.0
|
|
30
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
|
31
|
+
Requires-Dist: starlette>=0.52.1
|
|
32
|
+
Provides-Extra: fast-json
|
|
33
|
+
Requires-Dist: orjson>=3.11.7; extra == "fast-json"
|
|
34
|
+
Provides-Extra: prometheus
|
|
35
|
+
Requires-Dist: prometheus-client>=0.24.1; extra == "prometheus"
|
|
36
|
+
Provides-Extra: loguru
|
|
37
|
+
Requires-Dist: loguru>=0.7.2; extra == "loguru"
|
|
38
|
+
Provides-Extra: otel
|
|
39
|
+
Requires-Dist: opentelemetry-api>=1.39.1; extra == "otel"
|
|
40
|
+
Requires-Dist: opentelemetry-sdk>=1.39.1; extra == "otel"
|
|
41
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.39.1; extra == "otel"
|
|
42
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.60b1; extra == "otel"
|
|
43
|
+
Requires-Dist: opentelemetry-instrumentation-logging>=0.60b1; extra == "otel"
|
|
44
|
+
Provides-Extra: otel-httpx
|
|
45
|
+
Requires-Dist: opentelemetry-instrumentation-httpx>=0.60b1; extra == "otel-httpx"
|
|
46
|
+
Provides-Extra: otel-requests
|
|
47
|
+
Requires-Dist: opentelemetry-instrumentation-requests>=0.60b1; extra == "otel-requests"
|
|
48
|
+
Provides-Extra: audit
|
|
49
|
+
Requires-Dist: cryptography>=46.0.5; extra == "audit"
|
|
50
|
+
Provides-Extra: otel-sqlalchemy
|
|
51
|
+
Requires-Dist: opentelemetry-instrumentation-sqlalchemy>=0.60b1; extra == "otel-sqlalchemy"
|
|
52
|
+
Provides-Extra: all
|
|
53
|
+
Requires-Dist: orjson>=3.11.7; extra == "all"
|
|
54
|
+
Requires-Dist: prometheus-client>=0.24.1; extra == "all"
|
|
55
|
+
Requires-Dist: loguru>=0.7.2; extra == "all"
|
|
56
|
+
Requires-Dist: opentelemetry-api>=1.39.1; extra == "all"
|
|
57
|
+
Requires-Dist: opentelemetry-sdk>=1.39.1; extra == "all"
|
|
58
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.39.1; extra == "all"
|
|
59
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.60b1; extra == "all"
|
|
60
|
+
Requires-Dist: opentelemetry-instrumentation-logging>=0.60b1; extra == "all"
|
|
61
|
+
Requires-Dist: opentelemetry-instrumentation-httpx>=0.60b1; extra == "all"
|
|
62
|
+
Requires-Dist: opentelemetry-instrumentation-requests>=0.60b1; extra == "all"
|
|
63
|
+
Requires-Dist: opentelemetry-instrumentation-sqlalchemy>=0.60b1; extra == "all"
|
|
64
|
+
Requires-Dist: cryptography>=46.0.5; extra == "all"
|
|
65
|
+
Provides-Extra: dev
|
|
66
|
+
Requires-Dist: httpx>=0.28.1; extra == "dev"
|
|
67
|
+
Requires-Dist: loguru>=0.7.2; extra == "dev"
|
|
68
|
+
Requires-Dist: mypy>=1.19.1; extra == "dev"
|
|
69
|
+
Requires-Dist: pip-audit>=2.10.0; extra == "dev"
|
|
70
|
+
Requires-Dist: pytest>=9.0.2; extra == "dev"
|
|
71
|
+
Requires-Dist: pytest-randomly>=3.16.0; extra == "dev"
|
|
72
|
+
Requires-Dist: ruff>=0.15.1; extra == "dev"
|
|
73
|
+
Requires-Dist: cyclonedx-bom>=7.2.1; extra == "dev"
|
|
74
|
+
Requires-Dist: uvicorn>=0.30.0; extra == "dev"
|
|
75
|
+
Dynamic: license-file
|
|
76
|
+
|
|
77
|
+
# fastapi-observer
|
|
78
|
+
|
|
79
|
+
[](https://github.com/Vitaee/FastapiObserver/actions/workflows/ci.yml)
|
|
80
|
+
[](https://buymeacoffee.com/FYbPCSu)
|
|
81
|
+
|
|
82
|
+
**Zero-glue observability for FastAPI.**
|
|
83
|
+
|
|
84
|
+
`fastapi-observer` gives you structured JSON logs, request correlation, Prometheus metrics, OpenTelemetry tracing, security redaction presets, and runtime controls in one install step and one function call.
|
|
85
|
+
|
|
86
|
+
**Supported Python versions:** `3.10` to `3.14`
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Compatibility Matrix
|
|
92
|
+
|
|
93
|
+
| Component | Supported / Tested |
|
|
94
|
+
|---|---|
|
|
95
|
+
| Python | `3.10` to `3.14` (CI matrix) |
|
|
96
|
+
| FastAPI | `>=0.129.0` |
|
|
97
|
+
| Starlette | `>=0.52.1` |
|
|
98
|
+
| pydantic-settings | `>=2.10.1` |
|
|
99
|
+
| Prometheus backend | `prometheus-client>=0.24.1` (optional extra) |
|
|
100
|
+
| OpenTelemetry | `opentelemetry-api/sdk/exporter>=1.39.1` (optional extra) |
|
|
101
|
+
| Loguru bridge | `loguru>=0.7.2` (optional extra) |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Why This Package Exists
|
|
106
|
+
|
|
107
|
+
Most FastAPI services eventually need the same observability plumbing:
|
|
108
|
+
- Structured JSON logging
|
|
109
|
+
- Request and trace correlation
|
|
110
|
+
- Metrics for dashboards and alerts
|
|
111
|
+
- OpenTelemetry setup
|
|
112
|
+
- Redaction/sanitization for sensitive data
|
|
113
|
+
- Runtime controls for incident response
|
|
114
|
+
|
|
115
|
+
Teams usually implement this as custom glue code in every service. That costs engineering time and creates drift between services.
|
|
116
|
+
|
|
117
|
+
`fastapi-observer` replaces this repeated wiring with a consistent, secure-by-default setup.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Sponsor
|
|
122
|
+
|
|
123
|
+
If this library saves you engineering time, you can support maintenance here:
|
|
124
|
+
|
|
125
|
+
[buymeacoffee.com/FYbPCSu](https://buymeacoffee.com/FYbPCSu)
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## What You Get Immediately
|
|
130
|
+
|
|
131
|
+
After one call to `install_observability()`:
|
|
132
|
+
|
|
133
|
+
| Capability | Included | Default |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| Structured JSON logs | Yes | Enabled |
|
|
136
|
+
| Request ID correlation | Yes | Enabled |
|
|
137
|
+
| Trace/span IDs in logs | Yes (with OTel) | Off until OTel enabled |
|
|
138
|
+
| Prometheus `/metrics` | Yes | Off until `metrics_enabled=True` |
|
|
139
|
+
| Native FastAPI Lifespan | Yes | Explicit opt-in via `observability_lifespan` |
|
|
140
|
+
| Auto-discovery | Yes | Excluded routes (`/docs`, etc.) & DB engines |
|
|
141
|
+
| Sensitive-data redaction | Yes | Enabled |
|
|
142
|
+
| Security presets (`strict`, `pci`, `gdpr`) | Yes | Available |
|
|
143
|
+
| Runtime control endpoint | Yes | Off until enabled |
|
|
144
|
+
| Plugin hooks for enrichment/hooks | Yes | Available |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Install
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Core (logging + metrics + security)
|
|
152
|
+
pip install fastapi-observer
|
|
153
|
+
|
|
154
|
+
# Prometheus metrics support
|
|
155
|
+
pip install "fastapi-observer[prometheus]"
|
|
156
|
+
|
|
157
|
+
# Loguru coexistence bridge support
|
|
158
|
+
pip install "fastapi-observer[loguru]"
|
|
159
|
+
|
|
160
|
+
# OpenTelemetry tracing/logs support
|
|
161
|
+
pip install "fastapi-observer[otel]"
|
|
162
|
+
|
|
163
|
+
# Everything
|
|
164
|
+
pip install "fastapi-observer[all]"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Import path:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
import fastapiobserver
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 5-Minute Quick Start
|
|
176
|
+
|
|
177
|
+
## 5-Minute Quick Start ("Zero-Glue")
|
|
178
|
+
|
|
179
|
+
You can configure the entire library via environment variables simply by calling `install_observability(app)`.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
export APP_NAME="orders-api"
|
|
183
|
+
export SERVICE_NAME="orders"
|
|
184
|
+
export ENVIRONMENT="production"
|
|
185
|
+
export METRICS_ENABLED="true"
|
|
186
|
+
|
|
187
|
+
# Optional: Set a profile ("development" or "production") to auto-configure log levels, queues, and redaction strictness
|
|
188
|
+
export OBS_PROFILE="production"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from fastapi import FastAPI
|
|
193
|
+
from fastapiobserver import install_observability
|
|
194
|
+
|
|
195
|
+
app = FastAPI()
|
|
196
|
+
|
|
197
|
+
# Wires up logging, metrics, OTel, and security automatically from env vars
|
|
198
|
+
install_observability(app)
|
|
199
|
+
|
|
200
|
+
@app.get("/orders/{order_id}")
|
|
201
|
+
def get_order(order_id: int) -> dict[str, int]:
|
|
202
|
+
return {"order_id": order_id}
|
|
203
|
+
|
|
204
|
+
@app.get("/hidden", include_in_schema=False)
|
|
205
|
+
def hidden_endpoint():
|
|
206
|
+
# This endpoint is automatically excluded from
|
|
207
|
+
# Prometheus metrics and OTel tracing.
|
|
208
|
+
return {"status": "ok"}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Run:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
uvicorn main:app --reload
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Now you have:
|
|
218
|
+
- Structured request logs on every request
|
|
219
|
+
- Request ID propagation
|
|
220
|
+
- Sanitized event payloads (enforced by the `production` profile)
|
|
221
|
+
- Prometheus metrics at `/metrics`
|
|
222
|
+
|
|
223
|
+
### Environment Profiles (`OBS_PROFILE`)
|
|
224
|
+
|
|
225
|
+
To dramatically reduce boilerplate, you can use the `OBS_PROFILE` environment variable to automatically set sensible defaults for your environment:
|
|
226
|
+
|
|
227
|
+
- **`OBS_PROFILE=development`**: Forces `LOG_LEVEL=DEBUG` and disables any OpenTelemetry network overhead to keep local development fast and noisy.
|
|
228
|
+
- **`OBS_PROFILE=production`**: Forces `LOG_LEVEL=INFO`, optimizes internal queues for massive throughput (`LOG_QUEUE_MAX_SIZE=20000`), and enforces the `strict` security redaction preset.
|
|
229
|
+
|
|
230
|
+
*(Explicit env vars or Python arguments will always override profile defaults).*
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Documentation Map
|
|
235
|
+
|
|
236
|
+
For deep-dive documentation, please explore the official documentation site (or read the `docs/` folder directly):
|
|
237
|
+
- [Security & Presets](security.md)
|
|
238
|
+
- [Environment Variables](configuration.md)
|
|
239
|
+
- [Runtime Control](runtime-control.md)
|
|
240
|
+
- [OpenTelemetry](opentelemetry.md)
|
|
241
|
+
- [Logtail Sink](logtail-sink.md)
|
|
242
|
+
- [Audit Logging](audit-logging.md)
|
|
243
|
+
- [Database Tracing](db-tracing.md)
|
|
244
|
+
- [GraphQL Support](graphql.md)
|
|
245
|
+
- [Architecture & Operations](architecture.md)
|
|
246
|
+
- [Production Deployment](deployment.md)
|
|
247
|
+
- [Performance Tuning](tuning.md)
|
|
248
|
+
- [Advanced Operations](advanced.md)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# fastapi-observer
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Vitaee/FastapiObserver/actions/workflows/ci.yml)
|
|
4
|
+
[](https://buymeacoffee.com/FYbPCSu)
|
|
5
|
+
|
|
6
|
+
**Zero-glue observability for FastAPI.**
|
|
7
|
+
|
|
8
|
+
`fastapi-observer` gives you structured JSON logs, request correlation, Prometheus metrics, OpenTelemetry tracing, security redaction presets, and runtime controls in one install step and one function call.
|
|
9
|
+
|
|
10
|
+
**Supported Python versions:** `3.10` to `3.14`
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Compatibility Matrix
|
|
16
|
+
|
|
17
|
+
| Component | Supported / Tested |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Python | `3.10` to `3.14` (CI matrix) |
|
|
20
|
+
| FastAPI | `>=0.129.0` |
|
|
21
|
+
| Starlette | `>=0.52.1` |
|
|
22
|
+
| pydantic-settings | `>=2.10.1` |
|
|
23
|
+
| Prometheus backend | `prometheus-client>=0.24.1` (optional extra) |
|
|
24
|
+
| OpenTelemetry | `opentelemetry-api/sdk/exporter>=1.39.1` (optional extra) |
|
|
25
|
+
| Loguru bridge | `loguru>=0.7.2` (optional extra) |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Why This Package Exists
|
|
30
|
+
|
|
31
|
+
Most FastAPI services eventually need the same observability plumbing:
|
|
32
|
+
- Structured JSON logging
|
|
33
|
+
- Request and trace correlation
|
|
34
|
+
- Metrics for dashboards and alerts
|
|
35
|
+
- OpenTelemetry setup
|
|
36
|
+
- Redaction/sanitization for sensitive data
|
|
37
|
+
- Runtime controls for incident response
|
|
38
|
+
|
|
39
|
+
Teams usually implement this as custom glue code in every service. That costs engineering time and creates drift between services.
|
|
40
|
+
|
|
41
|
+
`fastapi-observer` replaces this repeated wiring with a consistent, secure-by-default setup.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Sponsor
|
|
46
|
+
|
|
47
|
+
If this library saves you engineering time, you can support maintenance here:
|
|
48
|
+
|
|
49
|
+
[buymeacoffee.com/FYbPCSu](https://buymeacoffee.com/FYbPCSu)
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## What You Get Immediately
|
|
54
|
+
|
|
55
|
+
After one call to `install_observability()`:
|
|
56
|
+
|
|
57
|
+
| Capability | Included | Default |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| Structured JSON logs | Yes | Enabled |
|
|
60
|
+
| Request ID correlation | Yes | Enabled |
|
|
61
|
+
| Trace/span IDs in logs | Yes (with OTel) | Off until OTel enabled |
|
|
62
|
+
| Prometheus `/metrics` | Yes | Off until `metrics_enabled=True` |
|
|
63
|
+
| Native FastAPI Lifespan | Yes | Explicit opt-in via `observability_lifespan` |
|
|
64
|
+
| Auto-discovery | Yes | Excluded routes (`/docs`, etc.) & DB engines |
|
|
65
|
+
| Sensitive-data redaction | Yes | Enabled |
|
|
66
|
+
| Security presets (`strict`, `pci`, `gdpr`) | Yes | Available |
|
|
67
|
+
| Runtime control endpoint | Yes | Off until enabled |
|
|
68
|
+
| Plugin hooks for enrichment/hooks | Yes | Available |
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Core (logging + metrics + security)
|
|
76
|
+
pip install fastapi-observer
|
|
77
|
+
|
|
78
|
+
# Prometheus metrics support
|
|
79
|
+
pip install "fastapi-observer[prometheus]"
|
|
80
|
+
|
|
81
|
+
# Loguru coexistence bridge support
|
|
82
|
+
pip install "fastapi-observer[loguru]"
|
|
83
|
+
|
|
84
|
+
# OpenTelemetry tracing/logs support
|
|
85
|
+
pip install "fastapi-observer[otel]"
|
|
86
|
+
|
|
87
|
+
# Everything
|
|
88
|
+
pip install "fastapi-observer[all]"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Import path:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import fastapiobserver
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 5-Minute Quick Start
|
|
100
|
+
|
|
101
|
+
## 5-Minute Quick Start ("Zero-Glue")
|
|
102
|
+
|
|
103
|
+
You can configure the entire library via environment variables simply by calling `install_observability(app)`.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export APP_NAME="orders-api"
|
|
107
|
+
export SERVICE_NAME="orders"
|
|
108
|
+
export ENVIRONMENT="production"
|
|
109
|
+
export METRICS_ENABLED="true"
|
|
110
|
+
|
|
111
|
+
# Optional: Set a profile ("development" or "production") to auto-configure log levels, queues, and redaction strictness
|
|
112
|
+
export OBS_PROFILE="production"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from fastapi import FastAPI
|
|
117
|
+
from fastapiobserver import install_observability
|
|
118
|
+
|
|
119
|
+
app = FastAPI()
|
|
120
|
+
|
|
121
|
+
# Wires up logging, metrics, OTel, and security automatically from env vars
|
|
122
|
+
install_observability(app)
|
|
123
|
+
|
|
124
|
+
@app.get("/orders/{order_id}")
|
|
125
|
+
def get_order(order_id: int) -> dict[str, int]:
|
|
126
|
+
return {"order_id": order_id}
|
|
127
|
+
|
|
128
|
+
@app.get("/hidden", include_in_schema=False)
|
|
129
|
+
def hidden_endpoint():
|
|
130
|
+
# This endpoint is automatically excluded from
|
|
131
|
+
# Prometheus metrics and OTel tracing.
|
|
132
|
+
return {"status": "ok"}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Run:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
uvicorn main:app --reload
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Now you have:
|
|
142
|
+
- Structured request logs on every request
|
|
143
|
+
- Request ID propagation
|
|
144
|
+
- Sanitized event payloads (enforced by the `production` profile)
|
|
145
|
+
- Prometheus metrics at `/metrics`
|
|
146
|
+
|
|
147
|
+
### Environment Profiles (`OBS_PROFILE`)
|
|
148
|
+
|
|
149
|
+
To dramatically reduce boilerplate, you can use the `OBS_PROFILE` environment variable to automatically set sensible defaults for your environment:
|
|
150
|
+
|
|
151
|
+
- **`OBS_PROFILE=development`**: Forces `LOG_LEVEL=DEBUG` and disables any OpenTelemetry network overhead to keep local development fast and noisy.
|
|
152
|
+
- **`OBS_PROFILE=production`**: Forces `LOG_LEVEL=INFO`, optimizes internal queues for massive throughput (`LOG_QUEUE_MAX_SIZE=20000`), and enforces the `strict` security redaction preset.
|
|
153
|
+
|
|
154
|
+
*(Explicit env vars or Python arguments will always override profile defaults).*
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Documentation Map
|
|
159
|
+
|
|
160
|
+
For deep-dive documentation, please explore the official documentation site (or read the `docs/` folder directly):
|
|
161
|
+
- [Security & Presets](security.md)
|
|
162
|
+
- [Environment Variables](configuration.md)
|
|
163
|
+
- [Runtime Control](runtime-control.md)
|
|
164
|
+
- [OpenTelemetry](opentelemetry.md)
|
|
165
|
+
- [Logtail Sink](logtail-sink.md)
|
|
166
|
+
- [Audit Logging](audit-logging.md)
|
|
167
|
+
- [Database Tracing](db-tracing.md)
|
|
168
|
+
- [GraphQL Support](graphql.md)
|
|
169
|
+
- [Architecture & Operations](architecture.md)
|
|
170
|
+
- [Production Deployment](deployment.md)
|
|
171
|
+
- [Performance Tuning](tuning.md)
|
|
172
|
+
- [Advanced Operations](advanced.md)
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fastapi-observer
|
|
3
|
+
Version: 1.3.1
|
|
4
|
+
Summary: Zero-glue FastAPI observability with security presets and runtime controls
|
|
5
|
+
Author-email: Vitaee <opensource@vitaee.dev>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Vitaee/FastapiObserver
|
|
8
|
+
Project-URL: Documentation, https://github.com/Vitaee/FastapiObserver#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/Vitaee/FastapiObserver.git
|
|
10
|
+
Project-URL: Issues, https://github.com/Vitaee/FastapiObserver/issues
|
|
11
|
+
Project-URL: Funding, https://buymeacoffee.com/FYbPCSu
|
|
12
|
+
Keywords: fastapi,observability,logging,metrics,opentelemetry
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Framework :: FastAPI
|
|
23
|
+
Classifier: Topic :: System :: Logging
|
|
24
|
+
Classifier: Topic :: System :: Monitoring
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: <3.15,>=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: fastapi>=0.129.0
|
|
30
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
|
31
|
+
Requires-Dist: starlette>=0.52.1
|
|
32
|
+
Provides-Extra: fast-json
|
|
33
|
+
Requires-Dist: orjson>=3.11.7; extra == "fast-json"
|
|
34
|
+
Provides-Extra: prometheus
|
|
35
|
+
Requires-Dist: prometheus-client>=0.24.1; extra == "prometheus"
|
|
36
|
+
Provides-Extra: loguru
|
|
37
|
+
Requires-Dist: loguru>=0.7.2; extra == "loguru"
|
|
38
|
+
Provides-Extra: otel
|
|
39
|
+
Requires-Dist: opentelemetry-api>=1.39.1; extra == "otel"
|
|
40
|
+
Requires-Dist: opentelemetry-sdk>=1.39.1; extra == "otel"
|
|
41
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.39.1; extra == "otel"
|
|
42
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.60b1; extra == "otel"
|
|
43
|
+
Requires-Dist: opentelemetry-instrumentation-logging>=0.60b1; extra == "otel"
|
|
44
|
+
Provides-Extra: otel-httpx
|
|
45
|
+
Requires-Dist: opentelemetry-instrumentation-httpx>=0.60b1; extra == "otel-httpx"
|
|
46
|
+
Provides-Extra: otel-requests
|
|
47
|
+
Requires-Dist: opentelemetry-instrumentation-requests>=0.60b1; extra == "otel-requests"
|
|
48
|
+
Provides-Extra: audit
|
|
49
|
+
Requires-Dist: cryptography>=46.0.5; extra == "audit"
|
|
50
|
+
Provides-Extra: otel-sqlalchemy
|
|
51
|
+
Requires-Dist: opentelemetry-instrumentation-sqlalchemy>=0.60b1; extra == "otel-sqlalchemy"
|
|
52
|
+
Provides-Extra: all
|
|
53
|
+
Requires-Dist: orjson>=3.11.7; extra == "all"
|
|
54
|
+
Requires-Dist: prometheus-client>=0.24.1; extra == "all"
|
|
55
|
+
Requires-Dist: loguru>=0.7.2; extra == "all"
|
|
56
|
+
Requires-Dist: opentelemetry-api>=1.39.1; extra == "all"
|
|
57
|
+
Requires-Dist: opentelemetry-sdk>=1.39.1; extra == "all"
|
|
58
|
+
Requires-Dist: opentelemetry-exporter-otlp>=1.39.1; extra == "all"
|
|
59
|
+
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.60b1; extra == "all"
|
|
60
|
+
Requires-Dist: opentelemetry-instrumentation-logging>=0.60b1; extra == "all"
|
|
61
|
+
Requires-Dist: opentelemetry-instrumentation-httpx>=0.60b1; extra == "all"
|
|
62
|
+
Requires-Dist: opentelemetry-instrumentation-requests>=0.60b1; extra == "all"
|
|
63
|
+
Requires-Dist: opentelemetry-instrumentation-sqlalchemy>=0.60b1; extra == "all"
|
|
64
|
+
Requires-Dist: cryptography>=46.0.5; extra == "all"
|
|
65
|
+
Provides-Extra: dev
|
|
66
|
+
Requires-Dist: httpx>=0.28.1; extra == "dev"
|
|
67
|
+
Requires-Dist: loguru>=0.7.2; extra == "dev"
|
|
68
|
+
Requires-Dist: mypy>=1.19.1; extra == "dev"
|
|
69
|
+
Requires-Dist: pip-audit>=2.10.0; extra == "dev"
|
|
70
|
+
Requires-Dist: pytest>=9.0.2; extra == "dev"
|
|
71
|
+
Requires-Dist: pytest-randomly>=3.16.0; extra == "dev"
|
|
72
|
+
Requires-Dist: ruff>=0.15.1; extra == "dev"
|
|
73
|
+
Requires-Dist: cyclonedx-bom>=7.2.1; extra == "dev"
|
|
74
|
+
Requires-Dist: uvicorn>=0.30.0; extra == "dev"
|
|
75
|
+
Dynamic: license-file
|
|
76
|
+
|
|
77
|
+
# fastapi-observer
|
|
78
|
+
|
|
79
|
+
[](https://github.com/Vitaee/FastapiObserver/actions/workflows/ci.yml)
|
|
80
|
+
[](https://buymeacoffee.com/FYbPCSu)
|
|
81
|
+
|
|
82
|
+
**Zero-glue observability for FastAPI.**
|
|
83
|
+
|
|
84
|
+
`fastapi-observer` gives you structured JSON logs, request correlation, Prometheus metrics, OpenTelemetry tracing, security redaction presets, and runtime controls in one install step and one function call.
|
|
85
|
+
|
|
86
|
+
**Supported Python versions:** `3.10` to `3.14`
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Compatibility Matrix
|
|
92
|
+
|
|
93
|
+
| Component | Supported / Tested |
|
|
94
|
+
|---|---|
|
|
95
|
+
| Python | `3.10` to `3.14` (CI matrix) |
|
|
96
|
+
| FastAPI | `>=0.129.0` |
|
|
97
|
+
| Starlette | `>=0.52.1` |
|
|
98
|
+
| pydantic-settings | `>=2.10.1` |
|
|
99
|
+
| Prometheus backend | `prometheus-client>=0.24.1` (optional extra) |
|
|
100
|
+
| OpenTelemetry | `opentelemetry-api/sdk/exporter>=1.39.1` (optional extra) |
|
|
101
|
+
| Loguru bridge | `loguru>=0.7.2` (optional extra) |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Why This Package Exists
|
|
106
|
+
|
|
107
|
+
Most FastAPI services eventually need the same observability plumbing:
|
|
108
|
+
- Structured JSON logging
|
|
109
|
+
- Request and trace correlation
|
|
110
|
+
- Metrics for dashboards and alerts
|
|
111
|
+
- OpenTelemetry setup
|
|
112
|
+
- Redaction/sanitization for sensitive data
|
|
113
|
+
- Runtime controls for incident response
|
|
114
|
+
|
|
115
|
+
Teams usually implement this as custom glue code in every service. That costs engineering time and creates drift between services.
|
|
116
|
+
|
|
117
|
+
`fastapi-observer` replaces this repeated wiring with a consistent, secure-by-default setup.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Sponsor
|
|
122
|
+
|
|
123
|
+
If this library saves you engineering time, you can support maintenance here:
|
|
124
|
+
|
|
125
|
+
[buymeacoffee.com/FYbPCSu](https://buymeacoffee.com/FYbPCSu)
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## What You Get Immediately
|
|
130
|
+
|
|
131
|
+
After one call to `install_observability()`:
|
|
132
|
+
|
|
133
|
+
| Capability | Included | Default |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| Structured JSON logs | Yes | Enabled |
|
|
136
|
+
| Request ID correlation | Yes | Enabled |
|
|
137
|
+
| Trace/span IDs in logs | Yes (with OTel) | Off until OTel enabled |
|
|
138
|
+
| Prometheus `/metrics` | Yes | Off until `metrics_enabled=True` |
|
|
139
|
+
| Native FastAPI Lifespan | Yes | Explicit opt-in via `observability_lifespan` |
|
|
140
|
+
| Auto-discovery | Yes | Excluded routes (`/docs`, etc.) & DB engines |
|
|
141
|
+
| Sensitive-data redaction | Yes | Enabled |
|
|
142
|
+
| Security presets (`strict`, `pci`, `gdpr`) | Yes | Available |
|
|
143
|
+
| Runtime control endpoint | Yes | Off until enabled |
|
|
144
|
+
| Plugin hooks for enrichment/hooks | Yes | Available |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Install
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Core (logging + metrics + security)
|
|
152
|
+
pip install fastapi-observer
|
|
153
|
+
|
|
154
|
+
# Prometheus metrics support
|
|
155
|
+
pip install "fastapi-observer[prometheus]"
|
|
156
|
+
|
|
157
|
+
# Loguru coexistence bridge support
|
|
158
|
+
pip install "fastapi-observer[loguru]"
|
|
159
|
+
|
|
160
|
+
# OpenTelemetry tracing/logs support
|
|
161
|
+
pip install "fastapi-observer[otel]"
|
|
162
|
+
|
|
163
|
+
# Everything
|
|
164
|
+
pip install "fastapi-observer[all]"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Import path:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
import fastapiobserver
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 5-Minute Quick Start
|
|
176
|
+
|
|
177
|
+
## 5-Minute Quick Start ("Zero-Glue")
|
|
178
|
+
|
|
179
|
+
You can configure the entire library via environment variables simply by calling `install_observability(app)`.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
export APP_NAME="orders-api"
|
|
183
|
+
export SERVICE_NAME="orders"
|
|
184
|
+
export ENVIRONMENT="production"
|
|
185
|
+
export METRICS_ENABLED="true"
|
|
186
|
+
|
|
187
|
+
# Optional: Set a profile ("development" or "production") to auto-configure log levels, queues, and redaction strictness
|
|
188
|
+
export OBS_PROFILE="production"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from fastapi import FastAPI
|
|
193
|
+
from fastapiobserver import install_observability
|
|
194
|
+
|
|
195
|
+
app = FastAPI()
|
|
196
|
+
|
|
197
|
+
# Wires up logging, metrics, OTel, and security automatically from env vars
|
|
198
|
+
install_observability(app)
|
|
199
|
+
|
|
200
|
+
@app.get("/orders/{order_id}")
|
|
201
|
+
def get_order(order_id: int) -> dict[str, int]:
|
|
202
|
+
return {"order_id": order_id}
|
|
203
|
+
|
|
204
|
+
@app.get("/hidden", include_in_schema=False)
|
|
205
|
+
def hidden_endpoint():
|
|
206
|
+
# This endpoint is automatically excluded from
|
|
207
|
+
# Prometheus metrics and OTel tracing.
|
|
208
|
+
return {"status": "ok"}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Run:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
uvicorn main:app --reload
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Now you have:
|
|
218
|
+
- Structured request logs on every request
|
|
219
|
+
- Request ID propagation
|
|
220
|
+
- Sanitized event payloads (enforced by the `production` profile)
|
|
221
|
+
- Prometheus metrics at `/metrics`
|
|
222
|
+
|
|
223
|
+
### Environment Profiles (`OBS_PROFILE`)
|
|
224
|
+
|
|
225
|
+
To dramatically reduce boilerplate, you can use the `OBS_PROFILE` environment variable to automatically set sensible defaults for your environment:
|
|
226
|
+
|
|
227
|
+
- **`OBS_PROFILE=development`**: Forces `LOG_LEVEL=DEBUG` and disables any OpenTelemetry network overhead to keep local development fast and noisy.
|
|
228
|
+
- **`OBS_PROFILE=production`**: Forces `LOG_LEVEL=INFO`, optimizes internal queues for massive throughput (`LOG_QUEUE_MAX_SIZE=20000`), and enforces the `strict` security redaction preset.
|
|
229
|
+
|
|
230
|
+
*(Explicit env vars or Python arguments will always override profile defaults).*
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Documentation Map
|
|
235
|
+
|
|
236
|
+
For deep-dive documentation, please explore the official documentation site (or read the `docs/` folder directly):
|
|
237
|
+
- [Security & Presets](security.md)
|
|
238
|
+
- [Environment Variables](configuration.md)
|
|
239
|
+
- [Runtime Control](runtime-control.md)
|
|
240
|
+
- [OpenTelemetry](opentelemetry.md)
|
|
241
|
+
- [Logtail Sink](logtail-sink.md)
|
|
242
|
+
- [Audit Logging](audit-logging.md)
|
|
243
|
+
- [Database Tracing](db-tracing.md)
|
|
244
|
+
- [GraphQL Support](graphql.md)
|
|
245
|
+
- [Architecture & Operations](architecture.md)
|
|
246
|
+
- [Production Deployment](deployment.md)
|
|
247
|
+
- [Performance Tuning](tuning.md)
|
|
248
|
+
- [Advanced Operations](advanced.md)
|
|
@@ -14,6 +14,7 @@ src/fastapiobserver/db_tracing.py
|
|
|
14
14
|
src/fastapiobserver/fastapi.py
|
|
15
15
|
src/fastapiobserver/loguru.py
|
|
16
16
|
src/fastapiobserver/plugins.py
|
|
17
|
+
src/fastapiobserver/profiles.py
|
|
17
18
|
src/fastapiobserver/propagation.py
|
|
18
19
|
src/fastapiobserver/py.typed
|
|
19
20
|
src/fastapiobserver/request_context.py
|
|
@@ -85,6 +86,7 @@ tests/test_dx_parity.py
|
|
|
85
86
|
tests/test_excluded_url_precedence.py
|
|
86
87
|
tests/test_fastapi_install.py
|
|
87
88
|
tests/test_graphql_integrations.py
|
|
89
|
+
tests/test_lifespan_teardown.py
|
|
88
90
|
tests/test_log_queue_controls.py
|
|
89
91
|
tests/test_logging_schema_contract.py
|
|
90
92
|
tests/test_logtail_dlq.py
|
|
@@ -101,6 +103,7 @@ tests/test_otel_logs_pipeline.py
|
|
|
101
103
|
tests/test_otel_metrics_from_env.py
|
|
102
104
|
tests/test_otlp_export_integration.py
|
|
103
105
|
tests/test_plugin_isolation.py
|
|
106
|
+
tests/test_profiles.py
|
|
104
107
|
tests/test_propagation.py
|
|
105
108
|
tests/test_redaction_presets.py
|
|
106
109
|
tests/test_route_template_cardinality.py
|