@@ -38,8 +38,6 @@ import {
3838/** @knipignore */
3939import { PACKAGE_NAME , PACKAGE_VERSION } from './version' ;
4040
41- type formatType = typeof mysqlTypes . format ;
42-
4341export class MySQL2Instrumentation extends InstrumentationBase < MySQL2InstrumentationConfig > {
4442 static readonly COMMON_ATTRIBUTES = {
4543 [ SEMATTRS_DB_SYSTEM ] : DBSYSTEMVALUES_MYSQL ,
@@ -63,7 +61,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
6361 this . _wrap (
6462 ConnectionPrototype ,
6563 'query' ,
66- this . _patchQuery ( moduleExports . format , false ) as any
64+ this . _patchQuery ( false ) as any
6765 ) ;
6866
6967 if ( isWrapped ( ConnectionPrototype . execute ) ) {
@@ -72,7 +70,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
7270 this . _wrap (
7371 ConnectionPrototype ,
7472 'execute' ,
75- this . _patchQuery ( moduleExports . format , true ) as any
73+ this . _patchQuery ( true ) as any
7674 ) ;
7775
7876 return moduleExports ;
@@ -81,14 +79,18 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
8179 if ( moduleExports === undefined ) return ;
8280 const ConnectionPrototype : mysqlTypes . Connection =
8381 moduleExports . Connection . prototype ;
84- this . _unwrap ( ConnectionPrototype , 'query' ) ;
85- this . _unwrap ( ConnectionPrototype , 'execute' ) ;
82+ if ( isWrapped ( ConnectionPrototype . query ) ) {
83+ this . _unwrap ( ConnectionPrototype , 'query' ) ;
84+ }
85+ if ( isWrapped ( ConnectionPrototype . execute ) ) {
86+ this . _unwrap ( ConnectionPrototype , 'execute' ) ;
87+ }
8688 }
8789 ) ,
8890 ] ;
8991 }
9092
91- private _patchQuery ( format : formatType , isPrepared : boolean ) {
93+ private _patchQuery ( isPrepared : boolean ) {
9294 return ( originalQuery : Function ) : Function => {
9395 const thisPlugin = this ;
9496 return function query (
@@ -109,7 +111,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
109111 attributes : {
110112 ...MySQL2Instrumentation . COMMON_ATTRIBUTES ,
111113 ...getConnectionAttributes ( this . config ) ,
112- [ SEMATTRS_DB_STATEMENT ] : getDbStatement ( query , format , values ) ,
114+ [ SEMATTRS_DB_STATEMENT ] : getDbStatement ( query , values ) ,
113115 } ,
114116 } ) ;
115117
@@ -149,11 +151,10 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
149151 ) ;
150152 }
151153 }
152-
153154 span . end ( ) ;
154155 } ) ;
155156
156- if ( arguments . length === 1 ) {
157+ if ( typeof arguments [ arguments . length - 1 ] !== 'function' ) {
157158 if ( typeof ( query as any ) . onResult === 'function' ) {
158159 thisPlugin . _wrap (
159160 query as any ,
@@ -177,22 +178,13 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
177178 } ) ;
178179
179180 return streamableQuery ;
180- }
181-
182- if ( typeof arguments [ 1 ] === 'function' ) {
181+ } else {
183182 thisPlugin . _wrap (
184183 arguments ,
185- 1 ,
186- thisPlugin . _patchCallbackQuery ( endSpan )
187- ) ;
188- } else if ( typeof arguments [ 2 ] === 'function' ) {
189- thisPlugin . _wrap (
190- arguments ,
191- 2 ,
184+ arguments . length - 1 ,
192185 thisPlugin . _patchCallbackQuery ( endSpan )
193186 ) ;
194187 }
195-
196188 return originalQuery . apply ( this , arguments ) ;
197189 } ;
198190 } ;
0 commit comments