data-context-hq / datacontext
PublicOpen-source runtime attribution and context observability for data access by AI agents and applications
DataContext is a Python library that helps developers understand which user requests, background jobs, or code paths triggered specific database queries. It works by wrapping your existing database code to automatically capture query events with information about where the query came from, how long it took, and what context was active. Events include details like the service name, database type, query fingerprint, and the full call stack showing which functions led to the query. You can also attach custom labels like user IDs, request IDs, or tenant names so every query carries that context. Events are sent to your choice of destination—console, file, custom handler, or OpenTelemetry—without changing your application behavior or blocking your code.
How It Works
Your database logs show queries, but you can't tell which user request or code path triggered them.
You install DataContext with a simple command, and optionally add support for SQLAlchemy or OpenTelemetry.
You tell DataContext your service name and environment, like naming your app 'checkout-api' in 'production'.
You point DataContext at your database code, and it automatically watches every query that runs.
You wrap your business logic with labels like 'checkout', 'user:123', or 'req_abc' so queries carry that information.
Simple output that writes events as JSON lines to stdout or a log file.
Send events to your own handler, data warehouse, or analytics system.
Connect to your existing tracing system to correlate queries with other spans.
For any query in your logs, you now know exactly which request, user, and code path caused it.
Star Growth
Repurpose is a Pro feature
Generate ready-to-use prompts for X threads, LinkedIn posts, blog posts, YouTube scripts, and more -- with full repo context baked in.
Unlock RepurposeSimilar repos coming soon.