Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove patch and unpatch diag from instrumentations #2107

Merged
merged 9 commits into from
Apr 25, 2024
16 changes: 2 additions & 14 deletions plugins/node/instrumentation-cucumber/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export class CucumberInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition<Cucumber>(
'@cucumber/cucumber',
['^8.0.0', '^9.0.0', '^10.0.0'],
(moduleExports, moduleVersion) => {
this._diag.debug(
`Applying patch for @cucumber/cucumber@${moduleVersion}`
);
moduleExports => {
this.module = moduleExports;
steps.forEach(step => {
if (isWrapped(moduleExports[step])) {
Expand All @@ -72,11 +69,8 @@ export class CucumberInstrumentation extends InstrumentationBase {
});
return moduleExports;
},
(moduleExports, moduleVersion) => {
moduleExports => {
JamieDanielson marked this conversation as resolved.
Show resolved Hide resolved
if (moduleExports === undefined) return;
this._diag.debug(
`Removing patch for @cucumber/cucumber@${moduleVersion}`
);
[...hooks, ...steps].forEach(method => {
this._unwrap(moduleExports, method);
});
Expand All @@ -88,9 +82,6 @@ export class CucumberInstrumentation extends InstrumentationBase {
'@cucumber/cucumber/lib/runtime/test_case_runner.js',
['^8.0.0', '^9.0.0', '^10.0.0'],
(moduleExports, moduleVersion) => {
this._diag.debug(
`Applying patch for @cucumber/cucumber/lib/runtime/test_case_runner.js@${moduleVersion}`
);
if (isWrapped(moduleExports.default.prototype.run)) {
this._unwrap(moduleExports.default.prototype, 'run');
this._unwrap(moduleExports.default.prototype, 'runStep');
Expand Down Expand Up @@ -119,9 +110,6 @@ export class CucumberInstrumentation extends InstrumentationBase {
},
(moduleExports, moduleVersion) => {
if (moduleExports === undefined) return;
this._diag.debug(
`Removing patch for @cucumber/cucumber/lib/runtime/test_case_runner.js@${moduleVersion}`
);
this._unwrap(moduleExports.default.prototype, 'run');
this._unwrap(moduleExports.default.prototype, 'runStep');
if ('runAttempt' in moduleExports.default.prototype) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
isWrapped,
} from '@opentelemetry/instrumentation';
import {
diag,
trace,
context,
Link,
Expand Down Expand Up @@ -54,17 +53,13 @@ export class DataloaderInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition<typeof Dataloader>(
MODULE_NAME,
['^2.0.0'],
(dataloader, moduleVersion) => {
diag.debug(`Applying patch for ${MODULE_NAME}@${moduleVersion}`);

dataloader => {
this._patchLoad(dataloader.prototype);
this._patchLoadMany(dataloader.prototype);

return this._getPatchedConstructor(dataloader);
},
(dataloader, moduleVersion) => {
diag.debug(`Removing patch for ${MODULE_NAME}@${moduleVersion}`);

dataloader => {
if (isWrapped(dataloader.prototype.load)) {
this._unwrap(dataloader.prototype, 'load');
}
Expand Down
4 changes: 0 additions & 4 deletions plugins/node/instrumentation-fs/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default class FsInstrumentation extends InstrumentationBase<FS> {
'fs',
['*'],
(fs: FS) => {
this._diag.debug('Applying patch for fs');
for (const fName of SYNC_FUNCTIONS) {
const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);

Expand Down Expand Up @@ -113,7 +112,6 @@ export default class FsInstrumentation extends InstrumentationBase<FS> {
},
(fs: FS) => {
if (fs === undefined) return;
this._diag.debug('Removing patch for fs');
for (const fName of SYNC_FUNCTIONS) {
const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);
if (isWrapped(objectToPatch[functionNameToPatch])) {
Expand All @@ -137,7 +135,6 @@ export default class FsInstrumentation extends InstrumentationBase<FS> {
'fs/promises',
['*'],
(fsPromises: FSPromises) => {
this._diag.debug('Applying patch for fs/promises');
for (const fName of PROMISE_FUNCTIONS) {
if (isWrapped(fsPromises[fName])) {
this._unwrap(fsPromises, fName);
Expand All @@ -152,7 +149,6 @@ export default class FsInstrumentation extends InstrumentationBase<FS> {
},
(fsPromises: FSPromises) => {
if (fsPromises === undefined) return;
this._diag.debug('Removing patch for fs/promises');
for (const fName of PROMISE_FUNCTIONS) {
if (isWrapped(fsPromises[fName])) {
this._unwrap(fsPromises, fName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export default class LruMemoizerInstrumentation extends InstrumentationBase {
'lru-memoizer',
['>=1.3 <3'],
moduleExports => {
this._diag.debug('applying patch for lru-memoizer');

// moduleExports is a function which receives an options object,
// and returns a "memoizer" function upon invocation.
// We want to patch this "memoizer's" internal function
Expand Down
17 changes: 0 additions & 17 deletions plugins/node/instrumentation-socket.io/src/socket.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(`applying patch to socket.io@${moduleVersion} Socket`);
if (isWrapped(moduleExports?.Socket?.prototype?.on)) {
this._unwrap(moduleExports.Socket.prototype, 'on');
}
Expand Down Expand Up @@ -113,9 +112,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(
`applying patch to socket.io@${moduleVersion} StrictEventEmitter`
);
if (isWrapped(moduleExports?.BroadcastOperator?.prototype?.emit)) {
this._unwrap(moduleExports.BroadcastOperator.prototype, 'emit');
}
Expand Down Expand Up @@ -143,9 +139,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(
`applying patch to socket.io@${moduleVersion} Namespace`
);
if (isWrapped(moduleExports?.Namespace?.prototype?.emit)) {
this._unwrap(moduleExports.Namespace.prototype, 'emit');
}
Expand All @@ -172,7 +165,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(`applying patch to socket.io@${moduleVersion} Socket`);
if (isWrapped(moduleExports.prototype?.on)) {
this._unwrap(moduleExports.prototype, 'on');
}
Expand Down Expand Up @@ -208,9 +200,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(
`applying patch to socket.io@${moduleVersion} Namespace`
);
if (isWrapped(moduleExports?.prototype?.emit)) {
this._unwrap(moduleExports.prototype, 'emit');
}
Expand Down Expand Up @@ -239,9 +228,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(
`applying patch to socket.io@${moduleVersion} Server`
);
if (isWrapped(moduleExports?.Server?.prototype?.on)) {
this._unwrap(moduleExports.Server.prototype, 'on');
}
Expand Down Expand Up @@ -274,9 +260,6 @@ export class SocketIoInstrumentation extends InstrumentationBase<any> {
if (moduleVersion === undefined) {
return moduleExports;
}
this._diag.debug(
`applying patch to socket.io@${moduleVersion} Server`
);
if (isWrapped(moduleExports?.prototype?.on)) {
this._unwrap(moduleExports.prototype, 'on');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export class TediousInstrumentation extends InstrumentationBase<
new InstrumentationNodeModuleDefinition<typeof tedious>(
TediousInstrumentation.COMPONENT,
['>=1.11.0 <=15'],
(moduleExports: any, moduleVersion) => {
this._diag.debug(`Patching tedious@${moduleVersion}`);

(moduleExports: any) => {
const ConnectionPrototype: any = moduleExports.Connection.prototype;
for (const method of PATCHED_METHODS) {
if (isWrapped(ConnectionPrototype[method])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
module,
['*'],
(moduleExports: LambdaModule) => {
diag.debug('Applying patch for lambda handler');
if (isWrapped(moduleExports[functionName])) {
this._unwrap(moduleExports, functionName);
}
Expand All @@ -159,7 +158,6 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
},
(moduleExports?: LambdaModule) => {
if (moduleExports == null) return;
diag.debug('Removing patch for lambda handler');
this._unwrap(moduleExports, functionName);
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ export class AwsInstrumentation extends InstrumentationBase<any> {
}

protected patchV3ConstructStack(moduleExports: any, moduleVersion?: string) {
diag.debug(
'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'
);
this._wrap(
moduleExports,
'constructStack',
Expand All @@ -185,17 +182,11 @@ export class AwsInstrumentation extends InstrumentationBase<any> {
}

protected unpatchV3ConstructStack(moduleExports: any) {
diag.debug(
'aws-sdk instrumentation: applying unpatch to aws-sdk v3 constructStack'
);
this._unwrap(moduleExports, 'constructStack');
return moduleExports;
}

protected patchV3SmithyClient(moduleExports: any) {
diag.debug(
'aws-sdk instrumentation: applying patch to aws-sdk v3 client send'
);
this._wrap(
moduleExports.Client.prototype,
'send',
Expand All @@ -205,17 +196,11 @@ export class AwsInstrumentation extends InstrumentationBase<any> {
}

protected unpatchV3SmithyClient(moduleExports: any) {
diag.debug(
'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'
);
this._unwrap(moduleExports.Client.prototype, 'send');
return moduleExports;
}

protected patchV2(moduleExports: any, moduleVersion?: string) {
diag.debug(
`aws-sdk instrumentation: applying patch to ${AwsInstrumentation.component}`
);
this.unpatchV2(moduleExports);
this._wrap(
moduleExports?.Request.prototype,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class BunyanInstrumentation extends InstrumentationBase<
'bunyan',
['<2.0'],
(module: any, moduleVersion) => {
this._diag.debug(`Applying patch for bunyan@${moduleVersion}`);
const instrumentation = this;
const Logger =
module[Symbol.toStringTag] === 'Module'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export class CassandraDriverInstrumentation extends InstrumentationBase {
'cassandra-driver',
supportedVersions,
(driverModule, moduleVersion) => {
this._diag.debug(
`Applying patch for cassandra-driver@${moduleVersion}`
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Client = driverModule.Client.prototype as any;

Expand All @@ -77,9 +74,6 @@ export class CassandraDriverInstrumentation extends InstrumentationBase {
return driverModule;
},
(driverModule, moduleVersion) => {
this._diag.debug(
`Removing patch for cassandra-driver@${moduleVersion}`
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Client = driverModule.Client.prototype as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { context, diag, Span, SpanOptions } from '@opentelemetry/api';
import { context, Span, SpanOptions } from '@opentelemetry/api';
import { getRPCMetadata, RPCType } from '@opentelemetry/core';
import type { HandleFunction, NextFunction, Server } from 'connect';
import type { ServerResponse } from 'http';
Expand Down Expand Up @@ -55,12 +55,8 @@ export class ConnectInstrumentation extends InstrumentationBase<Server> {
new InstrumentationNodeModuleDefinition<any>(
'connect',
['^3.0.0'],
(moduleExports, moduleVersion) => {
diag.debug(`Applying patch for connect@${moduleVersion}`);
moduleExports => {
return this._patchConstructor(moduleExports);
},
(moduleExports, moduleVersion) => {
diag.debug(`Removing patch for connect@${moduleVersion}`);
}
),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class DnsInstrumentation extends InstrumentationBase<Dns> {
'dns',
['*'],
moduleExports => {
diag.debug('Applying patch for dns');
if (isWrapped(moduleExports.lookup)) {
this._unwrap(moduleExports, 'lookup');
}
Expand All @@ -66,7 +65,6 @@ export class DnsInstrumentation extends InstrumentationBase<Dns> {
},
moduleExports => {
if (moduleExports === undefined) return;
diag.debug('Removing patch for dns');
this._unwrap(moduleExports, 'lookup');
this._unwrap(moduleExports.promises, 'lookup');
}
Expand All @@ -75,7 +73,6 @@ export class DnsInstrumentation extends InstrumentationBase<Dns> {
'dns/promises',
['*'],
moduleExports => {
diag.debug('Applying patch for dns/promises');
if (isWrapped(moduleExports.lookup)) {
this._unwrap(moduleExports, 'lookup');
}
Expand All @@ -85,7 +82,6 @@ export class DnsInstrumentation extends InstrumentationBase<Dns> {
},
moduleExports => {
if (moduleExports === undefined) return;
diag.debug('Removing patch for dns/promises');
this._unwrap(moduleExports, 'lookup');
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class ExpressInstrumentation extends InstrumentationBase<
'express',
['^4.0.0'],
(moduleExports, moduleVersion) => {
diag.debug(`Applying patch for express@${moduleVersion}`);
const routerProto = moduleExports.Router as unknown as express.Router;
// patch express.Router.route
if (isWrapped(routerProto.route)) {
Expand All @@ -101,7 +100,6 @@ export class ExpressInstrumentation extends InstrumentationBase<
},
(moduleExports, moduleVersion) => {
if (moduleExports === undefined) return;
diag.debug(`Removing patch for express@${moduleVersion}`);
const routerProto = moduleExports.Router as unknown as express.Router;
this._unwrap(routerProto, 'route');
this._unwrap(routerProto, 'use');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class FastifyInstrumentation extends InstrumentationBase {
'fastify',
['^3.0.0', '^4.0.0'],
(moduleExports, moduleVersion) => {
this._diag.debug(`Applying patch for fastify@${moduleVersion}`);
return this._patchConstructor(moduleExports);
}
),
Expand Down
Loading
Loading