Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

OpenTelemetry Knex Instrumentation for Node.js

NPM Published Version Apache License

This module provides automatic instrumentation for the knex module. This module allows the user to automatically collect trace data and export them to their backend of choice.

If total installation size is not constrained, it is recommended to use the @opentelemetry/auto-instrumentations-node bundle with @opentelemetry/sdk-node for the most seamless instrumentation experience.

Compatible with OpenTelemetry JS API and SDK 1.0+.

Installation

npm install --save @opentelemetry/instrumentation-knex

Supported Versions

  • knex versions >=0.10.0 <4

Usage

const { NodeSDK } = require('@opentelemetry/sdk-node');
const { KnexInstrumentation } = require('@opentelemetry/instrumentation-knex');

const sdk = new NodeSDK({
  instrumentations: [
    new KnexInstrumentation({
      // See below for configuration options.
    }),
  ],
});
sdk.start();
process.once('beforeExit', async () => { await sdk.shutdown(); });

Configuration Options

Options Type Example Description
maxQueryLength number 100 Truncate db.query.text attribute to a maximum length. If the statement is truncated '..' is added to its end. Default 1022. -1 leaves db.query.text untouched.
requireParentSpan boolean false Don't create spans unless they are part of an existing trace. Default is false.

Semantic Conventions

This instrumentation creates spans with database-related attributes.

The instrumentation-knex versions 0.64.0 and later emit the stable v1.33.0+ semantic conventions.

Attribute Short Description
db.collection.name The name of the primary table that the operation is acting upon.
db.namespace The name of the database being accessed.
db.operation.name The name of the operation being executed.
db.query.text The database statement being executed.
db.system.name An identifier for the database management system (DBMS) product being used.
server.address Remote hostname or similar.
server.port Remote port number.

Useful links

License

Apache 2.0 - See LICENSE for more information.