Skip to content

Commit 26e5811

Browse files
committed
Improve EdgeDB tracing data
Identify query/segment name by the first method in stack in our src & outside of core/edgedb Add current user & db identifier
1 parent 1c8a036 commit 26e5811

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/core/edgedb/edgedb.service.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { Injectable, Optional } from '@nestjs/common';
33
import { $, ConstraintViolationError, EdgeDBError, Executor } from 'edgedb';
44
import { QueryArgs } from 'edgedb/dist/ifaces';
5+
import { dirname, resolve } from 'path';
6+
import { fileURLToPath } from 'url';
57
import { retry, RetryOptions } from '~/common/retry';
68
import { TracingService } from '~/core/tracing';
79
import { jestSkipFileInExceptionSource } from '../exception';
@@ -107,11 +109,26 @@ export class EdgeDB {
107109

108110
async run(query: any, args?: any) {
109111
const executor = this.childExecutor ?? this.transactionContext.current;
110-
return await this.tracing.capture('EdgeDB Query', async (segment) => {
112+
113+
const queryName =
114+
new Error().stack
115+
?.split('\n')
116+
.slice(2)
117+
.find(
118+
(frm) => frm.includes(projectDir) && !frm.includes('/core/edgedb/'),
119+
)
120+
?.split(/\s+/)[2]
121+
.replaceAll(/(EdgeDB|Repository)/g, '') ?? 'Query';
122+
123+
return await this.tracing.capture(queryName, async (segment) => {
111124
// Show this segment separately in the service map
112125
segment.namespace = 'remote';
113126
// Help ID the segment as being for a database
114-
segment.sql = {};
127+
segment.sql = {
128+
// eslint-disable-next-line @typescript-eslint/naming-convention
129+
database_version: 'EdgeDB',
130+
user: this.optionsContext.current.session.globals.currentUserId,
131+
};
115132

116133
try {
117134
if (query instanceof TypedEdgeQL) {
@@ -173,3 +190,7 @@ const cardinalityToExecutorMethod = {
173190
AtLeastOne: 'query',
174191
Empty: 'query',
175192
} satisfies Record<`${$.Cardinality}`, keyof Executor>;
193+
194+
const projectDir = resolve(
195+
`${dirname(fileURLToPath(import.meta.url))}/../../..`,
196+
);

0 commit comments

Comments
 (0)