Python

The Sophonz Python SDK is an OpenTelemetry distro that sends traces, metrics, and logs from Python server applications to Sophonz, with framework middleware and exception capture.

sophonz-opentelemetry is an OpenTelemetry distro for Python servers. It configures the official OpenTelemetry Python SDK to export traces, metrics, and logs to Sophonz, attaches your service identity to every signal, and loads the OpenTelemetry instrumentations for Flask, FastAPI, Django, requests, httpx, PostgreSQL drivers, SQLAlchemy and more. Its API follows the Node.js SDK: init(), request middleware, error handlers, set_trace_attributes() and record_exception().

What you get

  • Traces, metrics, and logs over OTLP, each signal with its own exporter and a shared resource. The hosted endpoint https://in.sophonz.ai accepts traces and logs; see Deployment for metrics.
  • Distributed tracing from the browser to the database — an incoming W3C traceparent is continued, baggage entries (including the browser's session.id) are copied onto every span, and SQLCommenter can carry the trace into PostgreSQL.
  • Two ways to start — init() in code, or opentelemetry-instrument with environment variables and no code changes.
  • Framework middleware for Flask, FastAPI, and Django that adds baggage, client IP, user agent, and your own attributes to every span of a request, plus error handlers.
  • Exception capture — exceptions escaping a route are recorded on the request span, uncaught exceptions are recorded before the process dies, and every failed span also emits an error log.
  • Standard library logging — logging records are exported and linked to the active trace.
  • Graceful shutdown — telemetry is flushed on SIGTERM / SIGINT and at exit.
  • Service identity — your API key is sent as the authorization header and the service.key resource attribute.

How it works

  1. In code — call init() before your web framework is imported. Installed instrumentations are loaded automatically.
  2. With opentelemetry-instrument — prefix your start command and configure the SDK with SOPHONZ_* / OTEL_* environment variables.

Explicit init() arguments take precedence over environment variables, as in the Node.js SDK.

NOTE — Requirements

Python 3.9 or later.

Reading order

Start here:

  1. Installation — install the package and start sending telemetry.
  2. Configuration — every option and environment variable.
  3. Framework Guides — where init() goes in Flask, FastAPI, and Django, and how gunicorn and uvicorn affect it.
  4. Middleware — request enrichment and error handler options.

Then, as you need them:

  • Instrumentation — what is captured automatically, logs, exceptions, network capture and redaction, custom spans.
  • Database Tracing — psycopg, psycopg2, SQLAlchemy, and the Django ORM, with SQLCommenter for PostgreSQL.
  • Browser to Backend Tracing — continue browser traces and sessions on the server.
  • Deployment — containers, Kubernetes, secrets, and graceful shutdown.

Reference:

  • API Reference — every public function, class, and helper.
  • Examples — complete Flask, FastAPI, and Django servers.

TIP — This is just the beginning

Now ship your app. Sophonz surfaces the problems real users hit — so your app evolves on its own.