Skip to content

Commit f3406ea

Browse files
authored
chore: remove patch and unpatch diag from instrumentations (#2107)
* chore: remove patch and unpatch diag from instrumentations * fix: compile * fix: compile error connect instrumentation * fix: compile * fix: remove more patch and unpatch diag prints * fix: remove unused moduleVersion argument * fix: unused import from merge
1 parent 73e01f2 commit f3406ea

File tree

34 files changed

+99
-330
lines changed

34 files changed

+99
-330
lines changed

plugins/node/instrumentation-cucumber/src/instrumentation.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ export class CucumberInstrumentation extends InstrumentationBase {
5353
new InstrumentationNodeModuleDefinition(
5454
'@cucumber/cucumber',
5555
['^8.0.0', '^9.0.0', '^10.0.0'],
56-
(moduleExports: Cucumber, moduleVersion) => {
57-
this._diag.debug(
58-
`Applying patch for @cucumber/cucumber@${moduleVersion}`
59-
);
56+
(moduleExports: Cucumber) => {
6057
this.module = moduleExports;
6158
steps.forEach(step => {
6259
if (isWrapped(moduleExports[step])) {
@@ -72,11 +69,8 @@ export class CucumberInstrumentation extends InstrumentationBase {
7269
});
7370
return moduleExports;
7471
},
75-
(moduleExports: Cucumber, moduleVersion) => {
72+
(moduleExports: Cucumber) => {
7673
if (moduleExports === undefined) return;
77-
this._diag.debug(
78-
`Removing patch for @cucumber/cucumber@${moduleVersion}`
79-
);
8074
[...hooks, ...steps].forEach(method => {
8175
this._unwrap(moduleExports, method);
8276
});
@@ -85,10 +79,7 @@ export class CucumberInstrumentation extends InstrumentationBase {
8579
new InstrumentationNodeModuleFile(
8680
'@cucumber/cucumber/lib/runtime/test_case_runner.js',
8781
['^8.0.0', '^9.0.0', '^10.0.0'],
88-
(moduleExports, moduleVersion) => {
89-
this._diag.debug(
90-
`Applying patch for @cucumber/cucumber/lib/runtime/test_case_runner.js@${moduleVersion}`
91-
);
82+
moduleExports => {
9283
if (isWrapped(moduleExports.default.prototype.run)) {
9384
this._unwrap(moduleExports.default.prototype, 'run');
9485
this._unwrap(moduleExports.default.prototype, 'runStep');
@@ -115,11 +106,8 @@ export class CucumberInstrumentation extends InstrumentationBase {
115106
}
116107
return moduleExports;
117108
},
118-
(moduleExports, moduleVersion) => {
109+
moduleExports => {
119110
if (moduleExports === undefined) return;
120-
this._diag.debug(
121-
`Removing patch for @cucumber/cucumber/lib/runtime/test_case_runner.js@${moduleVersion}`
122-
);
123111
this._unwrap(moduleExports.default.prototype, 'run');
124112
this._unwrap(moduleExports.default.prototype, 'runStep');
125113
if ('runAttempt' in moduleExports.default.prototype) {

plugins/node/instrumentation-dataloader/src/instrumentation.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
isWrapped,
2121
} from '@opentelemetry/instrumentation';
2222
import {
23-
diag,
2423
trace,
2524
context,
2625
Link,
@@ -54,17 +53,13 @@ export class DataloaderInstrumentation extends InstrumentationBase {
5453
new InstrumentationNodeModuleDefinition(
5554
MODULE_NAME,
5655
['^2.0.0'],
57-
(dataloader, moduleVersion) => {
58-
diag.debug(`Applying patch for ${MODULE_NAME}@${moduleVersion}`);
59-
56+
dataloader => {
6057
this._patchLoad(dataloader.prototype);
6158
this._patchLoadMany(dataloader.prototype);
6259

6360
return this._getPatchedConstructor(dataloader);
6461
},
65-
(dataloader, moduleVersion) => {
66-
diag.debug(`Removing patch for ${MODULE_NAME}@${moduleVersion}`);
67-
62+
dataloader => {
6863
if (isWrapped(dataloader.prototype.load)) {
6964
this._unwrap(dataloader.prototype, 'load');
7065
}

plugins/node/instrumentation-fs/src/instrumentation.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export default class FsInstrumentation extends InstrumentationBase {
6565
'fs',
6666
['*'],
6767
(fs: FS) => {
68-
this._diag.debug('Applying patch for fs');
6968
for (const fName of SYNC_FUNCTIONS) {
7069
const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);
7170

@@ -113,7 +112,6 @@ export default class FsInstrumentation extends InstrumentationBase {
113112
},
114113
(fs: FS) => {
115114
if (fs === undefined) return;
116-
this._diag.debug('Removing patch for fs');
117115
for (const fName of SYNC_FUNCTIONS) {
118116
const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);
119117
if (isWrapped(objectToPatch[functionNameToPatch])) {
@@ -137,7 +135,6 @@ export default class FsInstrumentation extends InstrumentationBase {
137135
'fs/promises',
138136
['*'],
139137
(fsPromises: FSPromises) => {
140-
this._diag.debug('Applying patch for fs/promises');
141138
for (const fName of PROMISE_FUNCTIONS) {
142139
if (isWrapped(fsPromises[fName])) {
143140
this._unwrap(fsPromises, fName);
@@ -152,7 +149,6 @@ export default class FsInstrumentation extends InstrumentationBase {
152149
},
153150
(fsPromises: FSPromises) => {
154151
if (fsPromises === undefined) return;
155-
this._diag.debug('Removing patch for fs/promises');
156152
for (const fName of PROMISE_FUNCTIONS) {
157153
if (isWrapped(fsPromises[fName])) {
158154
this._unwrap(fsPromises, fName);

plugins/node/instrumentation-lru-memoizer/src/instrumentation.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export default class LruMemoizerInstrumentation extends InstrumentationBase {
3333
'lru-memoizer',
3434
['>=1.3 <3'],
3535
moduleExports => {
36-
this._diag.debug('applying patch for lru-memoizer');
37-
3836
// moduleExports is a function which receives an options object,
3937
// and returns a "memoizer" function upon invocation.
4038
// We want to patch this "memoizer's" internal function

plugins/node/instrumentation-mongoose/src/mongoose.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export class MongooseInstrumentation extends InstrumentationBase {
126126
}
127127

128128
private unpatch(moduleExports: typeof mongoose): void {
129-
this._diag.debug('mongoose instrumentation: unpatch mongoose');
130129
this._unwrap(moduleExports.Model.prototype, 'save');
131130
// revert the patch for $save which we applied by aliasing it to patched `save`
132131
moduleExports.Model.prototype.$save = moduleExports.Model.prototype.save;

plugins/node/instrumentation-socket.io/src/socket.io.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
7272
if (moduleVersion === undefined) {
7373
return moduleExports;
7474
}
75-
this._diag.debug(`applying patch to socket.io@${moduleVersion} Socket`);
7675
if (isWrapped(moduleExports?.Socket?.prototype?.on)) {
7776
this._unwrap(moduleExports.Socket.prototype, 'on');
7877
}
@@ -112,9 +111,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
112111
if (moduleVersion === undefined) {
113112
return moduleExports;
114113
}
115-
this._diag.debug(
116-
`applying patch to socket.io@${moduleVersion} StrictEventEmitter`
117-
);
118114
if (isWrapped(moduleExports?.BroadcastOperator?.prototype?.emit)) {
119115
this._unwrap(moduleExports.BroadcastOperator.prototype, 'emit');
120116
}
@@ -142,9 +138,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
142138
if (moduleVersion === undefined) {
143139
return moduleExports;
144140
}
145-
this._diag.debug(
146-
`applying patch to socket.io@${moduleVersion} Namespace`
147-
);
148141
if (isWrapped(moduleExports?.Namespace?.prototype?.emit)) {
149142
this._unwrap(moduleExports.Namespace.prototype, 'emit');
150143
}
@@ -171,7 +164,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
171164
if (moduleVersion === undefined) {
172165
return moduleExports;
173166
}
174-
this._diag.debug(`applying patch to socket.io@${moduleVersion} Socket`);
175167
if (isWrapped(moduleExports.prototype?.on)) {
176168
this._unwrap(moduleExports.prototype, 'on');
177169
}
@@ -206,9 +198,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
206198
if (moduleVersion === undefined) {
207199
return moduleExports;
208200
}
209-
this._diag.debug(
210-
`applying patch to socket.io@${moduleVersion} Namespace`
211-
);
212201
if (isWrapped(moduleExports?.prototype?.emit)) {
213202
this._unwrap(moduleExports.prototype, 'emit');
214203
}
@@ -237,9 +226,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
237226
if (moduleVersion === undefined) {
238227
return moduleExports;
239228
}
240-
this._diag.debug(
241-
`applying patch to socket.io@${moduleVersion} Server`
242-
);
243229
if (isWrapped(moduleExports?.Server?.prototype?.on)) {
244230
this._unwrap(moduleExports.Server.prototype, 'on');
245231
}
@@ -250,7 +236,7 @@ export class SocketIoInstrumentation extends InstrumentationBase {
250236
);
251237
return moduleExports;
252238
},
253-
(moduleExports, moduleVersion) => {
239+
moduleExports => {
254240
if (isWrapped(moduleExports?.Server?.prototype?.on)) {
255241
this._unwrap(moduleExports.Server.prototype, 'on');
256242
}
@@ -272,9 +258,6 @@ export class SocketIoInstrumentation extends InstrumentationBase {
272258
if (moduleVersion === undefined) {
273259
return moduleExports;
274260
}
275-
this._diag.debug(
276-
`applying patch to socket.io@${moduleVersion} Server`
277-
);
278261
if (isWrapped(moduleExports?.prototype?.on)) {
279262
this._unwrap(moduleExports.prototype, 'on');
280263
}

plugins/node/instrumentation-tedious/src/instrumentation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ export class TediousInstrumentation extends InstrumentationBase {
7373
new InstrumentationNodeModuleDefinition(
7474
TediousInstrumentation.COMPONENT,
7575
['>=1.11.0 <=15'],
76-
(moduleExports: typeof tedious, moduleVersion) => {
77-
this._diag.debug(`Patching tedious@${moduleVersion}`);
78-
76+
(moduleExports: typeof tedious) => {
7977
const ConnectionPrototype: any = moduleExports.Connection.prototype;
8078
for (const method of PATCHED_METHODS) {
8179
if (isWrapped(ConnectionPrototype[method])) {

plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
151151
module,
152152
['*'],
153153
(moduleExports: LambdaModule) => {
154-
diag.debug('Applying patch for lambda handler');
155154
if (isWrapped(moduleExports[functionName])) {
156155
this._unwrap(moduleExports, functionName);
157156
}
@@ -160,7 +159,6 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
160159
},
161160
(moduleExports?: LambdaModule) => {
162161
if (moduleExports == null) return;
163-
diag.debug('Removing patch for lambda handler');
164162
this._unwrap(moduleExports, functionName);
165163
}
166164
),

plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ export class AwsInstrumentation extends InstrumentationBase {
174174
}
175175

176176
protected patchV3ConstructStack(moduleExports: any, moduleVersion?: string) {
177-
diag.debug(
178-
'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'
179-
);
180177
this._wrap(
181178
moduleExports,
182179
'constructStack',
@@ -186,17 +183,11 @@ export class AwsInstrumentation extends InstrumentationBase {
186183
}
187184

188185
protected unpatchV3ConstructStack(moduleExports: any) {
189-
diag.debug(
190-
'aws-sdk instrumentation: applying unpatch to aws-sdk v3 constructStack'
191-
);
192186
this._unwrap(moduleExports, 'constructStack');
193187
return moduleExports;
194188
}
195189

196190
protected patchV3SmithyClient(moduleExports: any) {
197-
diag.debug(
198-
'aws-sdk instrumentation: applying patch to aws-sdk v3 client send'
199-
);
200191
this._wrap(
201192
moduleExports.Client.prototype,
202193
'send',
@@ -206,17 +197,11 @@ export class AwsInstrumentation extends InstrumentationBase {
206197
}
207198

208199
protected unpatchV3SmithyClient(moduleExports: any) {
209-
diag.debug(
210-
'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'
211-
);
212200
this._unwrap(moduleExports.Client.prototype, 'send');
213201
return moduleExports;
214202
}
215203

216204
protected patchV2(moduleExports: any, moduleVersion?: string) {
217-
diag.debug(
218-
`aws-sdk instrumentation: applying patch to ${AwsInstrumentation.component}`
219-
);
220205
this.unpatchV2(moduleExports);
221206
this._wrap(
222207
moduleExports?.Request.prototype,

plugins/node/opentelemetry-instrumentation-bunyan/src/instrumentation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ export class BunyanInstrumentation extends InstrumentationBase {
4646
new InstrumentationNodeModuleDefinition(
4747
'bunyan',
4848
['<2.0'],
49-
(module: any, moduleVersion) => {
50-
this._diag.debug(`Applying patch for bunyan@${moduleVersion}`);
49+
(module: any) => {
5150
const instrumentation = this;
5251
const Logger =
5352
module[Symbol.toStringTag] === 'Module'

plugins/node/opentelemetry-instrumentation-cassandra/src/instrumentation.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ export class CassandraDriverInstrumentation extends InstrumentationBase {
5151
return new InstrumentationNodeModuleDefinition(
5252
'cassandra-driver',
5353
supportedVersions,
54-
(driverModule, moduleVersion) => {
55-
this._diag.debug(
56-
`Applying patch for cassandra-driver@${moduleVersion}`
57-
);
54+
driverModule => {
5855
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5956
const Client = driverModule.Client.prototype as any;
6057

@@ -76,10 +73,7 @@ export class CassandraDriverInstrumentation extends InstrumentationBase {
7673

7774
return driverModule;
7875
},
79-
(driverModule, moduleVersion) => {
80-
this._diag.debug(
81-
`Removing patch for cassandra-driver@${moduleVersion}`
82-
);
76+
driverModule => {
8377
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8478
const Client = driverModule.Client.prototype as any;
8579

plugins/node/opentelemetry-instrumentation-connect/src/instrumentation.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { context, diag, Span, SpanOptions } from '@opentelemetry/api';
17+
import { context, Span, SpanOptions } from '@opentelemetry/api';
1818
import { getRPCMetadata, RPCType } from '@opentelemetry/core';
1919
import type { HandleFunction, NextFunction, Server } from 'connect';
2020
import type { ServerResponse } from 'http';
@@ -55,12 +55,8 @@ export class ConnectInstrumentation extends InstrumentationBase {
5555
new InstrumentationNodeModuleDefinition(
5656
'connect',
5757
['^3.0.0'],
58-
(moduleExports, moduleVersion) => {
59-
diag.debug(`Applying patch for connect@${moduleVersion}`);
58+
moduleExports => {
6059
return this._patchConstructor(moduleExports);
61-
},
62-
(moduleExports, moduleVersion) => {
63-
diag.debug(`Removing patch for connect@${moduleVersion}`);
6460
}
6561
),
6662
];

plugins/node/opentelemetry-instrumentation-dns/src/instrumentation.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class DnsInstrumentation extends InstrumentationBase {
5050
'dns',
5151
['*'],
5252
(moduleExports: typeof dns) => {
53-
diag.debug('Applying patch for dns');
5453
if (isWrapped(moduleExports.lookup)) {
5554
this._unwrap(moduleExports, 'lookup');
5655
}
@@ -66,7 +65,6 @@ export class DnsInstrumentation extends InstrumentationBase {
6665
},
6766
moduleExports => {
6867
if (moduleExports === undefined) return;
69-
diag.debug('Removing patch for dns');
7068
this._unwrap(moduleExports, 'lookup');
7169
this._unwrap(moduleExports.promises, 'lookup');
7270
}
@@ -75,7 +73,6 @@ export class DnsInstrumentation extends InstrumentationBase {
7573
'dns/promises',
7674
['*'],
7775
(moduleExports: typeof dnsPromises) => {
78-
diag.debug('Applying patch for dns/promises');
7976
if (isWrapped(moduleExports.lookup)) {
8077
this._unwrap(moduleExports, 'lookup');
8178
}
@@ -85,7 +82,6 @@ export class DnsInstrumentation extends InstrumentationBase {
8582
},
8683
moduleExports => {
8784
if (moduleExports === undefined) return;
88-
diag.debug('Removing patch for dns/promises');
8985
this._unwrap(moduleExports, 'lookup');
9086
}
9187
),

plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export class ExpressInstrumentation extends InstrumentationBase {
7171
new InstrumentationNodeModuleDefinition(
7272
'express',
7373
['^4.0.0'],
74-
(moduleExports, moduleVersion) => {
75-
diag.debug(`Applying patch for express@${moduleVersion}`);
74+
moduleExports => {
7675
const routerProto = moduleExports.Router as unknown as express.Router;
7776
// patch express.Router.route
7877
if (isWrapped(routerProto.route)) {
@@ -97,9 +96,8 @@ export class ExpressInstrumentation extends InstrumentationBase {
9796
);
9897
return moduleExports;
9998
},
100-
(moduleExports, moduleVersion) => {
99+
moduleExports => {
101100
if (moduleExports === undefined) return;
102-
diag.debug(`Removing patch for express@${moduleVersion}`);
103101
const routerProto = moduleExports.Router as unknown as express.Router;
104102
this._unwrap(routerProto, 'route');
105103
this._unwrap(routerProto, 'use');

plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ export class FastifyInstrumentation extends InstrumentationBase {
6868
new InstrumentationNodeModuleDefinition(
6969
'fastify',
7070
['^3.0.0', '^4.0.0'],
71-
(moduleExports, moduleVersion) => {
72-
this._diag.debug(`Applying patch for fastify@${moduleVersion}`);
71+
moduleExports => {
7372
return this._patchConstructor(moduleExports);
7473
}
7574
),

0 commit comments

Comments
 (0)