or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ai-service-integrations.mdcontext-management.mddatabase-integrations.mderror-capture.mdfeature-flags-integrations.mdframework-integrations.mdindex.mdinitialization.mdmonitoring-sessions.mdnodejs-integrations.mdperformance-monitoring.md

database-integrations.mddocs/

0

# Database Integrations

1

2

Comprehensive database instrumentation for MongoDB, PostgreSQL, MySQL, Redis, Prisma, and more.

3

4

## Capabilities

5

6

### MongoDB Integration

7

8

Automatic instrumentation for MongoDB operations.

9

10

```typescript { .api }

11

/**

12

* Create MongoDB integration for automatic database operation tracing

13

* @param options - MongoDB integration configuration options

14

* @returns MongoDB integration instance

15

*/

16

function mongoIntegration(options?: MongoOptions): Integration;

17

18

/**

19

* Create Mongoose integration for MongoDB ODM tracing

20

* @param options - Mongoose integration configuration options

21

* @returns Mongoose integration instance

22

*/

23

function mongooseIntegration(options?: MongooseOptions): Integration;

24

```

25

26

**Usage Examples:**

27

28

```typescript

29

import * as Sentry from "@sentry/node";

30

import { MongoClient } from "mongodb";

31

import mongoose from "mongoose";

32

33

// Initialize with MongoDB integrations

34

Sentry.init({

35

dsn: "YOUR_DSN",

36

integrations: [

37

Sentry.mongoIntegration({

38

operations: ["find", "insert", "update", "delete"], // Operations to trace

39

captureQueries: true, // Include query details in spans

40

}),

41

Sentry.mongooseIntegration({

42

captureQueries: true,

43

}),

44

],

45

});

46

47

// MongoDB native driver - automatically traced

48

const client = new MongoClient("mongodb://localhost:27017");

49

await client.connect();

50

const db = client.db("myapp");

51

52

// These operations will create spans

53

const users = await db.collection("users").find({ active: true }).toArray();

54

await db.collection("users").insertOne({ name: "John", email: "john@example.com" });

55

56

// Mongoose - automatically traced

57

await mongoose.connect("mongodb://localhost:27017/myapp");

58

59

const UserSchema = new mongoose.Schema({

60

name: String,

61

email: String,

62

active: Boolean,

63

});

64

const User = mongoose.model("User", UserSchema);

65

66

// These operations will create spans

67

const activeUsers = await User.find({ active: true });

68

const newUser = await User.create({ name: "Jane", email: "jane@example.com" });

69

```

70

71

### PostgreSQL Integration

72

73

Automatic instrumentation for PostgreSQL operations.

74

75

```typescript { .api }

76

/**

77

* Create PostgreSQL integration using pg driver

78

* @param options - PostgreSQL integration configuration options

79

* @returns PostgreSQL integration instance

80

*/

81

function postgresIntegration(options?: PostgresOptions): Integration;

82

83

/**

84

* Create Postgres.js integration

85

* @param options - Postgres.js integration configuration options

86

* @returns Postgres.js integration instance

87

*/

88

function postgresJsIntegration(options?: PostgresJsOptions): Integration;

89

```

90

91

**Usage Examples:**

92

93

```typescript

94

import * as Sentry from "@sentry/node";

95

import { Pool } from "pg";

96

import postgres from "postgres";

97

98

// Initialize with PostgreSQL integrations

99

Sentry.init({

100

dsn: "YOUR_DSN",

101

integrations: [

102

Sentry.postgresIntegration({

103

captureQueries: true, // Include SQL queries in spans

104

maxQueryLength: 1000, // Maximum query length to capture

105

}),

106

Sentry.postgresJsIntegration({

107

captureQueries: true,

108

}),

109

],

110

});

111

112

// pg driver - automatically traced

113

const pool = new Pool({

114

user: "dbuser",

115

host: "localhost",

116

database: "myapp",

117

password: "secret",

118

port: 5432,

119

});

120

121

// These queries will create spans

122

const result = await pool.query("SELECT * FROM users WHERE active = $1", [true]);

123

await pool.query("INSERT INTO users (name, email) VALUES ($1, $2)", ["John", "john@example.com"]);

124

125

// postgres.js - automatically traced

126

const sql = postgres("postgres://username:password@localhost/database");

127

128

// These queries will create spans

129

const users = await sql`SELECT * FROM users WHERE active = ${true}`;

130

await sql`INSERT INTO users ${sql({ name: "Jane", email: "jane@example.com" })}`;

131

```

