-
-
Notifications
You must be signed in to change notification settings - Fork 751
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
Better debugging for the ORM [WIP] #3996
base: beta
Are you sure you want to change the base?
Conversation
I think errors should definitely be try {
const res = await db.select().from(users);
} catch(e) {
if(e instanceof DrizzleErr) {
...
}
e.printStackTrace(); // is it java?
console.error(e);
} |
I also think we should wrap both this way we can have a typed error which will let developers handle errors exhaustively on type level } catch(e) {
if(e instanceof DrizzleError){
if(e.type === "io") { ... }
if(e.type === "sql") { ... }
assertUnreachable(e.type); // future proof, will show a type level error if we extend subset of errors. Opt-in for everybody
}
console.error(e);
} |
regarding profiling - there's an outstanding issues which Dan abandoned ~2 years ago and it's OpenTelemetry integration/compatibility, which we should potentially discuss and design before going into:
|
This is already possible, the examples use
This would be great to implement, but I haven't done so due to some drivers not providing the proper tools to distinguish between generic
You can see how difficult it could be to categorize errors by looking at the source code of the drivers mentioned above:
I'm not too familiar working with OpenTelemetry, but from some brief research, an integration with it could be it's entirely separate package (like Also, I think we can still have query execution time in logs. I personally have a small app in prod that would benefit from having a simple metric to determine query performance while keeping its codebase simple and not add additional packages (like OpenTelemetry). I feel like for a lot of people getting started, this can be a way to easily measure query performance. Larger codebases and apps would of course require something like OpenTelemetry, but I don't think that means that we should remove the simple query time execution logs altogether. An improvement I can definitely see is making it toggable, that way, you can avoid the tiny bit of overhead added by const db = drizzle('...', { logger: true, queryExecutionTime: false });
await db.select().from(users);
// Query: select * from "users"
const db = drizzle('...', { logger: true, queryExecutionTime: true });
await db.select().from(users);
// Query [250ms]: select * from "users" |
Addresses #376, #1957, #2414 & #2605.
This PR is WIP
Didn't mark it as draft as I'd like feedback on the API/implementation details for the work currently done before applying the same changes to other drivers and dialects.
This PR aims to implement improvements for the debugging experience, mainly improving error handling and logging.
Driver-agnostic errors
Previously, the way to handle query-related errors was dependent on the driver you used. Not the worst, but not the best. The shape of the error can be different depending on the driver and a lot of them don't have any way of identifying a query error (just thrown as a generic
Error
) and don't have type safety. We aim to improve this:Errors are now only dependent on the dialect you're using and are type safe. This only handles query-related errors though, other errors like connection issues will still come from the driver and/or DB provider.
Here's another example using the
getColumnNames
method provided by Drizzle:More customization for TransactionRollbackError
Improved logging
Example 1: Query fails
Logs:
Example 2: Query execution time for each operation
Logs:
Example 3: Better transaction logging. Includes where it begins, end and how long it took. Each query in a transaction can be identified by a randomly generated id/name.
Logs:
Example 4: Specifying a name for the logs
Logs:
Example 5: Rollback transaction
Logs:
Example 6: Error inside transaction
Logs:
Example 7: Nested transactions
Logs:
With all of these changes, there's also more methods you can implement in your logger:
Todo: