Skip to content

Commit 8b518df

Browse files
committed
Update span descriptions
1 parent c47ee4a commit 8b518df

File tree

2 files changed

+47
-53
lines changed

2 files changed

+47
-53
lines changed

dev-packages/e2e-tests/test-applications/supabase-nextjs/tests/performance.test.ts

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ test('Sends server-side Supabase auth admin `createUser` span', async ({ page, b
1818

1919
expect(transactionEvent.spans).toContainEqual({
2020
data: expect.objectContaining({
21-
"db.operation": "auth.admin.createUser",
22-
"db.system": "postgresql",
23-
"sentry.op": "db",
24-
"sentry.origin": "auto.db.supabase"
21+
'db.operation': 'auth.admin.createUser',
22+
'db.system': 'postgresql',
23+
'sentry.op': 'db',
24+
'sentry.origin': 'auto.db.supabase',
2525
}),
26-
description: 'createUser',
26+
description: 'auth (admin) createUser',
2727
op: 'db',
2828
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
2929
span_id: expect.stringMatching(/[a-f0-9]{16}/),
@@ -59,17 +59,14 @@ test('Sends client-side Supabase db-operation spans and breadcrumbs to Sentry',
5959

6060
expect(transactionEvent.spans).toContainEqual(
6161
expect.objectContaining({
62-
description: 'from(todos)',
62+
description: 'select(*) filter(order, asc) from(todos)',
6363
op: 'db',
6464
data: expect.objectContaining({
65-
"db.operation": "select",
66-
"db.query": [
67-
"select(*)",
68-
"filter(order, asc)"
69-
],
70-
"db.system": "postgresql",
71-
"sentry.op": "db",
72-
"sentry.origin": "auto.db.supabase"
65+
'db.operation': 'select',
66+
'db.query': ['select(*)', 'filter(order, asc)'],
67+
'db.system': 'postgresql',
68+
'sentry.op': 'db',
69+
'sentry.origin': 'auto.db.supabase',
7370
}),
7471
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
7572
span_id: expect.stringMatching(/[a-f0-9]{16}/),
@@ -83,16 +80,13 @@ test('Sends client-side Supabase db-operation spans and breadcrumbs to Sentry',
8380

8481
expect(transactionEvent.spans).toContainEqual({
8582
data: expect.objectContaining({
86-
"db.operation": "select",
87-
"db.query": [
88-
"select(*)",
89-
"filter(order, asc)"
90-
],
91-
"db.system": "postgresql",
92-
"sentry.op": "db",
93-
"sentry.origin": "auto.db.supabase"
83+
'db.operation': 'select',
84+
'db.query': ['select(*)', 'filter(order, asc)'],
85+
'db.system': 'postgresql',
86+
'sentry.op': 'db',
87+
'sentry.origin': 'auto.db.supabase',
9488
}),
95-
description: 'from(todos)',
89+
description: 'select(*) filter(order, asc) from(todos)',
9690
op: 'db',
9791
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
9892
span_id: expect.stringMatching(/[a-f0-9]{16}/),
@@ -107,15 +101,15 @@ test('Sends client-side Supabase db-operation spans and breadcrumbs to Sentry',
107101
timestamp: expect.any(Number),
108102
type: 'supabase',
109103
category: 'db.select',
110-
message: 'from(todos)',
104+
message: 'select(*) filter(order, asc) from(todos)',
111105
data: expect.any(Object),
112106
});
113107

114108
expect(transactionEvent.breadcrumbs).toContainEqual({
115109
timestamp: expect.any(Number),
116110
type: 'supabase',
117111
category: 'db.insert',
118-
message: 'from(todos)',
112+
message: 'insert(...) select(*) from(todos)',
119113
data: expect.any(Object),
120114
});
121115
});
@@ -134,15 +128,13 @@ test('Sends server-side Supabase db-operation spans and breadcrumbs to Sentry',
134128
expect(transactionEvent.spans).toContainEqual(
135129
expect.objectContaining({
136130
data: expect.objectContaining({
137-
"db.operation": "insert",
138-
"db.query": [
139-
"select(*)",
140-
],
141-
"db.system": "postgresql",
142-
"sentry.op": "db",
143-
"sentry.origin": "auto.db.supabase"
131+
'db.operation': 'insert',
132+
'db.query': ['select(*)'],
133+
'db.system': 'postgresql',
134+
'sentry.op': 'db',
135+
'sentry.origin': 'auto.db.supabase',
144136
}),
145-
description: 'from(todos)',
137+
description: 'insert(...) select(*) from(todos)',
146138
op: 'db',
147139
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
148140
span_id: expect.stringMatching(/[a-f0-9]{16}/),
@@ -156,15 +148,13 @@ test('Sends server-side Supabase db-operation spans and breadcrumbs to Sentry',
156148

157149
expect(transactionEvent.spans).toContainEqual({
158150
data: expect.objectContaining({
159-
"db.operation": "select",
160-
"db.query": [
161-
"select(*)",
162-
],
163-
"db.system": "postgresql",
164-
"sentry.op": "db",
165-
"sentry.origin": "auto.db.supabase"
151+
'db.operation': 'select',
152+
'db.query': ['select(*)'],
153+
'db.system': 'postgresql',
154+
'sentry.op': 'db',
155+
'sentry.origin': 'auto.db.supabase',
166156
}),
167-
description: 'from(todos)',
157+
description: 'select(*) from(todos)',
168158
op: 'db',
169159
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
170160
span_id: expect.stringMatching(/[a-f0-9]{16}/),
@@ -179,24 +169,23 @@ test('Sends server-side Supabase db-operation spans and breadcrumbs to Sentry',
179169
timestamp: expect.any(Number),
180170
type: 'supabase',
181171
category: 'db.select',
182-
message: 'from(todos)',
172+
message: 'select(*) from(todos)',
183173
data: expect.any(Object),
184174
});
185175

186176
expect(transactionEvent.breadcrumbs).toContainEqual({
187177
timestamp: expect.any(Number),
188178
type: 'supabase',
189179
category: 'db.insert',
190-
message: 'from(todos)',
180+
message: 'insert(...) select(*) from(todos)',
191181
data: expect.any(Object),
192182
});
193183
});
194184

195185
test('Sends server-side Supabase auth admin `listUsers` span', async ({ page, baseURL }) => {
196186
const httpTransactionPromise = waitForTransaction('supabase-nextjs', transactionEvent => {
197187
return (
198-
transactionEvent?.contexts?.trace?.op === 'http.server' &&
199-
transactionEvent?.transaction === 'GET /api/list-users'
188+
transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'GET /api/list-users'
200189
);
201190
});
202191

@@ -205,12 +194,12 @@ test('Sends server-side Supabase auth admin `listUsers` span', async ({ page, ba
205194

206195
expect(transactionEvent.spans).toContainEqual({
207196
data: expect.objectContaining({
208-
"db.operation": "auth.admin.listUsers",
209-
"db.system": "postgresql",
210-
"sentry.op": "db",
211-
"sentry.origin": "auto.db.supabase"
197+
'db.operation': 'auth.admin.listUsers',
198+
'db.system': 'postgresql',
199+
'sentry.op': 'db',
200+
'sentry.origin': 'auto.db.supabase',
212201
}),
213-
description: 'listUsers',
202+
description: 'auth (admin) listUsers',
214203
op: 'db',
215204
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
216205
span_id: expect.stringMatching(/[a-f0-9]{16}/),

packages/core/src/integrations/supabase.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
219219
apply(target, thisArg, argumentsList) {
220220
return startSpan(
221221
{
222-
name: operation.name,
222+
name: `auth ${isAdmin ? '(admin) ' : ''}${operation.name}`,
223223
attributes: {
224224
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.supabase',
225225
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db',
@@ -343,22 +343,27 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte
343343

344344
const pathParts = typedThis.url.pathname.split('/');
345345
const table = pathParts.length > 0 ? pathParts[pathParts.length - 1] : '';
346-
const description = `from(${table})`;
347346

348347
const queryItems: string[] = [];
349348
for (const [key, value] of typedThis.url.searchParams.entries()) {
350349
// It's possible to have multiple entries for the same key, eg. `id=eq.7&id=eq.3`,
351350
// so we need to use array instead of object to collect them.
352351
queryItems.push(translateFiltersIntoMethods(key, value));
353352
}
354-
355353
const body: Record<string, unknown> = Object.create(null);
356354
if (isPlainObject(typedThis.body)) {
357355
for (const [key, value] of Object.entries(typedThis.body)) {
358356
body[key] = value;
359357
}
360358
}
361359

360+
// Adding operation to the beginning of the description if it's not a `select` operation
361+
// For example, it can be an `insert` or `update` operation but the query can be `select(...)`
362+
// For `select` operations, we don't need repeat it in the description
363+
const description = `${operation === 'select' ? '' : `${operation}${body ? '(...) ' : ''}`}${queryItems.join(
364+
' ',
365+
)} from(${table})`;
366+
362367
const attributes: Record<string, any> = {
363368
'db.table': table,
364369
'db.schema': typedThis.schema,

0 commit comments

Comments
 (0)