Libraries
    Preparing search index...

    Function instrumentKnex

    • 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({...})).

      Type Parameters

      • T extends Knex<any, any[]>

      Parameters

      • k: T

        the knex instance to instrument (mutated in place)

      • Optionaloptions: InstrumentKnexOptions

        optional overrides for db system, tracer name, redaction

      Returns T

      the same knex instance

      import knex from 'knex';
      import { instrumentKnex } from '@cleverbrush/otel';

      services.addSingleton(KnexToken, () =>
      instrumentKnex(
      knex({ client: 'pg', connection: dbUrl }),
      { dbSystem: 'postgresql' }
      )
      );