$ show future-agi/traceAI
TraceAI is a multi-language (Python, TypeScript, Java, C#) OpenTelemetry-based instrumentation SDK for AI/LLM applications. It provides drop-in auto-instrumentation for 50+ LLM providers, agent frameworks (LangChain, LlamaIndex, CrewAI, AutoGen, etc.), and vector databases (Pinecone, ChromaDB, Qdrant, etc.). The core library wraps SDK calls to capture structured spans with semantic attributes (tokens, model, messages, tool calls) and exports them via OTLP to any OpenTelemetry-compatible backend, with a default hosted backend at Future AGI. The architecture is a monorepo with per-framework packages that follow a consistent instrumentor pattern: register a tracer provider, instrument the target library, then make API calls. Key entry points are `register()` (Python/TypeScript), `TraceAI.init()` (Java), and `TraceAI.Register()` (C#). The SDK also includes context attribute propagation, PII redaction, evaluation tags, and configurable masking. While the codebase is well-structured and actively maintained, there is significant duplication across framework instrumentors and some tests rely on heavy mocking, which limits reusability of individual components.
The LLM identified 5 files worth highlighting for reuse:
TraceConfig is an immutable dataclass that centralizes all tracing configuration: API key, base URL, project type, and masking rules (hide inputs/outputs, images, embeddings). It reads from environment variables with sensible defaults and provides a callable masking function. This component is self-contained and could be extracted as a standalone configuration library for any OTel-based instrumentation SDK.
Provides FiSpanKind and helper functions to map internal span kinds (LLM, CHAIN, AGENT, TOOL, VECTOR_DB, EMBEDDING) to OpenTelemetry semantic conventions. Includes attribute filtering logic to respect TraceConfig masking. This module is a clean abstraction layer between the SDK's internal span model and OTel's span API, reusable in any OTel-based instrumentation project.
Implements PII redaction for common patterns (email, SSN, credit card, IP, API key) using regex replacement. Provides a `redact_pii` function that can be applied to span attributes. This is a self-contained utility that could be reused in any data masking pipeline, not just tracing.
GoogleADKInstrumentor demonstrates a sophisticated version-aware patching pattern. It uses `_PassthroughTracer` and `_SelectiveExecuteToolTracer` proxy objects to avoid duplicate spans when the ADK already creates its own traces. This pattern of conditional instrumentation based on library version is reusable for any framework that may have built-in tracing.
Provides `safe_json_dumps`, `safe_serialize`, and `_to_dict` utilities for safely converting complex objects (including Pydantic models, dataclasses, and nested structures) to JSON with truncation of long strings. These are generic data serialization helpers that could be extracted and used in any Python project needing safe JSON conversion.