import type { Knex } from 'knex'; /** * Configuration for {@link instrumentKnex}. */ export interface InstrumentKnexOptions { /** * Value to record as `db.system.name` (e.g. `postgresql`, `mysql`, * `sqlite`). When omitted, inferred from the knex client. */ dbSystem?: string; /** * Tracer name used when resolving the OTel tracer. * * @default '@cleverbrush/otel/knex' */ tracerName?: string; /** * Whether to include the SQL statement as `db.query.text`. * * The statement is taken verbatim from knex (parameter placeholders * are kept; bound values are **not** included). Disable if your * SQL itself may contain sensitive identifiers. * * @default true */ recordStatement?: boolean; /** * Optional hook to redact / rewrite the SQL before it is recorded. * Called only when {@link recordStatement} is enabled. */ sanitizeStatement?: (sql: string) => string; } /** * Instruments a Knex instance to emit an OpenTelemetry `CLIENT` span * for every executed query. * * Hooks knex's built-in `query`, `query-response`, and `query-error` * events — every dbset read, change-tracker write, save-graph, and raw * `knex(...)` call is captured uniformly because they all flow through * the same knex instance. * * Spans automatically nest under any ambient OTel context, so DB spans * become children of the enclosing HTTP server span produced by * `tracingMiddleware`. * * Returns the same instance for fluent chaining: * `instrumentKnex(knex({...}))`. * * @param k - the knex instance to instrument (mutated in place) * @param options - optional overrides for db system, tracer name, redaction * @returns the same knex instance * * @example * ```ts * import knex from 'knex'; * import { instrumentKnex } from '@cleverbrush/otel'; * * services.addSingleton(KnexToken, () => * instrumentKnex( * knex({ client: 'pg', connection: dbUrl }), * { dbSystem: 'postgresql' } * ) * ); * ``` */ export declare function instrumentKnex(k: T, options?: InstrumentKnexOptions): T;