-
Notifications
You must be signed in to change notification settings - Fork 44
feat: Add tracing channels support #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
375b187 to
0ae9a84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Node.js tracing channels support to db0, enabling observability and performance monitoring for database query operations. The implementation follows an opt-in approach where users must explicitly wrap their database instance with withTracing() to enable tracing.
Key Changes:
- Introduces
withTracing()wrapper function that instruments database operations with Node.js diagnostic channels - Adds comprehensive test coverage for all traced database operations (exec, sql, prepare.all, prepare.run, prepare.get)
- Exports tracing functionality and types through the main index
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/tracing.ts | Implements the core tracing functionality with withTracing() wrapper and channel management for db query operations |
| test/tracing.test.ts | Provides comprehensive test coverage for tracing behavior including opt-in verification, success/error scenarios, and query reconstruction |
| src/index.ts | Exports the new tracing API (withTracing, TraceContext, TracedOperation) for public consumption |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds Node.js tracing channels for db query operations, enabling observability and performance monitoring.
Channel Naming Convention
All channels use the
db0.queryconvention which when coupled with tracing channels produce the following diagnostic channels:tracing:db0.query:starttracing:db0.query:endtracing:db0.query:asyncStarttracing:db0.query:asyncEndtracing:db0.query:errorWhich matches nicely with
fastifybut there isn't a lot of convention for them other than the Node.js recommendation.Unlike
unstorageit didn't feel like we need multiple channels since more or less it boils down to executing a query.Tracing context includes
query- query to be executedmethod- source of the query likesqlorexec, basically the method name.dialect- the db dialectExample
I have made it so it is opt-in like
unstorage.Users can create traced instances like so:
SDKs and consumers can then do:
All operations emit standard tracing events:
start,end,asyncStart,asyncEnd, anderror.