Skip to main content

Production observability SDK for LLM apps and LangChain agents with OpenTelemetry-style tracing and low-friction callbacks.

Project description

TraceOtter Python SDK

License PyPI PyPI - Downloads Python

The TraceOtter Python SDK for LLM/agent observability.

It records traces for chains, tools, retrieval, and generations, and sends them to TraceOtter.

Built with batching, retries, and flush-on-exit to help you debug, monitor, and track quality and cost over time.

Installation

Requires Python 3.11+ (see requires-python in pyproject.toml).

pip install traceotter

Quick Start (LangChain)

1) Configure credentials

export TRACEOTTER_API_KEY="to_your_api_key"
export TRACEOTTER_HOST="https://api.traceotter.com"  # optional

2) Attach TraceOtter callback to your chain/agent

from traceotter import get_client
from traceotter.langchain import CallbackHandler
from langchain_openai import ChatOpenAI

# Singleton client with background batching + flush
client = get_client()
traceotter_handler = CallbackHandler()

llm = ChatOpenAI(model="gpt-4o-mini")
result = llm.invoke(
    "Write a haiku about observability.",
    config={"callbacks": [traceotter_handler]},
)
print(result.content)

Real Agent Example (Tool + ReAct)

from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain_core.prompts import PromptTemplate
from langchain_core.tools import tool

from traceotter.langchain import CallbackHandler

@tool
def add_numbers(expression: str) -> int:
    import re
    nums = [int(x) for x in re.findall(r"-?\d+", expression)]
    if len(nums) < 2:
        raise ValueError(f"Expected two numbers, got: {expression}")
    return nums[0] + nums[1]

llm = ChatOpenAI(model="gpt-4o-mini")
handler = CallbackHandler()

prompt = PromptTemplate.from_template(
    """Answer the question using tools when needed.

Question: {input}
Thought:{agent_scratchpad}"""
)

agent = create_react_agent(llm=llm, tools=[add_numbers], prompt=prompt)
executor = AgentExecutor(agent=agent, tools=[add_numbers])

result = executor.invoke(
    {"input": "What is 4232 + 5000?"},
    config={"callbacks": [handler]},
)
print(result)

Runtime Behavior

  • Automatic batching: spans are buffered and exported in batches.
  • Safe shutdown flush: pending spans flush on process exit.
  • Retries: HTTP ingestion retries transient failures.
  • Fallback mode: without TraceOtter credentials, spans are exported to console for local debugging.

Environment Variables

  • TRACEOTTER_API_KEY: required for remote ingest (to_...)
  • TRACEOTTER_HOST: API base URL (default: https://api.traceotter.com)
  • TRACEOTTER_TIMEOUT: request timeout seconds (default: 5)
  • TRACEOTTER_FLUSH_AT: max spans per flush batch
  • TRACEOTTER_FLUSH_INTERVAL: periodic flush interval in seconds
  • OTEL_BSP_MAX_EXPORT_BATCH_SIZE: optional OpenTelemetry-style alias for batch size (used if TRACEOTTER_FLUSH_AT is not set)
  • OTEL_BSP_SCHEDULE_DELAY: optional OpenTelemetry-style alias for flush interval in milliseconds (used if TRACEOTTER_FLUSH_INTERVAL is not set)
  • TRACEOTTER_USE_GRPC: set true/1/yes to enable gRPC target resolution
  • TRACEOTTER_GRPC_PORT: gRPC port (default: 50051)

Note: OPENAI_API_KEY is not a TraceOtter SDK variable; it is required only by the LangChain/OpenAI examples.

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

traceotter-0.2.6.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

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

traceotter-0.2.6-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file traceotter-0.2.6.tar.gz.

File metadata

  • Download URL: traceotter-0.2.6.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for traceotter-0.2.6.tar.gz
Algorithm Hash digest
SHA256 577f00624034b06fb61dd0e53d0494d6be1c2e6425548c101b291adb68137ace
MD5 4b5eae0226b104ea1dd9b4a1fde38fbd
BLAKE2b-256 2abb1b8954c32ab3cae90135b6bd8dda18bcc4823c67f26124fe7502f338a346

See more details on using hashes here.

File details

Details for the file traceotter-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: traceotter-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for traceotter-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0d4b8d2d7814ba53a36049b29bed4f9a411c98172f0cc12d6cc326f28349fb3b
MD5 cc44a9fdf09f3b5840b473d208091a51
BLAKE2b-256 6a320b81fb79b541313fa8e9779318ffa696fd35fbc597fe9539720817cddd68

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