# Python + FastAPI Configure collection for an **existing FastAPI/Uvicorn systemd service** on Linux. Setup installs the OTel instrumentation in the application's existing virtualenv and enables it at interpreter startup; it does not create a sample FastAPI app or a new application virtualenv. ## Existing server requirements - A running Uvicorn systemd service and an existing FastAPI application directory. - The application's virtualenv interpreter in `PYTHON_BINARY`, with Python 3.10+ and FastAPI >=0.92,<1. - Root access and Python 3.10+ for the installer itself. Package installation runs as the virtualenv owner; a root-managed virtualenv must have root-managed parent directories. - No preexisting OTel SDK or custom `sitecustomize`. Configure an existing SDK/bootstrap in place instead of layering another one on top. Gunicorn preload/fork arrangements need deployment-specific instrumentation and are not installed by this recipe. ## Server changes Set `SYSTEMD_SERVICE`, `APP_DIR`, `PYTHON_BINARY`, `OTEL_SERVICE_NAME`, and `INTEGRATION_ID`. Setup records constraints for every installed Python distribution, then adds only the pinned OTel dependencies to the existing virtualenv. It refuses a dependency solution that upgrades or downgrades the application's installed packages. A managed `sitecustomize.py` enables the official OTel distro, FastAPI instrumentation, and logging instrumentation before the application imports FastAPI. The systemd environment drop-in prepends its directory to `PYTHONPATH` while retaining the existing path. Application code and `ExecStart` are unchanged. Coverage includes HTTP request traces, FastAPI/ASGI request metrics, and supported standard-library logging records with active trace context. Existing logger levels still apply; printing to stdout does not become an OTel log automatically. Custom business metrics and additional client libraries need their own instrumentation. The agent pins SDK/HTTP exporters **1.45.0** and distro/FastAPI/logging instrumentation **0.66b0**. It uses HTTP/protobuf to the local Collector, then authenticated OTLP/HTTP to Corridora. Parent-based root sampling defaults to 10%. Distribution-provided `sitecustomize` in the root-owned standard-library directory is chained before instrumentation; application-specific hooks require manual integration. ## Set up collection Clone the repository on the existing server: ```sh git clone https://github.com/corridora/integrations.git cd integrations/python-fastapi cp env.example "$HOME/corridora-python-fastapi.env" chmod 600 "$HOME/corridora-python-fastapi.env" ``` Edit that private file to select the actual application directory, running service, runtime paths, and stable service name. The default ingest destination is `https://ingest.corridora.ai`; replace it only with the HTTPS ingest base URL supplied for your Corridora deployment. Do not append `/v1/traces`, `/v1/logs`, or `/v1/metrics`. Load an active Corridora **ingest key** through your secret manager or a hidden prompt. The process environment overrides the configuration file: ```sh export CORRIDORA_INGEST_KEY="$(python3 -c 'import getpass; print(getpass.getpass("Corridora ingest key: "))')" sudo --preserve-env=CORRIDORA_INGEST_KEY bash setup.sh --config "$HOME/corridora-python-fastapi.env" --dry-run sudo --preserve-env=CORRIDORA_INGEST_KEY bash setup.sh --config "$HOME/corridora-python-fastapi.env" ``` The first command inspects the server and prints the plan. The second installs collection, starts its Collector, and restarts the explicitly named application service. The script does not create an application, database, example site, or sample workload. It reads configuration as data and never sources it as shell code. It does not overwrite the input configuration file. Keep the whole checkout: `setup.sh` invokes the shared `lib/collection.py` installer and uses this folder's `agent/` files. The [public source](https://github.com/corridora/integrations/tree/main/python-fastapi) and this guide are mirrored; the old sample-launch `--start` and `--verify` modes have been removed. ## Corridora delivery The installed path is application → loopback OTLP/HTTP Collector → authenticated HTTPS Corridora ingestion. The Collector's **only exporter** is Corridora. There is no Jaeger, debug exporter, or optional alternate-backend mode. Collector Contrib **0.160.0** is downloaded from the official release with a pinned SHA-256 checksum for Linux amd64 or arm64. It runs under a dedicated `corridora-otel` system account. The receiver and health endpoint bind only to `127.0.0.1`; setup does not open firewall ports. Choose a free `COLLECTOR_PORT` and the following port for health checks. The default port differs between integration types. The Collector adds `X-CORRIDORA-KEY`. The key is stored in its protected `/etc/corridora-otel//collector.yaml`, readable by root and the Collector's group. It is not placed in the application environment, PHP settings, command-line arguments, or repository files. TLS certificate verification stays enabled. Application exporters use the local receiver without that key; the generated startup settings clear stale signal-specific exporter overrides. Traces and logs pass through an attribute processor that removes full SQL statements, query text, raw full URLs, and query strings before external export. Route/path attributes remain available. This does not replace the application's own log-message redaction policy. The Collector batches exports and uses a persistent retry queue under `/var/lib/corridora-otel//queue`. ## Verify and operate Generate traffic against the real application after setup. In Corridora, select its configured `OTEL_SERVICE_NAME` and the current time window, then inspect a request trace. Follow [stored-data verification](https://www.corridora.ai/docs/collect/setup/verification) and [the ingest reference](https://www.corridora.ai/docs/reference/ingest). A running service or successful local export test does not establish remote storage or UI visibility. Inspect the application and Collector services on the server: ```sh sudo systemctl status YOUR_APPLICATION.service sudo systemctl status corridora-otel-YOUR_INTEGRATION_ID.service sudo journalctl -u corridora-otel-YOUR_INTEGRATION_ID.service --since '10 minutes ago' ``` Repeat setup with the same ID to reconcile the same installation. Existing managed files that were changed outside setup are rejected rather than overwritten. Changing an ID creates a different installation; do not use a new ID as an update shortcut. Ingest key rotation uses the same config/ID and restarts the Collector. To restore saved startup configuration: ```sh sudo bash setup.sh --config "$HOME/corridora-python-fastapi.env" --rollback ``` Rollback disables this installation's Collector, restores the previous startup configuration, and restarts the affected service. Installed dependencies, the native PHP extension if installed, and queued data remain on disk. Configuration backups and installation state are root-only. Review the application's normal shutdown behavior: forced termination can lose an in-flight SDK batch. ## Validation scope The repository's [server validation fixture](https://github.com/corridora/integrations/tree/main/tests/server) exercises existing applications, installer filesystem changes, dry runs, repeated setup, native configuration validation, rollback, and real OTLP export through a Collector to an HTTPS Corridora-format receiver using synthetic credentials. `systemctl` is simulated in the unprivileged test container; these checks do not claim a production systemd rollout or ingestion into a real Corridora account.