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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
418c6428eec37a8cf6661978201c9991694d17bd0344130bdabb72929e158951
|
|
| MD5 |
b48d89e7400c5acaafb6f850250b723e
|
|
| BLAKE2b-256 |
c7b05817708a710161815a071c1055fae97c705d0bf6f352d0fcdfc7f9316b35
|
Provenance
The following attestation bundles were made for indratrace-0.1.0.tar.gz:
Publisher:
release.yml on indrasol/indratrace-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
indratrace-0.1.0.tar.gz -
Subject digest:
418c6428eec37a8cf6661978201c9991694d17bd0344130bdabb72929e158951 - Sigstore transparency entry: 2139846192
- Sigstore integration time:
-
Permalink:
indrasol/indratrace-python-sdk@7083ae209007b8f4c2b1619bcc18d93e493e74f4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/indrasol
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7083ae209007b8f4c2b1619bcc18d93e493e74f4 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6c33e1d3b0ccd33a052715a53ccbbcc330b587a84c5f3dffaccac164b32e3a1
|
|
| MD5 |
2e78538c1b4ad7af89622e12095e3deb
|
|
| BLAKE2b-256 |
3b382a39477a3e2fa90175122241d1a426cfd28ef81e63f18bfd02c9e2d6b081
|
Provenance
The following attestation bundles were made for indratrace-0.1.0-py3-none-any.whl:
Publisher:
release.yml on indrasol/indratrace-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
indratrace-0.1.0-py3-none-any.whl -
Subject digest:
f6c33e1d3b0ccd33a052715a53ccbbcc330b587a84c5f3dffaccac164b32e3a1 - Sigstore transparency entry: 2139846208
- Sigstore integration time:
-
Permalink:
indrasol/indratrace-python-sdk@7083ae209007b8f4c2b1619bcc18d93e493e74f4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/indrasol
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7083ae209007b8f4c2b1619bcc18d93e493e74f4 -
Trigger Event:
push
-
Statement type: