diff --git a/lib/connectionattributes.ts b/lib/connectionattributes.ts index f83aef29..831f1f57 100644 --- a/lib/connectionattributes.ts +++ b/lib/connectionattributes.ts @@ -7,6 +7,7 @@ import { } from '@opentelemetry/semantic-conventions'; import type { Knex } from 'knex'; +// eslint-disable-next-line sonarjs/function-return-type function findAttribute(where: Record, keys: string[]): AttributeValue | undefined { for (const key of keys) { const value = where[key]; diff --git a/lib/knex.ts b/lib/knex.ts index a175a0e3..3d03d9e0 100644 --- a/lib/knex.ts +++ b/lib/knex.ts @@ -97,10 +97,11 @@ export class KnexInstrumentation extends InstrumentationBase { span.setStatus({ code: SpanStatusCode.OK }).end(); return result; }, - (e: Error) => { - span.recordException(e); + (e: unknown) => { + const err = e instanceof Error ? e : new Error(String(e), { cause: e }); + span.recordException(err); span.setStatus({ code: SpanStatusCode.ERROR }).end(); - throw e; + throw err; }, ); }; diff --git a/test/index.spec.ts b/test/index.spec.ts index 22cce72e..d43e5199 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable sonarjs/no-nested-functions */ import { SpanStatusCode, context, trace } from '@opentelemetry/api'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { SEMATTRS_DB_NAME, SEMATTRS_DB_STATEMENT, SEMATTRS_DB_SYSTEM } from '@opentelemetry/semantic-conventions';