132

133

### MySQL Integration

134

135

Automatic instrumentation for MySQL operations.

136

137

```typescript { .api }

138

/**

139

* Create MySQL integration using mysql driver

140

* @param options - MySQL integration configuration options

141

* @returns MySQL integration instance

142

*/

143

function mysqlIntegration(options?: MysqlOptions): Integration;

144

145

/**

146

* Create MySQL2 integration using mysql2 driver

147

* @param options - MySQL2 integration configuration options

148

* @returns MySQL2 integration instance

149

*/

150

function mysql2Integration(options?: Mysql2Options): Integration;

151

```

152

153

**Usage Examples:**

154

155

```typescript

156

import * as Sentry from "@sentry/node";

157

import mysql from "mysql";

158

import mysql2 from "mysql2/promise";

159

160

// Initialize with MySQL integrations

161

Sentry.init({

162

dsn: "YOUR_DSN",

163

integrations: [

164

Sentry.mysqlIntegration({

165

captureQueries: true,

166

}),

167

Sentry.mysql2Integration({

168

captureQueries: true,

169

maxQueryLength: 1000,

170

}),

171

],

172

});

173

174

// mysql driver - automatically traced

175

const connection = mysql.createConnection({

176

host: "localhost",

177

user: "me",

178

password: "secret",

179

database: "my_db",

180

});

181

182

// These queries will create spans

183

connection.query("SELECT * FROM users WHERE active = ?", [1], (error, results) => {

184

if (error) throw error;

185

console.log(results);

186

});

187

188

// mysql2 driver - automatically traced

189

const connection2 = await mysql2.createConnection({

190

host: "localhost",

191

user: "root",

192

password: "password",

193

database: "test",

194

});

195

196

// These queries will create spans

197

const [rows] = await connection2.execute("SELECT * FROM users WHERE active = ?", [1]);

198

await connection2.execute("INSERT INTO users (name, email) VALUES (?, ?)", ["John", "john@example.com"]);

199

```

200

201

### Redis Integration

202

203

Automatic instrumentation for Redis operations.

204

205

```typescript { .api }

206

/**

207

* Create Redis integration for automatic Redis operation tracing

208

* @param options - Redis integration configuration options

209

* @returns Redis integration instance

210

*/

211

function redisIntegration(options?: RedisOptions): Integration;

212

213

/**

214

* Create IORedis integration for automatic Redis operation tracing using ioredis

215

* @param options - IORedis integration configuration options

216

* @returns IORedis integration instance

217

*/

218

function ioredisIntegration(options?: IoredisOptions): Integration;

219

```

220

221

**Usage Examples:**

222

223

```typescript

224

import * as Sentry from "@sentry/node";

225

import { createClient } from "redis";

226

227

// Initialize with Redis integration

228

Sentry.init({

229

dsn: "YOUR_DSN",

230

integrations: [

231

Sentry.redisIntegration({

232

captureCommands: true, // Include Redis commands in spans

233

maxCommandLength: 100, // Maximum command length to capture

234

}),

235

],

236

});

237

238

// Redis client - automatically traced

239

const client = createClient({

240

url: "redis://localhost:6379",

241

});

242

243

client.on("error", (err) => console.log("Redis Client Error", err));

244

await client.connect();

245

246

// These operations will create spans

247

await client.set("key", "value");

248

const value = await client.get("key");

249

await client.hSet("user:123", { name: "John", email: "john@example.com" });

250

const user = await client.hGetAll("user:123");

251

```

252

253

### Prisma Integration

254

255

Automatic instrumentation for Prisma ORM operations.

256

257

```typescript { .api }

258

/**

259

* Create Prisma integration for automatic ORM operation tracing

260

* @param options - Prisma integration configuration options

261

* @returns Prisma integration instance

262

*/

263

function prismaIntegration(options?: PrismaOptions): Integration;

264

```

