Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into patch-log
  • Loading branch information
blumamir committed Apr 25, 2024
commit 52584023661ac464587bee3a7cd2069693c9f6a3
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CucumberInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
'@cucumber/cucumber',
['^8.0.0', '^9.0.0', '^10.0.0'],
moduleExports => {
(moduleExports: Cucumber) => {
this.module = moduleExports;
steps.forEach(step => {
if (isWrapped(moduleExports[step])) {
Expand All @@ -69,7 +69,7 @@ export class CucumberInstrumentation extends InstrumentationBase {
});
return moduleExports;
},
moduleExports => {
(moduleExports: Cucumber) => {
if (moduleExports === undefined) return;
[...hooks, ...steps].forEach(method => {
this._unwrap(moduleExports, method);
Expand Down
62 changes: 11 additions & 51 deletions plugins/node/instrumentation-socket.io/src/socket.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,16 @@ export class SocketIoInstrumentation extends InstrumentationBase {
}
);

const broadcastOperatorInstrumentation =
new InstrumentationNodeModuleFile<any>(
'socket.io/dist/broadcast-operator.js',
['>=4 <5'],
(moduleExports, moduleVersion) => {
if (moduleExports === undefined || moduleExports === null) {
return moduleExports;
}
if (moduleVersion === undefined) {
return moduleExports;
}
if (isWrapped(moduleExports?.BroadcastOperator?.prototype?.emit)) {
this._unwrap(moduleExports.BroadcastOperator.prototype, 'emit');
}
this._wrap(
moduleExports.BroadcastOperator.prototype,
'emit',
this._patchEmit(moduleVersion)
);
return moduleExports;
},
moduleExports => {
if (isWrapped(moduleExports?.BroadcastOperator?.prototype?.emit)) {
this._unwrap(moduleExports.BroadcastOperator.prototype, 'emit');
}
const broadcastOperatorInstrumentation = new InstrumentationNodeModuleFile(
'socket.io/dist/broadcast-operator.js',
['>=4 <5'],
(moduleExports, moduleVersion) => {
if (moduleExports === undefined || moduleExports === null) {
return moduleExports;
}
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 @@ -211,33 +188,16 @@ export class SocketIoInstrumentation extends InstrumentationBase {
return moduleExports;
}
);
const namespaceInstrumentationLegacy =
new InstrumentationNodeModuleFile<any>(
'socket.io/lib/namespace.js',
['2'],
(moduleExports, moduleVersion) => {
if (moduleExports === undefined || moduleExports === null) {
return moduleExports;
}
if (moduleVersion === undefined) {
return moduleExports;
}
if (isWrapped(moduleExports?.prototype?.emit)) {
this._unwrap(moduleExports.prototype, 'emit');
}
this._wrap(
moduleExports.prototype,
'emit',
this._patchEmit(moduleVersion)
);
const namespaceInstrumentationLegacy = new InstrumentationNodeModuleFile(
'socket.io/lib/namespace.js',
['2'],
(moduleExports, moduleVersion) => {
if (moduleExports === undefined || moduleExports === null) {
return moduleExports;
}
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 @@ -276,7 +236,7 @@ export class SocketIoInstrumentation extends InstrumentationBase {
);
return moduleExports;
},
(moduleExports, moduleVersion) => {
moduleExports => {
if (isWrapped(moduleExports?.Server?.prototype?.on)) {
this._unwrap(moduleExports.Server.prototype, 'on');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class TediousInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
TediousInstrumentation.COMPONENT,
['>=1.11.0 <=15'],
(moduleExports: any) => {
(moduleExports: typeof tedious) => {
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 @@ -49,7 +49,7 @@ export class DnsInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
'dns',
['*'],
moduleExports => {
(moduleExports: typeof dns) => {
if (isWrapped(moduleExports.lookup)) {
this._unwrap(moduleExports, 'lookup');
}
Expand All @@ -72,7 +72,7 @@ export class DnsInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
'dns/promises',
['*'],
moduleExports => {
(moduleExports: typeof dnsPromises) => {
if (isWrapped(moduleExports.lookup)) {
this._unwrap(moduleExports, 'lookup');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ export class GraphQLInstrumentation extends InstrumentationBase {
return new InstrumentationNodeModuleFile(
'graphql/language/parser.js',
supportedVersions,
moduleExports => {
(moduleExports: typeof graphqlTypes) => {
if (isWrapped(moduleExports.parse)) {
this._unwrap(moduleExports, 'parse');
}
this._wrap(moduleExports, 'parse', this._patchParse());
return moduleExports;
},
moduleExports => {
(moduleExports: typeof graphqlTypes) => {
if (moduleExports) {
this._unwrap(moduleExports, 'parse');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class HapiInstrumentation extends InstrumentationBase {
}
return moduleExports;
},
moduleExports => {
(moduleExports: typeof Hapi) => {
this._massUnwrap([moduleExports], ['server', 'Server']);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ export class Instrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
'memcached',
['>=2.2'],
(moduleExports, moduleVersion) => {
(moduleExports: typeof Memcached, moduleVersion) => {
this.ensureWrapped(
moduleExports.prototype,
'command',
this.wrapCommand.bind(this, moduleVersion)
);
return moduleExports;
},
moduleExports => {
(moduleExports: typeof Memcached) => {
if (moduleExports === undefined) return;
// `command` is documented API missing from the types
this._unwrap(moduleExports.prototype, 'command' as keyof Memcached);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class MySQLInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
'mysql',
['2.*'],
moduleExports => {
(moduleExports: typeof mysqlTypes) => {
diag.debug('Patching mysql.createConnection');
if (isWrapped(moduleExports.createConnection)) {
this._unwrap(moduleExports, 'createConnection');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class NetInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleDefinition(
'net',
['*'],
moduleExports => {
(moduleExports: typeof net) => {
if (isWrapped(moduleExports.Socket.prototype.connect)) {
this._unwrap(moduleExports.Socket.prototype, 'connect');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PgInstrumentation extends InstrumentationBase {
const modulePGPool = new InstrumentationNodeModuleDefinition(
'pg-pool',
['2.*', '3.*'],
moduleExports => {
(moduleExports: typeof pgPoolTypes) => {
if (isWrapped(moduleExports.prototype.connect)) {
this._unwrap(moduleExports.prototype, 'connect');
}
Expand All @@ -107,7 +107,7 @@ export class PgInstrumentation extends InstrumentationBase {
);
return moduleExports;
},
moduleExports => {
(moduleExports: typeof pgPoolTypes) => {
if (isWrapped(moduleExports.prototype.connect)) {
this._unwrap(moduleExports.prototype, 'connect');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,56 +44,52 @@ export class PinoInstrumentation extends InstrumentationBase {

protected init() {
return [
new InstrumentationNodeModuleDefinition(
'pino',
pinoVersions,
module => {
const isESM = module[Symbol.toStringTag] === 'Module';
const moduleExports = isESM ? module.default : module;
const instrumentation = this;
const patchedPino = Object.assign((...args: unknown[]) => {
if (args.length === 0) {
return moduleExports({
new InstrumentationNodeModuleDefinition('pino', pinoVersions, module => {
const isESM = module[Symbol.toStringTag] === 'Module';
const moduleExports = isESM ? module.default : module;
const instrumentation = this;
const patchedPino = Object.assign((...args: unknown[]) => {
if (args.length === 0) {
return moduleExports({
mixin: instrumentation._getMixinFunction(),
});
}

if (args.length === 1) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const optsOrStream = args[0] as any;
if (
typeof optsOrStream === 'string' ||
typeof optsOrStream?.write === 'function'
) {
args.splice(0, 0, {
mixin: instrumentation._getMixinFunction(),
});
return moduleExports(...args);
}
}

if (args.length === 1) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const optsOrStream = args[0] as any;
if (
typeof optsOrStream === 'string' ||
typeof optsOrStream?.write === 'function'
) {
args.splice(0, 0, {
mixin: instrumentation._getMixinFunction(),
});
return moduleExports(...args);
}
}

args[0] = instrumentation._combineOptions(args[0]);
args[0] = instrumentation._combineOptions(args[0]);

return moduleExports(...args);
}, moduleExports);
return moduleExports(...args);
}, moduleExports);

if (typeof patchedPino.pino === 'function') {
patchedPino.pino = patchedPino;
}
if (typeof patchedPino.default === 'function') {
patchedPino.default = patchedPino;
}
if (isESM) {
if (module.pino) {
// This was added in [email protected] (https://github.com/pinojs/pino/pull/936).
module.pino = patchedPino;
}
module.default = patchedPino;
if (typeof patchedPino.pino === 'function') {
patchedPino.pino = patchedPino;
}
if (typeof patchedPino.default === 'function') {
patchedPino.default = patchedPino;
}
if (isESM) {
if (module.pino) {
// This was added in [email protected] (https://github.com/pinojs/pino/pull/936).
module.pino = patchedPino;
}

return patchedPino;
module.default = patchedPino;
}
),

return patchedPino;
}),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { isPromise, isAsyncFunction } from './utils';
import { getRPCMetadata, RPCType } from '@opentelemetry/core';
import type { RestifyInstrumentationConfig } from './types';

export class RestifyInstrumentation extends InstrumentationBase<any> {
export class RestifyInstrumentation extends InstrumentationBase {
constructor(config: RestifyInstrumentationConfig = {}) {
super(
`@opentelemetry/instrumentation-${constants.MODULE_NAME}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class WinstonInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleFile(
'winston/lib/winston/logger.js',
winston3Versions,
logger => {
(logger: Winston3Logger) => {
if (isWrapped(logger.prototype['write'])) {
this._unwrap(logger.prototype, 'write');
}
Expand All @@ -70,7 +70,7 @@ export class WinstonInstrumentation extends InstrumentationBase {

return logger;
},
logger => {
(logger: Winston3Logger) => {
if (logger === undefined) return;
this._unwrap(logger.prototype, 'write');
this._unwrap(logger.prototype, 'configure');
Expand All @@ -89,7 +89,7 @@ export class WinstonInstrumentation extends InstrumentationBase {
new InstrumentationNodeModuleFile(
'winston/lib/winston/logger.js',
winstonPre3Versions,
fileExports => {
(fileExports: Winston2LoggerModule) => {
const proto = fileExports.Logger.prototype;

if (isWrapped(proto.log)) {
Expand All @@ -99,7 +99,7 @@ export class WinstonInstrumentation extends InstrumentationBase {

return fileExports;
},
fileExports => {
(fileExports: Winston2LoggerModule) => {
if (fileExports === undefined) return;
this._unwrap(fileExports.Logger.prototype, 'log');
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.