Skip to content

Commit 501d121

Browse files
committed
fix: semantic attrs
1 parent 0229ca5 commit 501d121

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

packages/nuxt/src/runtime/plugins/database.server.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import type { Database, PreparedStatement } from 'db0';
1313
// eslint-disable-next-line import/no-extraneous-dependencies
1414
import { defineNitroPlugin, useDatabase } from 'nitropack/runtime';
1515

16-
type PreparedStatementType = 'get' | 'run' | 'all' | 'raw';
17-
1816
/**
1917
* Keeps track of prepared statements that have been patched.
2018
*/
@@ -65,8 +63,8 @@ function instrumentDatabase(db: Database): void {
6563
db.exec = new Proxy(db.exec, {
6664
apply(target, thisArg, args: Parameters<typeof db.exec>) {
6765
return startSpan(
68-
createStartSpanOptions(args[0], db.dialect, 'run'),
69-
handleSpanStart(() => target.apply(thisArg, args), { query: args[0], type: 'run' }),
66+
createStartSpanOptions(args[0], db.dialect),
67+
handleSpanStart(() => target.apply(thisArg, args), { query: args[0] }),
7068
);
7169
},
7270
});
@@ -106,8 +104,8 @@ function instrumentPreparedStatementQueries(
106104
statement.get = new Proxy(statement.get, {
107105
apply(target, thisArg, args: Parameters<typeof statement.get>) {
108106
return startSpan(
109-
createStartSpanOptions(query, dialect, 'get'),
110-
handleSpanStart(() => target.apply(thisArg, args), { query, type: 'get' }),
107+
createStartSpanOptions(query, dialect),
108+
handleSpanStart(() => target.apply(thisArg, args), { query }),
111109
);
112110
},
113111
});
@@ -116,8 +114,8 @@ function instrumentPreparedStatementQueries(
116114
statement.run = new Proxy(statement.run, {
117115
apply(target, thisArg, args: Parameters<typeof statement.run>) {
118116
return startSpan(
119-
createStartSpanOptions(query, dialect, 'run'),
120-
handleSpanStart(() => target.apply(thisArg, args), { query, type: 'run' }),
117+
createStartSpanOptions(query, dialect),
118+
handleSpanStart(() => target.apply(thisArg, args), { query }),
121119
);
122120
},
123121
});
@@ -126,8 +124,8 @@ function instrumentPreparedStatementQueries(
126124
statement.all = new Proxy(statement.all, {
127125
apply(target, thisArg, args: Parameters<typeof statement.all>) {
128126
return startSpan(
129-
createStartSpanOptions(query, dialect, 'all'),
130-
handleSpanStart(() => target.apply(thisArg, args), { query, type: 'all' }),
127+
createStartSpanOptions(query, dialect),
128+
handleSpanStart(() => target.apply(thisArg, args), { query }),
131129
);
132130
},
133131
});
@@ -140,12 +138,12 @@ function instrumentPreparedStatementQueries(
140138
/**
141139
* Creates a span start callback handler
142140
*/
143-
function handleSpanStart(fn: () => unknown, breadcrumbOpts?: { query: string; type: PreparedStatementType }) {
141+
function handleSpanStart(fn: () => unknown, breadcrumbOpts?: { query: string }) {
144142
return async (span: Span) => {
145143
try {
146144
const result = await fn();
147145
if (breadcrumbOpts) {
148-
createBreadcrumb(breadcrumbOpts.query, breadcrumbOpts.type);
146+
createBreadcrumb(breadcrumbOpts.query);
149147
}
150148

151149
return result;
@@ -166,26 +164,26 @@ function handleSpanStart(fn: () => unknown, breadcrumbOpts?: { query: string; ty
166164
};
167165
}
168166

169-
function createBreadcrumb(query: string, type: PreparedStatementType): void {
167+
function createBreadcrumb(query: string): void {
170168
addBreadcrumb({
171169
category: 'query',
172170
message: query,
173171
data: {
174-
'db.query_type': type,
172+
'db.query.text': query,
175173
},
176174
});
177175
}
178176

179177
/**
180178
* Creates a start span options object.
181179
*/
182-
function createStartSpanOptions(query: string, dialect: string, type?: PreparedStatementType): StartSpanOptions {
180+
function createStartSpanOptions(query: string, dialect: string): StartSpanOptions {
183181
return {
184182
op: 'db.query',
185183
name: query,
186184
attributes: {
187-
'db.system': dialect,
188-
'db.query_type': type,
185+
'db.system.name': dialect,
186+
'db.query.text': query,
189187
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: SENTRY_ORIGIN,
190188
},
191189
};

0 commit comments

Comments
 (0)