Proof of concept project for instrumenting Python APIs with OpenTelemetry and Checkly.
- About
- Prerequisites
- Installation
- Environment Variables Setup
- Running the API
- Simulating Trace Problems
- OpenTelemetry Instrumentation
- Testing
- Deployment
- References
This API demonstrates distributed tracing and monitoring in Python using OpenTelemetry and integration with Checkly.
- Python 3.8+
- pip
- Git
Clone the repository and install the dependencies:
git clone https://github.com/drigocsouza/tracechecklypoc-python.git
cd tracechecklypoc-python
pip install -r requirements.txtNever expose sensitive tokens directly in your code!
Create a .env file at the root of the project (do not commit this file) and add:
CHECKLY_OTEL_TOKEN=<your_checkly_token>
Or export it directly in your terminal (Linux/macOS):
export CHECKLY_OTEL_TOKEN=<your_checkly_token>On Windows (CMD):
set CHECKLY_OTEL_TOKEN=<your_checkly_token>Add .env to .gitignore to ensure it is not versioned:
.env
With the environment variable set, run:
python app.pyThe API will be available at http://localhost:8000.
The /ping endpoint will randomly:
- Return a simulated error (HTTP 500) ~30% of the time.
- Introduce a delay (~2 seconds) ~50% of the time.
This allows you to see both latency and error traces in Checkly.
A /fail endpoint is also available, which always raises an error and can be used to generate error traces intentionally.
- The code already includes tracer configuration and sends spans to Checkly via OTLP.
- To change to another backend, update the
endpointandheadersin the OTLPSpanExporter section.
It is recommended to use pytest for automated tests:
pytestUse environments that allow secure configuration of environment variables (Docker, Heroku, cloud servers).
Questions or suggestions? Open an issue in this repository!