Metadata-Version: 2.5
Name: traceiq-capture
Version: 0.1.0
Summary: TraceIQ Capture — OpenTelemetry instrumentation with a locked attribute contract
Author: TraceIQ
License-Expression: MIT
License-File: LICENSE
Keywords: ai,cost,llm,observability,opentelemetry,otlp
Requires-Python: >=3.10
Requires-Dist: opentelemetry-api>=1.27.0
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27.0
Requires-Dist: opentelemetry-sdk>=1.27.0
Provides-Extra: all
Requires-Dist: openai; extra == 'all'
Requires-Dist: opentelemetry-instrumentation-anthropic; extra == 'all'
Requires-Dist: opentelemetry-instrumentation-langchain; extra == 'all'
Requires-Dist: opentelemetry-instrumentation-llamaindex; extra == 'all'
Requires-Dist: opentelemetry-instrumentation-openai; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: opentelemetry-instrumentation-anthropic; extra == 'anthropic'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: langchain
Requires-Dist: opentelemetry-instrumentation-langchain; extra == 'langchain'
Provides-Extra: langgraph
Requires-Dist: langgraph; extra == 'langgraph'
Requires-Dist: opentelemetry-instrumentation-langchain; extra == 'langgraph'
Provides-Extra: llamaindex
Requires-Dist: opentelemetry-instrumentation-llamaindex; extra == 'llamaindex'
Provides-Extra: openai
Requires-Dist: openai; extra == 'openai'
Requires-Dist: opentelemetry-instrumentation-openai; extra == 'openai'
Description-Content-Type: text/markdown

# TraceIQ Capture (`traceiq-capture`)

OpenTelemetry-native Python SDK for AI agent / LLM cost observability. Locked attribute contract (no field sprawl). Framework coverage via optional OTel instrumentations — not Traceloop.

Install name: **`traceiq-capture`**. Import: **`import traceiq`**.

## Install

```bash
cd sdk
pip install -e .                 # installs package traceiq-capture
pip install -e ".[openai]"       # OpenAI auto-instrumentation
pip install -e ".[langchain]"    # LangChain / LangGraph
pip install -e ".[anthropic]"
pip install -e ".[llamaindex]"
pip install -e ".[all]"
pip install -e ".[dev]"          # pytest
```

## Quickstart

Set env (optional for local file export):

```bash
export TRACEIQ_API_KEY=...
export TRACEIQ_ENDPOINT=https://api.example.com   # omit → ./traces/
export TRACEIQ_APP_NAME=support-agent-api         # optional
export TRACEIQ_ENVIRONMENT=production             # optional
```

```python
import traceiq

traceiq.init()

# Existing OpenAI / LangChain / Anthropic / LlamaIndex code unchanged.
# Installed extras are auto-instrumented on init — no decorators required.
```

No `TRACEIQ_ENDPOINT` → spans written under `./traces/` for local debug. Batch export every **5s**; process exit flushes automatically (`flush()` is only needed in short scripts/tests).

## Optional: agent trees and attribution

Use decorators when you want a run root and step types. Use `set_context` when you want product / project / agent rollups.

```python
from traceiq import workflow, set_context

@workflow(name="triage_ticket")
def handle(ticket_id: str, user_msg: str):
    set_context(agent_name="triage", product_name="Pro")
    return run_agent(user_msg)
```

Also available: `@task`, `@tool`, `@agent`, `clear_context`.

## Frameworks

Install the matching extra; call `init()` once. LLM library calls emit child spans automatically.

| Stack | Extra |
|-------|-------|
| OpenAI | `[openai]` |
| Anthropic | `[anthropic]` |
| LangChain / LangGraph | `[langchain]` / `[langgraph]` |
| LlamaIndex | `[llamaindex]` |
| CrewAI | `[openai]` and/or `[langchain]` |

Decorators are optional — add `@workflow` on your entrypoint only if you want TraceIQ run identity around the call tree.

## Public API

`init`, `flush`, `set_context`, `clear_context`, `@workflow`, `@task`, `@tool`, `@agent`

## Export

- Default: OTLP/HTTP JSON → `{endpoint}/v1/otlp/v1/traces` (Bearer)
- Fallback: `export_mode="spans"` → `/v1/spans/batch`
- Batch every **5s** (`disable_batch=True` for sync scripts)

## Attributes (locked)

See build spec §3. Only allowlisted `traceiq.*` plus `gen_ai.system` / `gen_ai.request.model` / usage tokens. No prompt/completion content capture. No client-side pricing.

## Develop

```bash
pip install -e ".[dev]"
pytest
```

## License

MIT
