- Wrap your Drizzle database or underlying client
- Configure which query details are recorded
Overview
@monocle.sh/instrumentation-drizzle creates OpenTelemetry spans for Drizzle queries. Initialize your OpenTelemetry SDK or agent before creating the database, then wrap the Drizzle instance with instrumentDrizzleClient(). The instrumentation is opt-in and is not enabled automatically by the Monocle agent.
Installation
The package requires Drizzle ORM0.28.0 or later. Install your database driver separately. This example uses pg.
Terminal
Instrument your Drizzle database
Wrap the instance returned bydrizzle() before using it. Set dbSystem so Monocle can identify the database in query details.
app/services/database.ts
db.transaction, and query errors are recorded on their spans.
If you want to instrument the underlying client directly, use instrumentDrizzle() before passing the client to Drizzle:
app/services/database.ts
Configure query details
Pass these options to either instrumentation function:dbSystemidentifies the database, for examplepostgresql,mysql, orsqlite. It defaults tounknown.dbName,peerName, andpeerPortadd database name and connection details to spans.captureQueryTextincludes SQL statements in spans by default. Set it tofalseto omit SQL text.maxQueryTextLengthsets the maximum SQL statement length. It defaults to 1,000 characters.
CLIENT spans with database attributes such as the operation and table name when they can be read from the SQL statement. Transaction queries are marked with db.transaction.