Open
Conversation
375b187 to
0ae9a84
Compare
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.