Skip to main content

Obtrace Python SDK

Project description

obtrace-sdk-python

Python backend SDK for Obtrace telemetry transport and instrumentation.

Scope

  • OTLP logs/traces/metrics transport
  • Context propagation
  • HTTP instrumentation (requests/httpx)
  • Framework helpers (FastAPI, Flask)

Design Principle

SDK is thin/dumb.

  • No business logic authority in client SDK.
  • Policy and product logic are server-side.

Install

pip install obtrace-sdk-python

Configuration

Required:

  • api_key
  • ingest_base_url
  • service_name

Optional (auto-resolved from API key on the server side):

  • tenant_id
  • project_id
  • app_id
  • env
  • service_version

Quickstart

Simplified setup

The API key resolves tenant_id, project_id, app_id, and env automatically on the server side, so only three fields are needed:

from obtrace_sdk import ObtraceClient, ObtraceConfig

client = ObtraceClient(
    ObtraceConfig(
        api_key="obt_live_...",
        ingest_base_url="https://ingest.obtrace.io",
        service_name="my-service",
    )
)

Full configuration

For advanced use cases you can override the resolved values explicitly:

from obtrace_sdk import ObtraceClient, ObtraceConfig, SemanticMetrics

client = ObtraceClient(
    ObtraceConfig(
        api_key="<API_KEY>",
        ingest_base_url="https://inject.obtrace.ai",
        service_name="python-api",
        env="prod",
    )
)

client.log("info", "started")
client.metric(SemanticMetrics.RUNTIME_CPU_UTILIZATION, 0.41)
client.span(
    "checkout.charge",
    attrs={
        "feature.name": "checkout",
        "payment.provider": "stripe",
    },
)
client.flush()

Canonical metrics and custom spans

  • Use SemanticMetrics for the product-wide metric catalog.
  • Custom spans use client.span(name, attrs=...).
  • Keep free-form metric names only for truly product-specific signals that are not part of the shared catalog.

Frameworks and HTTP

  • Framework helpers: FastAPI and Flask
  • HTTP instrumentation: requests and httpx
  • Reference docs:
    • docs/frameworks.md
    • docs/http-instrumentation.md

Production Hardening

  1. Keep api_key only in server-side secret storage.
  2. Use one key per environment and rotate periodically.
  3. Keep fail-open behavior (telemetry must not break request flow).
  4. Validate ingestion after deploy using Query Gateway and ClickHouse checks.

Troubleshooting

  • No telemetry: validate ingest_base_url, API key, and egress connectivity.
  • Missing correlation: ensure propagation headers are injected on outbound HTTP.
  • Short-lived workers: call flush() before process exit.

Documentation

  • Docs index: docs/index.md
  • LLM context file: llm.txt
  • MCP metadata: mcp.json

Reference

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

obtrace_sdk_python-1.0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

obtrace_sdk_python-1.0.3-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file obtrace_sdk_python-1.0.3.tar.gz.

File metadata

  • Download URL: obtrace_sdk_python-1.0.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for obtrace_sdk_python-1.0.3.tar.gz
Algorithm Hash digest
SHA256 8e47388c81cbc86de2c59c412068708fe6ad165bfe8b17ac12989465163a513e
MD5 05449d5172cf9295a52a35493875c4d7
BLAKE2b-256 9166d6d40ac06e1f9e0ecb05c852516f43c230f9b4babb185018ed1413e787bd

See more details on using hashes here.

File details

Details for the file obtrace_sdk_python-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for obtrace_sdk_python-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8748edb8812f74a776d1fbee5e5ecae7028d1ff32f3be40521b7fd3fbcc69bc0
MD5 18a2020310e4b0359af3c52ee4e5f1be
BLAKE2b-256 e35abf18e2230c6587e4d75d856053df4a1d4c5726a216607a219ffb24d09d85

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