Skip to main content

Lightweight observability SDK for Python web frameworks. Auto-instruments FastAPI, Flask, and Django with real-time tracing via OTLP/HTTP.

Project description

tracely-sdk

Lightweight observability SDK for Python web frameworks. Auto-instruments FastAPI, Flask, and Django with real-time distributed tracing via OTLP/HTTP.

PyPI version Python License: MIT

Features

  • One-call instrumentation -- instrument_fastapi(app), instrument_flask(app), instrument_django()
  • Real-time pending spans -- see requests the moment they start, not just when they finish
  • Full request/response capture -- headers, body, query params with smart redaction
  • OTLP/HTTP protobuf export -- standard OpenTelemetry wire format
  • Batch export with backoff -- 1s flush interval, exponential retry on failure
  • Fail-silent design -- SDK never crashes or degrades your application
  • Minimal dependencies -- only httpx and opentelemetry-proto

Installation

pip install tracely-sdk

Quick Start

FastAPI

import tracely
from fastapi import FastAPI

tracely.init(api_key="trly_your_key_here")

app = FastAPI()
tracely.instrument_fastapi(app)

@app.get("/")
async def root():
    return {"status": "ok"}

Flask

import tracely
from flask import Flask

tracely.init(api_key="trly_your_key_here")

app = Flask(__name__)
tracely.instrument_flask(app)

@app.route("/")
def root():
    return {"status": "ok"}

Django

Initialize and instrument in your app startup (e.g., AppConfig.ready()):

import tracely

tracely.init(api_key="trly_your_key_here")
tracely.instrument_django()

Configuration

Environment Variables

Variable Description Default
TRACELY_API_KEY API key for authentication (required)
TRACELY_ENDPOINT Ingestion API endpoint https://i.tracely.sh
ENVIRONMENT Deployment environment (e.g., production) None
TRACELY_REDACT_FIELDS Comma-separated header/field names to redact None

Programmatic Init

import tracely

tracely.init(
    api_key="trly_your_key_here",
    environment="production",
    service_name="my-api",
    service_version="1.0.0",
)

Custom Spans

Create manual spans for custom operations:

import tracely

with tracely.span("db-query", kind="CLIENT") as s:
    s.set_attribute("db.system", "postgres")
    s.set_attribute("db.statement", "SELECT * FROM users")
    result = db.execute("SELECT * FROM users")

Span Events (Structured Logging)

Attach structured log events to the active span:

import tracely

with tracely.span("process-order") as s:
    tracely.info("Order received", order_id="123")
    # ... process
    tracely.debug("Validation passed")
    tracely.warning("Inventory low", sku="WIDGET-42")

Graceful Shutdown

Flush buffered spans before exit:

import tracely

tracely.init(api_key="trly_your_key_here")
# ... application runs ...
tracely.shutdown()  # flushes remaining spans

How It Works

Your App
  |
  v
Middleware (FastAPI/Flask/Django)
  |-- on_start --> SpanProcessor --> SpanBuffer (pending_span)
  |-- on_end ----> SpanProcessor --> SpanBuffer (final span)
                                        |
                                        v
                                  BatchSpanExporter (1s interval / 50 span threshold)
                                        |
                                        v
                                  OTLP Protobuf Serialization
                                        |
                                        v
                                  HttpTransport --> TRACELY API
                                  (retry with exponential backoff)

Documentation

Full docs at tracely.sh/docs

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tracely_sdk-0.2.5.tar.gz (58.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tracely_sdk-0.2.5-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file tracely_sdk-0.2.5.tar.gz.

File metadata

  • Download URL: tracely_sdk-0.2.5.tar.gz
  • Upload date:
  • Size: 58.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracely_sdk-0.2.5.tar.gz
Algorithm Hash digest
SHA256 3633270fea1798520f8fb1f0e6e4f1990dbe7bf322d351bac4cb8959529652a7
MD5 09656bf3d566a50943736eb7556917e8
BLAKE2b-256 ac3f8faadf4d65f99dd0965a4c203a8fc1abef046bf1df13286a6af4a281f3c8

See more details on using hashes here.

File details

Details for the file tracely_sdk-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: tracely_sdk-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 38.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tracely_sdk-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 169bdc893a5d7b028fbc866315dfeb67003092bda0af2ba7bc289a63ab9de623
MD5 ab88a638373ddb7594cd2bb56816a64c
BLAKE2b-256 24453b434f71708e8e72c8bb4ab25fd1b184db0b13cb4c3bd4ae9ecc5df5aa39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page