Skip to content

Commit 9266b95

Browse files
committed
Improve span naming and type safety
1 parent 93e2ad3 commit 9266b95

File tree

2 files changed

+9
-6
lines changed
  • dev-packages/node-integration-tests/suites/tracing/postgresjs
  • packages/node/src/integrations/tracing

2 files changed

+9
-6
lines changed

dev-packages/node-integration-tests/suites/tracing/postgresjs/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const EXISTING_TEST_EMAIL = 'bar@baz.com';
55
const NON_EXISTING_TEST_EMAIL = 'foo@baz.com';
66

77
// Helper function to create basic span matcher (reduces duplication in new tests)
8-
function createDbSpanMatcher(operationName: string, descriptionMatcher: any = expect.any(String)) {
8+
function createDbSpanMatcher(operationName: string, descriptionMatcher: unknown = expect.any(String)) {
99
return expect.objectContaining({
1010
data: expect.objectContaining({
1111
'db.namespace': 'test_db',

packages/node/src/integrations/tracing/postgresjs.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,14 @@ export class PostgresJsInstrumentation extends InstrumentationBase<PostgresJsIns
360360

361361
const sanitizedSqlQuery = self._sanitizeSqlQuery(query.strings?.[0]);
362362

363-
let spanName = sanitizedSqlQuery?.trim() || '';
364-
if (!spanName) {
365-
// Fallback: try to extract operation from the sanitized query
366-
const operationMatch = sanitizedSqlQuery?.match(SQL_OPERATION_REGEX);
367-
spanName = operationMatch?.[1] ? `db.${operationMatch[1].toLowerCase()}` : 'db.query';
363+
let spanName: string;
364+
const operationMatch = sanitizedSqlQuery?.match(SQL_OPERATION_REGEX);
365+
if (operationMatch?.[1]) {
366+
spanName = `db.${operationMatch[1].toLowerCase()}`;
367+
} else if (sanitizedSqlQuery?.trim()) {
368+
spanName = sanitizedSqlQuery.trim();
369+
} else {
370+
spanName = 'db.query';
368371
}
369372

370373
return startSpanManual(

0 commit comments

Comments
 (0)