-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: add bun sqlite auto instrumentation #16415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR @shyim. This is a good start!
I'd like us to follow the structure of https://github.com/getsentry/sentry-javascript/blob/develop/packages/cloudflare/src/d1.ts more closely here.
That means we need to
- Make sure we create breadcrumbs for SQL queries
- Link to bun docs wherever appropriate
- Extract out functions for
createStartSpanOptions
andcreateSpanAttributes
I understand thats a lot though (plus all of my review comments). Maybe we can start by creating a simple version of bunSqliteIntegration
that just patches one method. Then we can implement the rest of the patching in a follow-up PR.
let hasPatchedBunSqlite = false; | ||
|
||
export function _resetBunSqliteInstrumentation(): void { | ||
hasPatchedBunSqlite = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this functionality, it doesn't actually reset the proxy implementation, so calling this will lead to the sql module getting patched multiple times.
construct(target, args) { | ||
const instance = new target(...args); | ||
if (args[0]) { | ||
Object.defineProperty(instance, '_sentryDbName', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this being set?
It only seems to be defined, which would mean let dbName = this._sentryDbName || dbNameMap.get(this);
would always evaluate dbNameMap.get(this)
op: `db.sql.statement.${method}`, | ||
attributes: { | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.bun.sqlite', | ||
'db.system': 'sqlite', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'db.system': 'sqlite', | |
'db.system.name': 'sqlite', |
https://opentelemetry.io/docs/specs/semconv/registry/attributes/db/#db-system
const inParentSpanMap = new WeakMap<any, boolean>(); | ||
const dbNameMap = new WeakMap<any, string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do these maps do? Can we type them more stronger? Why are they WeakMap
?
let dbName = this._sentryDbName || dbNameMap.get(this); | ||
|
||
if (!dbName && this.filename) { | ||
dbName = this.filename; | ||
dbNameMap.set(this, dbName); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have this logic?
|
||
return startSpan( | ||
{ | ||
name: sql || 'db.sql.' + method, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what cases is sql
not defined? We should always try to make the span name the db statement.
op: `db.sql.${method}`, | ||
attributes: { | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.bun.sqlite', | ||
'db.system': 'sqlite', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'db.system': 'sqlite', | |
'db.system.name': 'sqlite', |
https://opentelemetry.io/docs/specs/semconv/registry/attributes/db/#db-system
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.bun.sqlite', | ||
'db.system': 'sqlite', | ||
'db.operation': method, | ||
...(sql && { 'db.statement': sql }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...(sql && { 'db.statement': sql }), | |
...(sql && { 'db.query.text': sql }), |
https://opentelemetry.io/docs/specs/semconv/registry/attributes/db/#db-statement
'db.system': 'sqlite', | ||
'db.operation': method, | ||
...(sql && { 'db.statement': sql }), | ||
...(dbName && { 'db.name': dbName }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...(dbName && { 'db.name': dbName }), | |
...(dbName && { 'db.namespace': dbName }), |
https://opentelemetry.io/docs/specs/semconv/registry/attributes/db/#db-name
return result; | ||
} catch (error) { | ||
span.setStatus({ code: 2, message: 'internal_error' }); | ||
captureException(error, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to capture an error here, we can just let the error bubble up.
Adds auto instrumentation support for Bun Sqlite
yarn lint
) & (yarn test
).