|
2 | 2 | import { Injectable, Optional } from '@nestjs/common';
|
3 | 3 | import { $, ConstraintViolationError, EdgeDBError, Executor } from 'edgedb';
|
4 | 4 | import { QueryArgs } from 'edgedb/dist/ifaces';
|
| 5 | +import { dirname, resolve } from 'path'; |
| 6 | +import { fileURLToPath } from 'url'; |
5 | 7 | import { retry, RetryOptions } from '~/common/retry';
|
6 | 8 | import { TracingService } from '~/core/tracing';
|
7 | 9 | import { jestSkipFileInExceptionSource } from '../exception';
|
@@ -107,11 +109,26 @@ export class EdgeDB {
|
107 | 109 |
|
108 | 110 | async run(query: any, args?: any) {
|
109 | 111 | 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) => { |
111 | 124 | // Show this segment separately in the service map
|
112 | 125 | segment.namespace = 'remote';
|
113 | 126 | // 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 | + }; |
115 | 132 |
|
116 | 133 | try {
|
117 | 134 | if (query instanceof TypedEdgeQL) {
|
@@ -173,3 +190,7 @@ const cardinalityToExecutorMethod = {
|
173 | 190 | AtLeastOne: 'query',
|
174 | 191 | Empty: 'query',
|
175 | 192 | } satisfies Record<`${$.Cardinality}`, keyof Executor>;
|
| 193 | + |
| 194 | +const projectDir = resolve( |
| 195 | + `${dirname(fileURLToPath(import.meta.url))}/../../..`, |
| 196 | +); |
0 commit comments