telemify
Seamless instrumentation of tracing, logging, and metrics in FastAPI and Starlette applications, using opentelemetry, structlog, and prometheus-client.
Installation
$ pip install telemify
Usage
import uvicorn
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import create_async_engine
from starlette.config import Config
from telemify.logging.configure import configure as configure_logger
from telemify.logging.filters import (
ExceptionASGIApplicationFilter,
MetricsEndpointFilter,
)
from telemify.logging.middleware import LoggerMiddleware
from telemify.logging.processors import add_open_telemetry_spans, drop_color_message_key
from telemify.metrics.configure import configure as configure_metrics
from telemify.metrics.middleware import PrometheusMiddleware
from telemify.tracing.configure import configure as configure_tracing
config = Config()
LOG_LEVEL: str = config("LOG_LEVEL", cast=str, default="info")
engine = create_async_engine("sqlite+aiosqlite:///test.db")
def configure_telemetry(app: FastAPI):
configure_logger(
json_logs=False,
additional_processors=[drop_color_message_key, add_open_telemetry_spans],
loggers_to_disable=["uvicorn.access"],
loggers_to_propagate=["uvicorn", "uvicorn.error", "sqlalchemy.engine.Engine"],
filters={
"uvicorn.error": [
ExceptionASGIApplicationFilter(),
],
"telemify.logging.middleware": [MetricsEndpointFilter()],
},
)
configure_metrics(app)
configure_tracing(
app,
instrument_httpx=True,
instrument_sqlalchemy=True,
instrument_celery=True,
instrument_botocore=True,
instrument_jinja2=True,
db_engine=engine,
)
app = FastAPI()
app.add_middleware(LoggerMiddleware)
app.add_middleware(PrometheusMiddleware)
configure_telemetry(app)
if __name__ == "__main__":
uvicorn.run(
app,
log_level=LOG_LEVEL,
)
Environment variables
# Application name to be used to mark signals
export APP_NAME=unknown
export LOG_LEVEL=info
export STATUS_4XX_LOG_LEVEL=warning
# Url to send the tracing data. It can be any tool that supports the OpenTelemetry protocol.
# ex. Grafana Tempo, Jaeger, etc.
export OTLP_GRPC_ENDPOINT=http://tempo-distributor.monitoring:4317
# Comma separated string to exclude certain urls from tracking.
# ex. "client/.*/info,healthcheck":
# This will exclude requests such as `https://site/client/123/info` and `https://site/xyz/healthcheck`.
export OTEL_PYTHON_EXCLUDED_URLS="client/.*/info,healthcheck"
Tests
To run the tests, use the following command:
$ poetry run pytest
Reference
Metadata
Release files for telemify 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| telemify-0.5.1.tar.gz | 9.3 kB | Without provenance | Details for telemify-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| telemify-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for telemify-0.5.1-py3-none-any.whl |
Total release size: 20.1 kB
Release files / telemify-0.5.1.tar.gz
| Download URL | telemify-0.5.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9ff5b2d5bf53eab02730aded728ea1b08fdf3a2f389be04dbc9c0d82740e719
|
|
BLAKE2b-256 checksum How to use checksums |
738b43b2e85da07bb4d2962cf1d57d036f313992ed2cad04e8ddbb8117bba18b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.6 Linux/5.14.0-1034-oem
|
Release files / telemify-0.5.1-py3-none-any.whl
| Download URL | telemify-0.5.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ca0af0aeaa5db281fec3d5a93f87a2a90f19dfc0beef81e2c1e5fd20cf5303c
|
|
BLAKE2b-256 checksum How to use checksums |
3219ebb39ce0af90e27f8e1447d6bd20ed8b5b3fd3b359ba7bd0b0150333f002
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.6 Linux/5.14.0-1034-oem
|
Security for telemify 0.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.