265

266

**Usage Examples:**

267

268

```typescript

269

import * as Sentry from "@sentry/node";

270

import { PrismaClient } from "@prisma/client";

271

272

// Initialize with Prisma integration

273

Sentry.init({

274

dsn: "YOUR_DSN",

275

integrations: [

276

Sentry.prismaIntegration({

277

captureQueries: true, // Include SQL queries in spans

278

}),

279

],

280

});

281

282

// Prisma client - automatically traced

283

const prisma = new PrismaClient();

284

285

// These operations will create spans

286

const users = await prisma.user.findMany({

287

where: { active: true },

288

});

289

290

const newUser = await prisma.user.create({

291

data: {

292

name: "John",

293

email: "john@example.com",

294

active: true,

295

},

296

});

297

298

await prisma.user.update({

299

where: { id: newUser.id },

300

data: { active: false },

301

});

302

```

303

304

### SQL Server Integration

305

306

Automatic instrumentation for SQL Server operations using Tedious.

307

308

```typescript { .api }

309

/**

310

* Create Tedious integration for SQL Server tracing

311

* @param options - Tedious integration configuration options

312

* @returns Tedious integration instance

313

*/

314

function tediousIntegration(options?: TediousOptions): Integration;

315

```

316

317

**Usage Examples:**

318

319

```typescript

320

import * as Sentry from "@sentry/node";

321

import { Connection, Request } from "tedious";

322

323

// Initialize with Tedious integration

324

Sentry.init({

325

dsn: "YOUR_DSN",

326

integrations: [

327

Sentry.tediousIntegration({

328

captureQueries: true,

329

}),

330

],

331

});

332

333

// Tedious connection - automatically traced

334

const config = {

335

server: "localhost",

336

authentication: {

337

type: "default",

338

options: {

339

userName: "username",

340

password: "password",

341

},

342

},

343

options: {

344

database: "mydatabase",

345

encrypt: true,

346

},

347

};

348

349

const connection = new Connection(config);

350

351

// These queries will create spans

352

const request = new Request("SELECT * FROM users WHERE active = @active", (err, rowCount) => {

353

if (err) {

354

console.error(err);

355

} else {

356

console.log(`${rowCount} rows returned`);

357

}

358

});

359

360

request.addParameter("active", TYPES.Bit, true);

361

connection.execSql(request);

362

```

363

364

### Knex.js Integration

365

366

Automatic instrumentation for Knex.js query builder.

367

368

```typescript { .api }

369

/**

370

* Create Knex.js integration for query builder tracing

371

* @param options - Knex integration configuration options

372

* @returns Knex integration instance

373

*/

374

function knexIntegration(options?: KnexOptions): Integration;

375

```

376

377

**Usage Examples:**

378

379

```typescript

380

import * as Sentry from "@sentry/node";

381

import knex from "knex";

382

383

// Initialize with Knex integration

384

Sentry.init({

385

dsn: "YOUR_DSN",

386

integrations: [

387

Sentry.knexIntegration({

388

captureQueries: true,

389

}),

390

],

391

});

392

393

// Knex instance - automatically traced

394

const db = knex({

395

client: "postgresql",

396

connection: {

397

host: "localhost",

398

port: 5432,

399

user: "username",

400

password: "password",

401

database: "myapp",

402

},

403

});

404

405

// These queries will create spans

406

const users = await db("users").where("active", true).select("*");

407

await db("users").insert({ name: "John", email: "john@example.com" });

408

await db("users").where("id", 1).update({ active: false });

409

```

410

411

### Additional Database Integrations

412

413

Additional database and connection pool integrations for specialized use cases.

414

415

```typescript { .api }

416

/**

417

* Create Generic Pool integration for connection pool tracing

418

* @param options - Generic Pool integration configuration options

419

* @returns Generic Pool integration instance

420

*/

421

function genericPoolIntegration(options?: GenericPoolOptions): Integration;

422

423

/**

424

* Create Dataloader integration for automatic batching and caching tracing

425

* @param options - Dataloader integration configuration options

426

* @returns Dataloader integration instance

427

*/

428

function dataloaderIntegration(options?: DataloaderOptions): Integration;

429

430

/**

431

* Create AMQP integration for RabbitMQ message queue tracing

432

* @param options - AMQP integration configuration options

433

* @returns AMQP integration instance

434

*/

435

function amqplibIntegration(options?: AmqplibOptions): Integration;

436

```

