Neuraltrust SDK
Python SDK for instrumenting AI agent libraries to send telemetry to the Neuraltrust platform.
Features
- 🔌 OpenAI Agents SDK integration via custom trace processor
- 📊 Automatic span capture: LLM calls, tool executions, agent runs, handoffs, guardrails
- 🚀 Async batching transport with exponential backoff and retry logic
- 🎯 Sampling support for high-volume production workloads
- 🔧 Configurable via environment variables or programmatic config
- 🧪 Local test server included for development
Installation
Install the SDK using pip:
pip install neuraltrust
Or with uv:
uv add neuraltrust
Quick Start (OpenAI Agents)
from agents import Agent, Runner
from neuraltrust import register_openai_tracing
# Register the Neuraltrust trace processor
register_openai_tracing()
# Your agent code runs normally
agent = Agent(name="Assistant", instructions="You are helpful")
result = await Runner.run(agent, "Hello!")
Configuration
Environment Variables
# Required
export NEURALTRUST_API_KEY=your-api-key
# Optional
export NEURALTRUST_ENDPOINT=https://telemetry.neuraltrust.ai/v1/traces/batch
export NEURALTRUST_BATCH_SIZE=25
export NEURALTRUST_FLUSH_INTERVAL=2.0
export NEURALTRUST_TIMEOUT=5.0
export NEURALTRUST_MAX_RETRIES=3
export NEURALTRUST_SAMPLING_RATE=1.0
# Custom metadata (any NEURALTRUST_METADATA_* vars)
export NEURALTRUST_METADATA_ENVIRONMENT=production
export NEURALTRUST_METADATA_VERSION=1.2.3
Programmatic Configuration
from neuraltrust import TelemetryConfig, register_openai_tracing
config = TelemetryConfig(
api_key="your-api-key",
endpoint="https://telemetry.neuraltrust.ai/v1/traces/batch",
batch_size=25,
flush_interval_seconds=2.0,
sampling_rate=0.1, # Sample 10% of traces
metadata={"environment": "staging", "version": "2.0.0"},
)
register_openai_tracing(config=config, replace_default=True)
Replace Default Exporters
By default, the SDK adds Neuraltrust telemetry in addition to OpenAI's default trace exporter. To disable OpenAI's exporter and send traces only to Neuraltrust:
register_openai_tracing(replace_default=True)
Or via environment variable:
export NEURALTRUST_REPLACE_DEFAULT=1
Development & Testing
Local Test Server
Start the included test API server:
uv run uvicorn examples.api.temp_server:app --host 127.0.0.1 --port 8000
Configure your SDK to point to it:
export NEURALTRUST_ENDPOINT=http://127.0.0.1:8000/v1/traces/batch
export NEURALTRUST_API_KEY=dummy
export NEURALTRUST_REPLACE_DEFAULT=1
Run the example:
uv run python examples/openai_agents/basic.py "your message here"
Inspect captured traces:
curl http://127.0.0.1:8000/v1/traces | jq
Reset stored traces:
curl -X DELETE http://127.0.0.1:8000/v1/traces
Trace Data Structure
Each trace envelope contains:
- Resource metadata: SDK version, language, library name/version
- Traces: One or more logical workflows
trace_id: Unique identifierworkflow_name: Human-readable workflow namegroup_id: Optional grouping (e.g., chat session ID)started_at/ended_at: Unix timestampsattributes: Key-value metadata- Spans: Individual operations within the trace
id: Unique span identifierparent_id: Parent span (null for root)name: Operation name (e.g., "Echo", "Response", "translate_to_french")kind: Span type (workflow,llm,tool,guardrail,handoff)status: Execution status (ok,error)started_at/ended_at: Unix timestampsattributes: Span-specific metadata (model, usage tokens, I/O, etc.)events: Time-stamped events within the span
Backend API Specification
See docs/backend/endpoints.md for the complete backend API specification, including:
POST /v1/traces/batch: Batch trace ingestionGET /v1/traces/{trace_id}: Retrieve trace by IDPOST /v1/traces/heartbeat: Client health check- Authentication, error codes, retry logic
Span Attributes
LLM Spans (kind=llm)
model: Model identifier (e.g.,gpt-4o-mini-2024-07-18)response_model,response_output: Response datausage_input_tokens,usage_output_tokens,usage_total_tokens: Token countstemperature: Sampling temperature
Tool/Function Spans (kind=tool)
function_name: Name of the tool/functionfunction_input: Serialized input argumentsfunction_output: Serialized output
Workflow/Agent Spans (kind=workflow)
agent_tools: Available toolsagent_handoffs: Available handoff targetsagent_output_type: Expected output type
Guardrail Spans (kind=guardrail)
guardrail_triggered: Whether the guardrail was triggered
Handoff Spans (kind=handoff)
handoff_from: Source agenthandoff_to: Target agent
Architecture
┌─────────────────────────────────────────────┐
│ OpenAI Agents SDK │
│ ├─ Agent runs │
│ ├─ LLM generations │
│ └─ Tool calls │
└──────────────┬──────────────────────────────┘
│ TracingProcessor interface
▼
┌─────────────────────────────────────────────┐
│ NeuraltrustTraceProcessor │
│ ├─ Buffers spans per trace │
│ ├─ Extracts span_data attributes │
│ └─ Emits TraceEnvelope on trace end │
└──────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ TelemetryClient │
│ ├─ Sampling │
│ └─ Async envelope queueing │
└──────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ TelemetryTransport │
│ ├─ Background flush loop │
│ ├─ Batching (default: 25 items) │
│ ├─ Exponential backoff retry │
│ └─ HTTP POST with Bearer auth │
└──────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ Neuraltrust Telemetry API │
│ POST /v1/traces/batch │
└─────────────────────────────────────────────┘
Debugging
Enable debug logging to see trace/span lifecycle events:
import logging
logging.basicConfig(level=logging.DEBUG)
Or via environment:
export LOG_LEVEL=DEBUG
Key log messages:
Trace started; trace_id=...Span ended; span_id=... stored_spans=NTrace envelope prepared; trace_id=... span_count=NTelemetry batch sent; items=N status=202
Future Roadmap
- LangChain integration
- LlamaIndex integration
- CrewAI integration
- OpenTelemetry exporter
- Prometheus metrics
- Local SQLite storage option
License
MIT
Metadata
Release files for neuraltrust 1.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neuraltrust-1.5.0.tar.gz | 16.5 kB | Without provenance | Details for neuraltrust-1.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neuraltrust-1.5.0-py3-none-any.whl | Python 3 | none | any | Details for neuraltrust-1.5.0-py3-none-any.whl |
Total release size: 31.1 kB
Release files / neuraltrust-1.5.0.tar.gz
| Download URL | neuraltrust-1.5.0.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
699423c48852c27ea8cef28641f6938c644fd9a0e8cfa72f57272444d3ffeefb
|
|
BLAKE2b-256 checksum How to use checksums |
01f59d762d48365a87177f3614d6cc1bf46c07ca47ad28005b85c01bb4146d47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / neuraltrust-1.5.0-py3-none-any.whl
| Download URL | neuraltrust-1.5.0-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ca75cc3086b105ab4d2d9ee269ffae9cd790ab25a43b8ae95f13f60cff8cb8e
|
|
BLAKE2b-256 checksum How to use checksums |
0c818f3a12cdfce941c597fb2eb5edd98ff166f53396a8aaed78aa2c676c0b63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for neuraltrust 1.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.