Skip to main content

OpenTelemetry-native observability SDK for the IndraTrace platform — one-line traces, logs, metrics, and model-call token usage for web apps and AI agents.

Project description

IndraTrace SDK

OpenTelemetry-native observability SDK for the IndraTrace platform — one-line instrumentation for web apps and AI agents: traces, logs, metrics, and model-call token usage.

pip install indratrace

init_observability() ships traces, logs, and metrics; trace_agent / trace_tool wrap your agents and tools; and model spans carry exact, provider-reported token counts when the GenAI extras are installed. Token counts are recorded raw — the SDK never computes cost; the platform derives it at query time.

import logging

from fastapi import FastAPI

from indratrace import init_observability, trace_agent, trace_tool

# Once, at app startup.
init_observability(product="my-app", env="prod", ingest_key="...")

app = FastAPI()  # HTTP spans are captured automatically


@trace_tool  # a child span per tool call
async def risk_score(vendor: str) -> int:
    logging.getLogger(__name__).info("scoring %s", vendor)  # ships with trace context
    return len(vendor)


@trace_agent("compliance-checker")  # a parent span per agent request
async def run(query: str) -> int:
    return await risk_score(query)

Both decorators work on sync and async functions. They are transparent: a tool that raises gets its span marked ERROR with the exception recorded, and the exception then propagates to your code unchanged.

Install the extras you need — FastAPI for HTTP auto-instrumentation, and anthropic / openai for model spans with token usage:

pip install "indratrace[fastapi,anthropic,openai]"

Token usage from model calls

With the anthropic and/or openai extra installed, every provider call made after init_observability() produces a model span carrying the exact, provider-reported token counts (gen_ai.usage.input_tokens / gen_ai.usage.output_tokens), nested under whatever agent/tool span is active. No wrapper, no config — just call the provider as you already do:

import anthropic

from indratrace import init_observability, trace_agent, trace_tool

init_observability(product="my-app", ingest_key="...")
client = anthropic.Anthropic()


@trace_tool
def summarize(doc: str) -> str:
    msg = client.messages.create(               # model span with token counts,
        model="claude-haiku-4-5",               # a child of this tool span
        max_tokens=256,
        messages=[{"role": "user", "content": doc}],
    )
    return msg.content[0].text


@trace_agent("summarizer")
def run(doc: str) -> str:
    return summarize(doc)

Streaming calls are captured too — usage lands on the span from the final streamed event.

For a provider the SDK does not auto-instrument, stamp the counts yourself from inside a span with record_llm_usage:

from indratrace import record_llm_usage

record_llm_usage(
    model="some-model-v2",
    input_tokens=resp.usage.input,
    output_tokens=resp.usage.output,
    system="acme-ai",
)

Token counts are stored raw — the SDK never computes cost; the platform derives it at query time from a price table.

Configuration is explicit args > env vars > defaults. The env vars are INDRATRACE_ENDPOINT, INDRATRACE_KEY, INDRATRACE_PRODUCT, and INDRATRACE_ENV.

Your existing logging calls ship automatically once your app is at INFO — the usual case under basicConfig(level=INFO), uvicorn, or gunicorn. The SDK does not change your root logger's level on its own; if your app never configured logging (so it sits at the stdlib default of WARNING), pass log_level="INFO" to opt in:

init_observability(product="my-app", ingest_key="...", log_level="INFO")

The SDK never raises into your app: if the collector is unreachable or the config is wrong, it logs one warning and runs un-instrumented. The decorators hold to that too — they run your function even when init_observability() was never called.

Built by Indrasol.

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

indratrace-0.1.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

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

indratrace-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file indratrace-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for indratrace-0.1.0.tar.gz
Algorithm Hash digest
SHA256 418c6428eec37a8cf6661978201c9991694d17bd0344130bdabb72929e158951
MD5 b48d89e7400c5acaafb6f850250b723e
BLAKE2b-256 c7b05817708a710161815a071c1055fae97c705d0bf6f352d0fcdfc7f9316b35

See more details on using hashes here.

Provenance

The following attestation bundles were made for indratrace-0.1.0.tar.gz:

Publisher: release.yml on indrasol/indratrace-python-sdk

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

File details

Details for the file indratrace-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for indratrace-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6c33e1d3b0ccd33a052715a53ccbbcc330b587a84c5f3dffaccac164b32e3a1
MD5 2e78538c1b4ad7af89622e12095e3deb
BLAKE2b-256 3b382a39477a3e2fa90175122241d1a426cfd28ef81e63f18bfd02c9e2d6b081

See more details on using hashes here.

Provenance

The following attestation bundles were made for indratrace-0.1.0-py3-none-any.whl:

Publisher: release.yml on indrasol/indratrace-python-sdk

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