mirror of
https://github.com/zoriya/drizzle-otel.git
synced 2025-12-06 00:46:09 +00:00
Proprely handle errors with drizzle-otel
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
"@opentelemetry/sdk-trace-base": "^2.1.0",
|
||||
"@types/node": "18.15.11",
|
||||
"@types/pg": "^8.11.10",
|
||||
"drizzle-orm": "^0.36.4",
|
||||
"drizzle-orm": "^0.44.7",
|
||||
"postgres": "^3.4.7",
|
||||
"rimraf": "3.0.2",
|
||||
"typescript": "^5",
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
trace,
|
||||
type Span,
|
||||
} from "@opentelemetry/api";
|
||||
import { DrizzleQueryError } from "drizzle-orm";
|
||||
|
||||
const DEFAULT_TRACER_NAME = "@kubiks/otel-drizzle";
|
||||
const DEFAULT_DB_SYSTEM = "postgresql";
|
||||
@@ -130,7 +131,12 @@ function extractOperation(queryText: string): string | undefined {
|
||||
*/
|
||||
function finalizeSpan(span: Span, error?: unknown): void {
|
||||
if (error) {
|
||||
if (error instanceof Error) {
|
||||
if (error instanceof DrizzleQueryError && error.cause) {
|
||||
// special handling for node-postgres
|
||||
if ("detail" in error.cause && typeof error.cause.detail === "string")
|
||||
error.cause.stack = error.cause.detail;
|
||||
span.recordException(error.cause)
|
||||
} else if (error instanceof Error) {
|
||||
span.recordException(error);
|
||||
} else {
|
||||
span.recordException(new Error(String(error)));
|
||||
|
||||
Reference in New Issue
Block a user