@@ -39,8 +39,6 @@ import {
3939/** @knipignore */
4040import { PACKAGE_NAME , PACKAGE_VERSION } from './version' ;
4141
42- type formatType = typeof mysqlTypes . format ;
43-
4442export class MySQL2Instrumentation extends InstrumentationBase < MySQL2InstrumentationConfig > {
4543 static readonly COMMON_ATTRIBUTES = {
4644 [ SEMATTRS_DB_SYSTEM ] : DBSYSTEMVALUES_MYSQL ,
@@ -64,7 +62,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
6462 this . _wrap (
6563 ConnectionPrototype ,
6664 'query' ,
67- this . _patchQuery ( moduleExports . format , false ) as any
65+ this . _patchQuery ( false ) as any
6866 ) ;
6967
7068 if ( isWrapped ( ConnectionPrototype . execute ) ) {
@@ -73,7 +71,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
7371 this . _wrap (
7472 ConnectionPrototype ,
7573 'execute' ,
76- this . _patchQuery ( moduleExports . format , true ) as any
74+ this . _patchQuery ( true ) as any
7775 ) ;
7876
7977 return moduleExports ;
@@ -82,14 +80,18 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
8280 if ( moduleExports === undefined ) return ;
8381 const ConnectionPrototype : mysqlTypes . Connection =
8482 moduleExports . Connection . prototype ;
85- this . _unwrap ( ConnectionPrototype , 'query' ) ;
86- this . _unwrap ( ConnectionPrototype , 'execute' ) ;
83+ if ( isWrapped ( ConnectionPrototype . query ) ) {
84+ this . _unwrap ( ConnectionPrototype , 'query' ) ;
85+ }
86+ if ( isWrapped ( ConnectionPrototype . execute ) ) {
87+ this . _unwrap ( ConnectionPrototype , 'execute' ) ;
88+ }
8789 }
8890 ) ,
8991 ] ;
9092 }
9193
92- private _patchQuery ( format : formatType , isPrepared : boolean ) {
94+ private _patchQuery ( isPrepared : boolean ) {
9395 return ( originalQuery : Function ) : Function => {
9496 const thisPlugin = this ;
9597 return function query (
@@ -110,7 +112,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
110112 attributes : {
111113 ...MySQL2Instrumentation . COMMON_ATTRIBUTES ,
112114 ...getConnectionAttributes ( this . config ) ,
113- [ SEMATTRS_DB_STATEMENT ] : getDbStatement ( query , format , values ) ,
115+ [ SEMATTRS_DB_STATEMENT ] : getDbStatement ( query , values ) ,
114116 } ,
115117 } ) ;
116118
@@ -150,11 +152,10 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
150152 ) ;
151153 }
152154 }
153-
154155 span . end ( ) ;
155156 } ) ;
156157
157- if ( arguments . length === 1 ) {
158+ if ( typeof arguments [ arguments . length - 1 ] !== 'function' ) {
158159 if ( typeof ( query as any ) . onResult === 'function' ) {
159160 thisPlugin . _wrap (
160161 query as any ,
@@ -178,22 +179,13 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
178179 } ) ;
179180
180181 return streamableQuery ;
181- }
182-
183- if ( typeof arguments [ 1 ] === 'function' ) {
182+ } else {
184183 thisPlugin . _wrap (
185184 arguments ,
186- 1 ,
187- thisPlugin . _patchCallbackQuery ( endSpan )
188- ) ;
189- } else if ( typeof arguments [ 2 ] === 'function' ) {
190- thisPlugin . _wrap (
191- arguments ,
192- 2 ,
185+ arguments . length - 1 ,
193186 thisPlugin . _patchCallbackQuery ( endSpan )
194187 ) ;
195188 }
196-
197189 return originalQuery . apply ( this , arguments ) ;
198190 } ;
199191 } ;
0 commit comments