TracePilot OpenTelemetry SDK for Python
Project description
TracePilot Python SDK
The official TracePilot SDK for Python. TracePilot provides zero-configuration distributed tracing, performance metrics, and global crash reporting for your Python applications.
This SDK is built on top of OpenTelemetry, meaning it provides industry-standard, vendor-neutral instrumentation out of the box, but specifically tuned and optimized for the TracePilot platform.
Quick Start
1. Installation
Install the package via pip or poetry:
pip install swapnil-tracepilot
# or
poetry add swapnil-tracepilot
2. Initialization
Initialize the TracePilot SDK at the very beginning of your application, ideally before importing other major libraries.
import os
from tracepilot import init_tracepilot
# Initialize TracePilot before your framework code
init_tracepilot(
token=os.environ.get("TRACEPILOT_TOKEN")
)
# Your normal application code...
Features
- Global Crash Reporting: Implements a custom
sys.excepthookthat guarantees unhandled exceptions (like aZeroDivisionErroror database disconnect) are caught, serialized into an OpenTelemetry span with the full stack trace, and reliably flushed to the TracePilot ingestor before the Python runtime exits. - Auto-Instrumentation: Uses standard OpenTelemetry instrumentors to automatically trace outgoing HTTP requests (
requests,urllib3), database queries (sqlalchemy,psycopg2), and web frameworks (FastAPI,Flask,Django). - Zero Config: Just provide a token and let the SDK handle batching, export processing, and retry logic.
Advanced Configuration
You can configure the SDK using environment variables or by passing arguments to init_tracepilot():
| Environment Variable | Argument | Description | Default |
|---|---|---|---|
TRACEPILOT_TOKEN |
token |
Required. Your project's API token. | None |
TRACEPILOT_COLLECTOR_URL |
collector_url |
Custom OTLP ingestor endpoint (e.g., if you are self-hosting TracePilot). | http://localhost:4318/v1/traces |
Example with Custom Endpoint
init_tracepilot(
token="tp_live_12345",
collector_url="https://ingestor.tracepilot.io/v1/traces"
)
Manual Tracing
While TracePilot auto-instruments your code, you can also create custom spans to track specific business logic:
from opentelemetry import trace
tracer = trace.get_tracer("my_custom_module")
def process_payment(amount):
with tracer.start_as_current_span("process_payment") as span:
span.set_attribute("payment.amount", amount)
try:
# Complex logic here
pass
except Exception as e:
span.record_exception(e)
span.set_status(trace.Status(trace.StatusCode.ERROR))
raise
Troubleshooting
No data showing up in TracePilot?
- Check that your
TRACEPILOT_TOKENis correct. - Ensure outbound network access to port
4318(or your custom collector port) is unblocked. - Enable OpenTelemetry debug logging by setting
OTEL_LOG_LEVEL=debugin your environment.
License
MIT License. See LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swapnil_tracepilot-0.1.1.tar.gz.
File metadata
- Download URL: swapnil_tracepilot-0.1.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d739e895032d99012596176ad8b77f3fb1ae3175fedc18c7c428b907deb829b
|
|
| MD5 |
876daa38bca03debb1bb173cca689ea8
|
|
| BLAKE2b-256 |
efc3d24325b0e92276bab44539bde0e3ac387d98d803cbf907c313ec5c046fb0
|
File details
Details for the file swapnil_tracepilot-0.1.1-py3-none-any.whl.
File metadata
- Download URL: swapnil_tracepilot-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a34da575bd4d74e86b6d8601e69e9442106fcb44644ca1896f99ed396b98d1f
|
|
| MD5 |
d1e4368c9bc7d937dd4193c3831e7097
|
|
| BLAKE2b-256 |
2d0ad803bef6e8bef56038d45c74e6dcdbc243b87f32499fb5addb124cb0a039
|