FastAPI Integration Steps
Requirements
- Python 3.8 or higher
Install SDKs
pip install opentelemetry-distro
pip install opentelemetry-exporter-otlp
You can use standard OpenTelemetry SDKs to send traces to our collector. List of all supported languages by OpenTelemetry and their SDK can be found in OpenTelemetry docs.
Add auto-instrumentation
opentelemetry-bootstrap --action=install
Run your application
OTEL_RESOURCE_ATTRIBUTES=service.name=<your_service_name> \
OTEL_EXPORTER_OTLP_ENDPOINT="https://collector.infrastack.ai" \
OTEL_EXPORTER_OTLP_HEADERS="infrastack-api-key=<your_infrastack_api_key>" \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
opentelemetry-instrument <your_run_command>
Go to InfraStack AI Dashboard (opens in a new tab) to observe your traces
Running applications with Gunicorn, uWSGI
For application servers which are based on pre fork model like Gunicorn, uWSGI you have to add a post_fork
hook or a @postfork
decorator in your configuration.
Check this documentation (opens in a new tab) from OpenTelemetry on how to set it up.
Here's (opens in a new tab) a working example where we have configured a gunicorn server with post_fork
hook.