Merge branch 'sentry-queries' into 'main'

Track queries with Sentry

See merge request soapbox-pub/ditto!71
This commit is contained in:
Alex Gleason 2023-12-07 18:25:22 +00:00
commit 2157822c7f
3 changed files with 24 additions and 17 deletions

11
src/sentry.ts Normal file
View File

@ -0,0 +1,11 @@
import { Conf } from './config.ts';
import { Sentry } from './deps.ts';
// Sentry
if (Conf.sentryDsn) {
console.log('Sentry enabled');
Sentry.init({
dsn: Conf.sentryDsn,
tracesSampleRate: 1.0,
});
}

View File

@ -1,15 +1,5 @@
import './precheck.ts';
import './sentry.ts';
import app from './app.ts';
import { Conf } from './config.ts';
import { Sentry } from './deps.ts';
// Sentry
if (Conf.sentryDsn) {
console.log('Sentry enabled');
Sentry.init({
dsn: Conf.sentryDsn,
tracesSampleRate: 1.0,
});
}
Deno.serve(app.fetch);

View File

@ -1,6 +1,7 @@
/// <reference lib="webworker" />
import { Comlink, type CompiledQuery, DenoSqlite3, type QueryResult } from '@/deps.ts';
import { Comlink, type CompiledQuery, DenoSqlite3, type QueryResult, Sentry } from '@/deps.ts';
import '@/sentry.ts';
let db: DenoSqlite3 | undefined;
@ -10,11 +11,16 @@ export const SqliteWorker = {
},
executeQuery<R>({ sql, parameters }: CompiledQuery): QueryResult<R> {
if (!db) throw new Error('Database not open');
return {
rows: db.prepare(sql).all(...parameters as any[]) as R[],
numAffectedRows: BigInt(db.changes),
insertId: BigInt(db.lastInsertRowId),
};
const result: QueryResult<R> = Sentry.startSpan({ name: sql, op: 'db.query' }, () => {
return {
rows: db!.prepare(sql).all(...parameters as any[]) as R[],
numAffectedRows: BigInt(db!.changes),
insertId: BigInt(db!.lastInsertRowId),
};
});
return result;
},
destroy() {
db?.close();