@@ -2,7 +2,7 @@ import type { Instrumentation } from '@opentelemetry/instrumentation';
2
2
// When importing CJS modules into an ESM module, we cannot import the named exports directly.
3
3
import * as prismaInstrumentation from '@prisma/instrumentation' ;
4
4
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , consoleSandbox , defineIntegration , spanToJSON } from '@sentry/core' ;
5
- import { generateInstrumentOnce } from '../../otel/instrument' ;
5
+ import { generateInstrumentOnce , instrumentWhenWrapped } from '../../otel/instrument' ;
6
6
import type { PrismaV5TracingHelper } from './prisma/vendor/v5-tracing-helper' ;
7
7
import type { PrismaV6TracingHelper } from './prisma/vendor/v6-tracing-helper' ;
8
8
@@ -113,29 +113,34 @@ export const prismaIntegration = defineIntegration(
113
113
*/
114
114
prismaInstrumentation ?: Instrumentation ;
115
115
} = { } ) => {
116
+ let instrumentationWrappedCallback : undefined | ( ( callback : ( ) => void ) => void ) ;
117
+
116
118
return {
117
119
name : INTEGRATION_NAME ,
118
120
setupOnce ( ) {
119
- instrumentPrisma ( { prismaInstrumentation } ) ;
121
+ const instrumentation = instrumentPrisma ( { prismaInstrumentation } ) ;
122
+ instrumentationWrappedCallback = instrumentWhenWrapped ( instrumentation ) ;
120
123
} ,
121
124
setup ( client ) {
122
- client . on ( 'spanStart' , span => {
123
- const spanJSON = spanToJSON ( span ) ;
124
- if ( spanJSON . description ?. startsWith ( 'prisma:' ) ) {
125
- span . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , 'auto.db.otel.prisma' ) ;
126
- }
125
+ instrumentationWrappedCallback ?.( ( ) =>
126
+ client . on ( 'spanStart' , span => {
127
+ const spanJSON = spanToJSON ( span ) ;
128
+ if ( spanJSON . description ?. startsWith ( 'prisma:' ) ) {
129
+ span . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , 'auto.db.otel.prisma' ) ;
130
+ }
127
131
128
- // Make sure we use the query text as the span name, for ex. SELECT * FROM "User" WHERE "id" = $1
129
- if ( spanJSON . description === 'prisma:engine:db_query' && spanJSON . data [ 'db.query.text' ] ) {
130
- span . updateName ( spanJSON . data [ 'db.query.text' ] as string ) ;
131
- }
132
+ // Make sure we use the query text as the span name, for ex. SELECT * FROM "User" WHERE "id" = $1
133
+ if ( spanJSON . description === 'prisma:engine:db_query' && spanJSON . data [ 'db.query.text' ] ) {
134
+ span . updateName ( spanJSON . data [ 'db.query.text' ] as string ) ;
135
+ }
132
136
133
- // In Prisma v5.22+, the `db.system` attribute is automatically set
134
- // On older versions, this is missing, so we add it here
135
- if ( spanJSON . description === 'prisma:engine:db_query' && ! spanJSON . data [ 'db.system' ] ) {
136
- span . setAttribute ( 'db.system' , 'prisma' ) ;
137
- }
138
- } ) ;
137
+ // In Prisma v5.22+, the `db.system` attribute is automatically set
138
+ // On older versions, this is missing, so we add it here
139
+ if ( spanJSON . description === 'prisma:engine:db_query' && ! spanJSON . data [ 'db.system' ] ) {
140
+ span . setAttribute ( 'db.system' , 'prisma' ) ;
141
+ }
142
+ } ) ,
143
+ ) ;
139
144
} ,
140
145
} ;
141
146
} ,
0 commit comments