Files
TextNLPClassifierApp/tests/runtime/unit/test_langfuse_tracer.py
T

31 lines
1.1 KiB
Python

"""Unit tests for Langfuse tracer and offline queue covering OBS-001 to OBS-011."""
from pathlib import Path
from src.runtime.core.config import load_runtime_config
from src.runtime.observability.langfuse_tracer import LangfuseRuntimeTracer
from src.runtime.storage.sqlite_store import SQLiteStore
def test_tracer_offline_queues_to_sqlite(tmp_path: Path):
db_file = tmp_path / "obs.db"
store = SQLiteStore(db_file)
cfg = load_runtime_config("runtime_config.local.json")
tracer = LangfuseRuntimeTracer(cfg, store)
# Without keys configured, record_trace must safely queue to SQLite pending_telemetry
success = tracer.record_trace(
trace_id="tr_001",
fingerprint="a" * 64,
source_url="https://example.com",
status="completed_text",
spans_data={"validation": {"status": "SUCCESS"}},
generations=[],
metrics={"cost_usd": 0.001},
)
assert success is False # Queued offline
unflushed = store.get_unflushed_telemetry()
assert len(unflushed) == 1
assert unflushed[0]["fingerprint"] == "a" * 64