mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-23 04:34:15 -04:00
(sentry) monitor database query performance
This commit is contained in:
parent
f8156d5204
commit
b0a11cf07c
@ -3,6 +3,7 @@ import './setup.ts';
|
||||
import express from 'express';
|
||||
import type { Request, Response, NextFunction } from 'express';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import type { StartSpanOptions } from '@sentry/types';
|
||||
import authenticate from '../src/authenticate.ts';
|
||||
import dbConnection from './db.ts';
|
||||
import type { Database, SQLQuery } from './db.ts';
|
||||
@ -87,21 +88,33 @@ export class LazyDatabase implements Database {
|
||||
}
|
||||
}
|
||||
|
||||
buildSpanOptions(sql: SQLQuery): StartSpanOptions {
|
||||
return {
|
||||
name: typeof sql === 'string' ? sql : sql.sql,
|
||||
op: 'db',
|
||||
attributes: {
|
||||
'db.system': 'sqlite',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async get<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T | undefined> {
|
||||
await this.init();
|
||||
return this.db!.get(sql, ...args);
|
||||
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.get(sql, ...args));
|
||||
}
|
||||
|
||||
async all<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T[]> {
|
||||
await this.init();
|
||||
return this.db!.all(sql, ...args);
|
||||
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.all(sql, ...args));
|
||||
}
|
||||
|
||||
async close(): Promise<void> {
|
||||
if (this.db !== null) {
|
||||
try {
|
||||
await this.db.close();
|
||||
} catch {}
|
||||
} catch (error) {
|
||||
Sentry.captureException(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user