Skip to main content

Official Python SDK for Ditliti (error tracking, tracing, replays, and profiling ingestion).

Project description

ditliti-sdk

Official Python SDK for Ditliti - error tracking, tracing, session replay, and profiling ingestion.

This SDK talks to a self-hosted Ditliti instance (ingestion-api). It does not connect to any managed/hosted service - point it at your own deployment's ingestion URL.

Install

pip install https://github.com/kangartha/inspectora/releases/download/sdk-v0.1.2/ditliti_sdk-0.1.2-py3-none-any.whl

Use pip install ditliti-sdk==0.1.2 only after PyPI confirms publication.

Quick start

from ditliti import DitlitiClient, install_global_exception_hook

client = DitlitiClient(
    endpoint="http://localhost:8305",
    api_key="mp_xxx",
    project_id="PROJECT_UUID",
    release="1.2.3",
    environment="production",
)

install_global_exception_hook(client)

try:
    risky_operation()
except Exception as exc:
    client.capture_exception(exc, context={"extra": "context"})

API

DitlitiClient(endpoint, api_key, project_id, release=None, environment=None, before_send=None, max_payload_bytes=200_000, max_retries=2, retry_base_seconds=0.15, queue_on_failure=False, max_queue_size=100, queue_file=None)

  • client.set_user(user) / client.set_session(session_id)
  • client.add_breadcrumb(...)
  • client.capture_exception(exc, context=..., tags=...)
  • client.capture_message(message, level=..., context=..., tags=...)
  • client.capture_replay_segment(...)
  • client.capture_profile(...)
  • client.send_envelope(envelope) - low-level batch submit.
  • client.flush_queue() - retry events queued after a failed send (when queue_on_failure=True).

Framework/runtime integrations

  • install_global_exception_hook(client) - installs a global sys.excepthook.
  • DitlitiLogHandler(client, level=logging.ERROR) - a logging.Handler that forwards log records as events.
  • DitlitiASGIMiddleware(app, client) / install_fastapi(app, client) - FastAPI/Starlette/ASGI exception capture.
  • DitlitiDjangoMiddleware(get_response, client) - Django exception capture middleware.

Distributed tracing

Generates real W3C traceparent (https://www.w3.org/TR/trace-context/) trace context, so a trace can be propagated across service/microservice boundaries instead of staying siloed per project:

# Service A: start a trace and call Service B, forwarding the header.
client.start_trace()
requests.get("https://service-b.internal/work", headers={"traceparent": client.get_traceparent()})

# Service B: continue the same trace from the inbound header.
# DitlitiASGIMiddleware / DitlitiDjangoMiddleware do this automatically, or call manually:
client.start_trace(request.headers.get("traceparent"))

with client.start_span("db.query", tags={"db": "postgres"}) as span:
    ...  # do the work; span.finish() is called automatically on exit

# capture_exception/capture_message automatically tag `trace_id` when a trace is active,
# so errors show up correlated to the trace at GET /api/v1/traces/:trace_id (org-wide).
  • client.start_trace(incoming_traceparent=None) - starts a new trace, or continues one from an inbound traceparent header.
  • client.get_traceparent() - the header value to forward on outgoing requests.
  • client.start_span(operation_name, tags=...) → a Span usable as a context manager or via .finish(extra_tags=...).

Database query instrumentation (Database Insights)

ditliti.db wraps a query call with a db.query span carrying the OpenTelemetry-shaped attributes the backend uses for Database Insights (slow query / N+1 / error-rate / regression detection). The server parameterizes and hashes db.query.text itself - send the real SQL text, never a redacted one:

from ditliti.db import trace_query, instrument_dbapi_cursor, django_execute_wrapper

# Generic wrapper - works for any driver/ORM:
rows = trace_query(
    client,
    system="postgresql",
    text="SELECT * FROM orders WHERE id = %s",
    execute=lambda: cursor.execute("SELECT * FROM orders WHERE id = %s", (order_id,)) or cursor.fetchall(),
)

# Or wrap any PEP 249 (DB-API 2.0) cursor - sqlite3, psycopg2, pymysql, mysql-connector - transparently:
cursor = instrument_dbapi_cursor(client, connection.cursor(), system="postgresql")
cursor.execute("SELECT * FROM orders WHERE id = %s", (order_id,))
rows = cursor.fetchall()

# Django: register via the official execute_wrapper hook.
from django.db import connection
connection.execute_wrappers.append(django_execute_wrapper(client, system="postgresql"))

# SQLAlchemy: hooks the Engine's before/after/error cursor events (requires sqlalchemy installed).
from ditliti.db import instrument_sqlalchemy_engine
instrument_sqlalchemy_engine(client, engine, system="postgresql")

None of these ever set db.query.summary or ditliti.query_hash (server-computed). On failure they record error.type and re-raise the original exception unchanged; on success they record db.response.returned_rows when the driver reports a row/affected count.

Transport behavior

  • Retries with exponential backoff on network failures and 5xx responses; no retry on permanent 4xx.
  • before_send callback to redact/mutate or drop (return None) a payload before it's sent.
  • Optional JSONL queue (queue_file=...) persists failed sends across process restarts.

More examples

See examples/basic.py in this package's source repository.

License

MIT - see LICENSE.

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

ditliti_sdk-0.1.2.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

ditliti_sdk-0.1.2-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file ditliti_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: ditliti_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ditliti_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 dcca0f727f21dc40dc19afa830d4a09cc0281cf6f36816ebdeb101f2bb651f59
MD5 0233c5d686de69480e639ed0bdd80f39
BLAKE2b-256 cd90010749d9d3fce3613493fa8baaeb283674024adf7a7fc966029a6c186892

See more details on using hashes here.

Provenance

The following attestation bundles were made for ditliti_sdk-0.1.2.tar.gz:

Publisher: sdk-release.yml on kangartha/inspectora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ditliti_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ditliti_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ditliti_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19117194e129d4d903d8179e60748ee431f78d9cc54146b0419801c66e82d46d
MD5 3a8ea0ca9f072b49868deb245c53a866
BLAKE2b-256 2d788f6ed3ebe7776fd50edc5d4f71f9d897c080f7d201348d30d2cb6681c122

See more details on using hashes here.

Provenance

The following attestation bundles were made for ditliti_sdk-0.1.2-py3-none-any.whl:

Publisher: sdk-release.yml on kangartha/inspectora

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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