437

438

**Usage Examples:**

439

440

```typescript

441

import * as Sentry from "@sentry/node";

442

import DataLoader from "dataloader";

443

import amqp from "amqplib";

444

445

// Initialize with additional integrations

446

Sentry.init({

447

dsn: "YOUR_DSN",

448

integrations: [

449

Sentry.genericPoolIntegration(),

450

Sentry.dataloaderIntegration({

451

captureKeys: true, // Include batch keys in spans

452

}),

453

Sentry.amqplibIntegration({

454

captureMessages: true, // Include message content in spans

455

}),

456

],

457

});

458

459

// DataLoader - automatically traced

460

const userLoader = new DataLoader(async (userIds) => {

461

// Batch loading logic will be traced

462

return fetchUsersByIds(userIds);

463

});

464

465

// AMQP - automatically traced

466

const connection = await amqp.connect("amqp://localhost");

467

const channel = await connection.createChannel();

468

await channel.assertQueue("task_queue");

469

470

// Publishing and consuming messages will create spans

471

await channel.sendToQueue("task_queue", Buffer.from("Hello World"));

472

```

473

474

## Types

475

476

### Integration Options

477

478

```typescript { .api }

479

interface MongoOptions {

480

/** MongoDB operations to trace */

481

operations?: string[];

482

/** Include query details in spans */

483

captureQueries?: boolean;

484

/** Maximum query length to capture */

485

maxQueryLength?: number;

486

}

487

488

interface MongooseOptions {

489

/** Include query details in spans */

490

captureQueries?: boolean;

491

/** Maximum query length to capture */

492

maxQueryLength?: number;

493

}

494

495

interface PostgresOptions {

496

/** Include SQL queries in spans */

497

captureQueries?: boolean;

498

/** Maximum query length to capture */

499

maxQueryLength?: number;

500

}

501

502

interface PostgresJsOptions {

503

/** Include SQL queries in spans */

504

captureQueries?: boolean;

505

/** Maximum query length to capture */

506

maxQueryLength?: number;

507

}

508

509

interface MysqlOptions {

510

/** Include SQL queries in spans */

511

captureQueries?: boolean;

512

/** Maximum query length to capture */

513

maxQueryLength?: number;

514

}

515

516

interface Mysql2Options {

517

/** Include SQL queries in spans */

518

captureQueries?: boolean;

519

/** Maximum query length to capture */

520

maxQueryLength?: number;

521

}

522

523

interface RedisOptions {

524

/** Include Redis commands in spans */

525

captureCommands?: boolean;

526

/** Maximum command length to capture */

527

maxCommandLength?: number;

528

}

529

530

interface PrismaOptions {

531

/** Include SQL queries in spans */

532

captureQueries?: boolean;

533

/** Maximum query length to capture */

534

maxQueryLength?: number;

535

}

536

537

interface TediousOptions {

538

/** Include SQL queries in spans */

539

captureQueries?: boolean;

540

/** Maximum query length to capture */

541

maxQueryLength?: number;

542

}

543

544

interface KnexOptions {

545

/** Include SQL queries in spans */

546

captureQueries?: boolean;

547

/** Maximum query length to capture */

548

maxQueryLength?: number;

549

}

550

551

interface IoredisOptions {

552

/** Include Redis commands in spans */

553

captureCommands?: boolean;

554

/** Maximum command length to capture */

555

maxCommandLength?: number;

556

}

557

558

interface GenericPoolOptions {

559

/** Include pool operation details in spans */

560

captureOperations?: boolean;

561

}

562

563

interface DataloaderOptions {

564

/** Include batch keys in spans */

565

captureKeys?: boolean;

566

/** Maximum key count to capture */

567

maxKeyCount?: number;

568

}

569

570

interface AmqplibOptions {

571

/** Include message content in spans */

572

captureMessages?: boolean;

573

/** Maximum message length to capture */

574

maxMessageLength?: number;

575

}

576

```