Version: v0.3 (enterprise hardening + runtime wiring) Tagline: "Quality scores in your RAG traces — computed, not just recorded"
- Name: RAGWatch
- Purpose: OpenTelemetry-native RAG observability Python SDK with semantic quality scores
- Key Differentiator:
chunk_relevance_score+user.feedback_score— computed semantic quality - Instrumentation: Explicit decorators only (use OpenLLMetry for auto-instrumentation)
- RAG Types: Linear RAG (v0.1), multi-stage via composed decorators
- Efficiency: ~1-5 ms overhead per request
- Scope: SDK only. Users bring their own OTel backend.
- Install:
uv add ragwatch(recommended) orpip install ragwatch(core);uv add ragwatch --extra langgraphorpip install ragwatch[langgraph]
Explicit decorators only — no auto-instrumentation in v0.1.
| Layer | Instrumentation | Reason |
|---|---|---|
| LLM calls | None (use OpenLLMetry) | They do it better; compose via OTel |
| Embedding generation | Explicit | Query embedding stored for relevance score |
| Vector search / retrieval | Explicit | chunk_relevance_score computed here |
| User feedback | Explicit | record_feedback() is user-initiated |
| Agent nodes / workflows | Explicit | User decides span boundaries |
| Stage | Span Name | Key Attributes |
|---|---|---|
| Embedding | ragwatch.embedding.generate |
model.name, embedding.dimensions, duration_ms |
| Vector Search | ragwatch.retrieval.search |
top_k, chunks.returned, chunk.relevance_score |
| Response | ragwatch.response.emit |
response.length, user.feedback_score |
embedding.pycomputes query embedding → stores in OTelContext(not baggage)context.pymanagesContextVarstorage for query embeddingretrieval.pyreads context → computes cosine similarity → setschunk.relevance_score- Supported dimensions: up to 512-dim
- CHAIN: Root spans, orchestration
- AGENT: Nodes, pipeline steps
- TOOL: Shared functions
- RETRIEVER: Vector search
- EMBEDDING: Embedding generation
ragwatch/
├── __init__.py # Public API: configure, trace, record_feedback, RAGWatchConfig, SpanKind,
│ # TelemetryExtractor, ExtractorRegistry, SpanHook, FrameworkAdapter,
│ # AttributePolicy, validate_attribute_name
├── core/
│ ├── __init__.py
│ ├── config.py # RAGWatchConfig dataclass (incl. strict_mode, global_auto_track_io)
│ ├── tracer.py # TracerProvider setup + singleton
│ ├── runtime.py # RAGWatchRuntime scoped accessor
│ ├── span_kinds.py # SpanKind enum (OpenInference standard)
│ └── context.py # ContextVar context for query embedding
├── instrumentation/
│ ├── __init__.py
│ ├── decorators.py # @trace (sync + async, orchestration + failure isolation)
│ ├── extractors.py # TelemetryExtractor Protocol + ExtractorRegistry + 5 built-in extractors
│ ├── span_hooks.py # SpanHook Protocol + global/local hook lifecycle + on_error
│ ├── context_model.py # InstrumentationContext dataclass (passed to hooks)
│ ├── attributes.py # safe_set_attribute() centralized writer with policy enforcement
│ ├── result_transformers.py # ResultTransformer Protocol + Registry + built-in RETRIEVER/TOOL logic
│ ├── token_usage.py # TokenExtractor Protocol + registry + built-in usage_metadata scanner
│ ├── attribute_policy.py # Attribute naming validation, truncation, redaction
│ ├── io_tracker.py # Auto input.value/output.value with 4KB truncation (policy-driven)
│ ├── semconv.py # GenAI SemConv strings. SEMCONV_VERSION = "v1.40"
│ ├── helpers.py # record_chunks, record_routing, etc.
│ ├── embedding.py # SpanKind.EMBEDDING + context set
│ └── evaluators.py # chunk_relevance_score() + record_feedback()
└── adapters/
├── __init__.py
├── base.py # FrameworkAdapter Protocol + adapter registry
├── langgraph/
│ ├── __init__.py # from ragwatch.adapters.langgraph import node, workflow, LangGraphAdapter
│ ├── adapter.py # LangGraphAdapter (FrameworkAdapter impl)
│ └── decorators.py # @node (AGENT), @workflow (CHAIN), @tool (TOOL)
└── crewai/
├── __init__.py # from ragwatch.adapters.crewai import node, endpoint, CrewAIAdapter
├── adapter.py # CrewAIAdapter (FrameworkAdapter impl)
└── decorators.py # @node (AGENT), @endpoint (CHAIN)
examples/
├── minimal_rag.py
├── langgraph_agent.py
├── crewai_agent.py
├── custom_extensions.py # All v0.3 extension points demo
└── README.md
tests/
├── conftest.py
├── test_tracer.py
├── test_evaluators.py
├── test_context.py
├── test_io_tracker.py
├── test_decorators.py
├── test_extractors.py # Plugin registry + built-in extractors
├── test_span_hooks.py # SpanHook lifecycle (local + global)
├── test_adapter_contracts.py # FrameworkAdapter Protocol compliance + runtime wiring
├── test_attribute_policy.py # Schema validation + redaction + truncation + safe_set_attribute
├── test_failure_isolation.py # Failure isolation for hooks/extractors/transformers + strict_mode
├── test_context_model.py # InstrumentationContext + on_error hooks
├── test_pluggable_transforms.py # ResultTransformer + TokenExtractor + global_auto_track_io
├── test_runtime.py # RAGWatchRuntime scoped accessor
├── test_adapters_langgraph.py
├── test_adapters_crewai.py
├── test_integration.py
└── test_semconv.py
# ragwatch/__init__.py
from ragwatch import (
configure, trace, record_feedback, RAGWatchConfig, SpanKind,
# Plugin system
TelemetryExtractor, ExtractorRegistry, get_default_registry,
# Span hooks
SpanHook, register_global_hook,
# Adapter contracts
FrameworkAdapter, register_adapter,
# Attribute policy + centralized writer
AttributePolicy, validate_attribute_name,
safe_set_attribute, safe_set_attributes, get_active_config,
# Runtime
RAGWatchRuntime,
)
# ragwatch/adapters/langgraph/
from ragwatch.adapters.langgraph import node, workflow, LangGraphAdapter
# ragwatch/adapters/crewai/
from ragwatch.adapters.crewai import node, endpoint, CrewAIAdapterconfigure(config: RAGWatchConfig)— TracerProvider setup; users bring their own exportertrace(span_name, span_kind, auto_track_io, telemetry, result_formatter, span_hooks, adapter)— sync + async decoratorrecord_feedback(trace_id, score)—user.feedback_scoreon response spanRAGWatchConfig— configuration dataclass (incl.custom_extractors,global_span_hooks,adapters,attribute_policy,strict_mode,global_auto_track_io)SpanKind— OpenInference enum (CHAIN, AGENT, TOOL, RETRIEVER, EMBEDDING)
TelemetryExtractor— Protocol for pluggable telemetry extraction. Register viaget_default_registry().register()orconfigure(custom_extractors=[...]).SpanHook— Protocol withon_start(span, args, kwargs)/on_end(span, result)/on_error(span, exception). Hooks may accept an optionalcontext=kwarg to receiveInstrumentationContext. Per-decorator via@trace(span_hooks=[...])or global viaconfigure(global_span_hooks=[...]).FrameworkAdapter— Protocol withextract_state(args, kwargs)/default_extractors(). Register viaconfigure(adapters=[...]). Wired at runtime via@trace(adapter="name").AttributePolicy— Truncation (max_value_bytes), pattern-based redaction (redact_patterns), key-based redaction (redact_keys).validate_attribute_name(name)— Enforces dot-separated lowercase namespace convention, max 128 chars.safe_set_attribute()/safe_set_attributes()— Centralized attribute writer; enforces activeAttributePolicyon every write.InstrumentationContext— Dataclass passed to hooks with span, args, kwargs, adapter, raw_result, result, exception.ResultTransformer— Protocol for pluggable result transformation perSpanKind. Register viaget_default_transformer_registry().register().TokenExtractor— Protocol for pluggable token-usage extraction. Register viaregister_token_extractor().RAGWatchRuntime— Scoped read-only accessor for active config, registries, and policy.RAGWatchRuntime.current().
Default ON. Captures args → input.value, return → output.value. 4KB truncation. Disable per-decorator: @trace(..., auto_track_io=False). Disable globally: RAGWatchConfig(global_auto_track_io=False).
Extension errors (hooks, extractors, transformers) are caught, logged, and recorded as span events. Enable strict_mode=True in config to re-raise instead (for dev/test).
All decorators work on both async def and def.
| Layer | Choice | Version |
|---|---|---|
| Language | Python | 3.11+ |
| OTel SDK | opentelemetry-sdk | pinned 1.45.2 |
| OTel API | opentelemetry-api | pinned 1.45.2 |
| Packaging | pyproject.toml | — |
- Explicit decorators only — No auto-instrumentation; use OpenLLMetry for that
- semconv.py as single source of truth — AST-based CI guard
- Quality layer built-in —
chunk_relevance_scorevia Context — core differentiator - Users provide exporter — SDK doesn't bundle OTel backend
- Span links for non-linear flows — Agent loops/branches use links
- 2 adapters in v0.1 — LangGraph, CrewAI; Protocol-based contracts in v0.2
- OTel-native positioning — vs Langfuse/LangSmith: zero vendor lock-in
- OpenInference span kinds — open standard
- Auto I/O tracking — default ON; 4KB cap; disable per-decorator
- Semantic quality scores — computed, not just recorded
- Plugin architecture (v0.2) —
TelemetryExtractorregistry replaces hardcoded switchboard - Span lifecycle hooks (v0.2) —
SpanHookprotocol for custom attribute enrichment - Adapter contracts (v0.2) —
FrameworkAdapterprotocol formalises framework integrations - Attribute policy (v0.2) — Validation, truncation, and redaction for enterprise safety
- Adapter runtime wiring (v0.3) —
@trace(adapter=...)drivesextract_state()at call time - Centralized attribute writer (v0.3) —
safe_set_attribute()enforcesAttributePolicyon every write - Failure isolation (v0.3) — Extension errors caught, logged, span-evented;
strict_modefor dev - InstrumentationContext (v0.3) — Unified context object threaded through all extension points
- on_error hooks (v0.3) —
SpanHook.on_error(span, exception)called on decorated-function exceptions - Pluggable result transformation (v0.3) —
ResultTransformerprotocol + per-SpanKind registry - Pluggable token extraction (v0.3) —
TokenExtractorprotocol + registry - Policy-driven I/O (v0.3) —
global_auto_track_ioconfig toggle; all writes viasafe_set_attribute - RAGWatchRuntime (v0.3) — Scoped accessor reducing reliance on module-level globals