1818 * - Upstream version: @opentelemetry/instrumentation-generic-pool@0.61.0
1919 * - Minor TypeScript strictness adjustments for this repository's compiler settings
2020 */
21- /* eslint-disable */
2221
2322import * as api from '@opentelemetry/api' ;
24- import {
25- InstrumentationBase ,
26- InstrumentationConfig ,
27- InstrumentationNodeModuleDefinition ,
28- isWrapped ,
29- } from '@opentelemetry/instrumentation' ;
30-
31- import type * as genericPool from './generic-pool-types' ;
32-
23+ import type { InstrumentationConfig } from '@opentelemetry/instrumentation' ;
24+ import { InstrumentationBase , InstrumentationNodeModuleDefinition , isWrapped } from '@opentelemetry/instrumentation' ;
3325import { SDK_VERSION } from '@sentry/core' ;
26+ import type * as genericPool from './generic-pool-types' ;
3427
3528const MODULE_NAME = 'generic-pool' ;
3629const PACKAGE_NAME = '@sentry/instrumentation-generic-pool' ;
3730
31+ type AcquireFn = ( this : unknown , ...args : unknown [ ] ) => unknown ;
32+ interface PoolConstructor {
33+ prototype : { acquire : AcquireFn } ;
34+ }
35+ interface GenericPoolModule {
36+ Pool : PoolConstructor ;
37+ }
38+
3839export class GenericPoolInstrumentation extends InstrumentationBase {
3940 // only used for v2 - v2.3)
4041 private _isDisabled = false ;
@@ -48,49 +49,49 @@ export class GenericPoolInstrumentation extends InstrumentationBase {
4849 new InstrumentationNodeModuleDefinition (
4950 MODULE_NAME ,
5051 [ '>=3.0.0 <4' ] ,
51- moduleExports => {
52- const Pool : any = moduleExports . Pool ;
52+ ( moduleExports : GenericPoolModule ) => {
53+ const Pool = moduleExports . Pool ;
5354 if ( isWrapped ( Pool . prototype . acquire ) ) {
5455 this . _unwrap ( Pool . prototype , 'acquire' ) ;
5556 }
5657 this . _wrap ( Pool . prototype , 'acquire' , this . _acquirePatcher . bind ( this ) ) ;
5758 return moduleExports ;
5859 } ,
59- moduleExports => {
60- const Pool : any = moduleExports . Pool ;
60+ ( moduleExports : GenericPoolModule ) => {
61+ const Pool = moduleExports . Pool ;
6162 this . _unwrap ( Pool . prototype , 'acquire' ) ;
6263 return moduleExports ;
6364 } ,
6465 ) ,
6566 new InstrumentationNodeModuleDefinition (
6667 MODULE_NAME ,
6768 [ '>=2.4.0 <3' ] ,
68- moduleExports => {
69- const Pool : any = moduleExports . Pool ;
69+ ( moduleExports : GenericPoolModule ) => {
70+ const Pool = moduleExports . Pool ;
7071 if ( isWrapped ( Pool . prototype . acquire ) ) {
7172 this . _unwrap ( Pool . prototype , 'acquire' ) ;
7273 }
7374 this . _wrap ( Pool . prototype , 'acquire' , this . _acquireWithCallbacksPatcher . bind ( this ) ) ;
7475 return moduleExports ;
7576 } ,
76- moduleExports => {
77- const Pool : any = moduleExports . Pool ;
77+ ( moduleExports : GenericPoolModule ) => {
78+ const Pool = moduleExports . Pool ;
7879 this . _unwrap ( Pool . prototype , 'acquire' ) ;
7980 return moduleExports ;
8081 } ,
8182 ) ,
8283 new InstrumentationNodeModuleDefinition (
8384 MODULE_NAME ,
8485 [ '>=2.0.0 <2.4' ] ,
85- moduleExports => {
86+ ( moduleExports : GenericPoolModule ) => {
8687 this . _isDisabled = false ;
8788 if ( isWrapped ( moduleExports . Pool ) ) {
8889 this . _unwrap ( moduleExports , 'Pool' ) ;
8990 }
9091 this . _wrap ( moduleExports , 'Pool' , this . _poolWrapper . bind ( this ) ) ;
9192 return moduleExports ;
9293 } ,
93- moduleExports => {
94+ ( moduleExports : GenericPoolModule ) => {
9495 // since the object is created on the fly every time, we need to use
9596 // a boolean switch here to disable the instrumentation
9697 this . _isDisabled = true ;
@@ -100,14 +101,15 @@ export class GenericPoolInstrumentation extends InstrumentationBase {
100101 ] ;
101102 }
102103
103- private _acquirePatcher ( original : genericPool . Pool < unknown > [ 'acquire' ] ) {
104+ private _acquirePatcher ( original : AcquireFn ) {
105+ // eslint-disable-next-line @typescript-eslint/no-this-alias
104106 const instrumentation = this ;
105- return function wrapped_acquire ( this : genericPool . Pool < unknown > , ...args : any [ ] ) {
107+ return function wrapped_acquire ( this : genericPool . Pool < unknown > , ...args : unknown [ ] ) {
106108 const parent = api . context . active ( ) ;
107109 const span = instrumentation . tracer . startSpan ( 'generic-pool.acquire' , { } , parent ) ;
108110
109111 return api . context . with ( api . trace . setSpan ( parent , span ) , ( ) => {
110- return original . call ( this , ...args ) . then (
112+ return ( original . call ( this , ...args ) as PromiseLike < unknown > ) . then (
111113 ( value : unknown ) => {
112114 span . end ( ) ;
113115 return value ;
@@ -122,18 +124,24 @@ export class GenericPoolInstrumentation extends InstrumentationBase {
122124 } ;
123125 }
124126
125- private _poolWrapper ( original : any ) {
127+ private _poolWrapper ( original : ( this : unknown , ...args : unknown [ ] ) => { acquire : AcquireFn } ) {
128+ // eslint-disable-next-line @typescript-eslint/no-this-alias
126129 const instrumentation = this ;
127- return function wrapped_pool ( this : any ) {
128- const pool = original . apply ( this , arguments ) ;
130+ return function wrapped_pool ( this : unknown , ... args : unknown [ ] ) {
131+ const pool = original . apply ( this , args ) ;
129132 instrumentation . _wrap ( pool , 'acquire' , instrumentation . _acquireWithCallbacksPatcher . bind ( instrumentation ) ) ;
130133 return pool ;
131134 } ;
132135 }
133136
134- private _acquireWithCallbacksPatcher ( original : any ) {
137+ private _acquireWithCallbacksPatcher ( original : AcquireFn ) {
138+ // eslint-disable-next-line @typescript-eslint/no-this-alias
135139 const instrumentation = this ;
136- return function wrapped_acquire ( this : genericPool . Pool < unknown > , cb : Function , priority : number ) {
140+ return function wrapped_acquire (
141+ this : genericPool . Pool < unknown > ,
142+ cb : ( err : unknown , client : unknown ) => unknown ,
143+ priority : number ,
144+ ) {
137145 // only used for v2 - v2.3
138146 if ( instrumentation . _isDisabled ) {
139147 return original . call ( this , cb , priority ) ;
@@ -148,8 +156,9 @@ export class GenericPoolInstrumentation extends InstrumentationBase {
148156 span . end ( ) ;
149157 // Not checking whether cb is a function because
150158 // the original code doesn't do that either.
159+ // The callback's return value is unused by generic-pool, so we don't return it.
151160 if ( cb ) {
152- return cb ( err , client ) ;
161+ cb ( err , client ) ;
153162 }
154163 } ,
155164 priority ,
0 commit comments