[NEW] Option to trace Methods and Subscription calls (#11085)

pull/10958/head^2
Rodrigo Nascimento 7 years ago committed by GitHub
parent f9d17afcff
commit bbc0fcf3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/rocketchat-i18n/i18n/en.i18n.json
  2. 3
      packages/rocketchat-lib/package.js
  3. 33
      packages/rocketchat-lib/server/lib/debug.js
  4. 24
      packages/rocketchat-lib/server/startup/settings.js

@ -1570,11 +1570,17 @@
"Loading_more_from_history": "Loading more from history",
"Loading_suggestion": "Loading suggestions",
"Localization": "Localization",
"Log_Exceptions_to_Channel": "Log Exceptions to Channel",
"Log_Exceptions_to_Channel_Description": "A channel that will receive all captured exceptions. Leave empty to ignore exceptions.",
"Log_Exceptions_to_Channel": "Log Exceptions to Channel",
"Log_File": "Show File and Line",
"Log_Level": "Log Level",
"Log_Package": "Show Package",
"Log_Trace_Methods_Filter": "Trace method filter",
"Log_Trace_Methods_Filter_Description": "The text here will be evaluated as RegExp (`new RegExp('text')`). Keep it empty to show trace of every call.",
"Log_Trace_Methods": "Trace method calls",
"Log_Trace_Subscriptions_Filter": "Trace subscription filter",
"Log_Trace_Subscriptions_Filter_Description": "The text here will be evaluated as RegExp (`new RegExp('text')`). Keep it empty to show trace of every call.",
"Log_Trace_Subscriptions": "Trace subscription calls",
"Log_View_Limit": "Log View Limit",
"Logged_out_of_other_clients_successfully": "Logged out of other clients successfully",
"Login": "Login",

@ -37,6 +37,8 @@ Package.onUse(function(api) {
api.addFiles('lib/core.js');
api.addFiles('lib/settings.js');
// DEBUGGER
api.addFiles('server/lib/debug.js', 'server');
@ -54,7 +56,6 @@ Package.onUse(function(api) {
// COMMON LIB
api.addFiles('lib/getURL.js');
api.addFiles('lib/settings.js');
api.addFiles('lib/callbacks.js');
api.addFiles('lib/fileUploadRestrictions.js');
api.addFiles('lib/getAvatarColor.js');

@ -12,8 +12,40 @@ const logger = new Logger('Meteor', {
}
});
let Log_Trace_Methods;
let Log_Trace_Subscriptions;
RocketChat.settings.get('Log_Trace_Methods', (key, value) => Log_Trace_Methods = value);
RocketChat.settings.get('Log_Trace_Subscriptions', (key, value) => Log_Trace_Subscriptions = value);
let Log_Trace_Methods_Filter;
let Log_Trace_Subscriptions_Filter;
RocketChat.settings.get('Log_Trace_Methods_Filter', (key, value) => Log_Trace_Methods_Filter = value ? new RegExp(value) : undefined);
RocketChat.settings.get('Log_Trace_Subscriptions_Filter', (key, value) => Log_Trace_Subscriptions_Filter = value ? new RegExp(value) : undefined);
const traceConnection = (enable, filter, prefix, name, connection, userId) => {
if (!enable) {
return;
}
if (filter && !filter.test(name)) {
return;
}
if (connection) {
console.log(name, {
id: connection.id,
clientAddress: connection.clientAddress,
httpHeaders: connection.httpHeaders,
userId
});
} else {
console.log(name, 'no-connection');
}
};
const wrapMethods = function(name, originalHandler, methodsMap) {
methodsMap[name] = function() {
traceConnection(Log_Trace_Methods, Log_Trace_Methods_Filter, 'method', name, this.connection, this.userId);
const end = RocketChat.metrics.meteorMethods.startTimer({method: name});
const args = name === 'ufsWrite' ? Array.prototype.slice.call(arguments, 1) : arguments;
logger.method(name, '-> userId:', Meteor.userId(), ', arguments: ', args);
@ -37,6 +69,7 @@ const originalMeteorPublish = Meteor.publish;
Meteor.publish = function(name, func) {
return originalMeteorPublish(name, function() {
traceConnection(Log_Trace_Subscriptions, Log_Trace_Subscriptions_Filter, 'subscription', name, this.connection, this.userId);
logger.publish(name, '-> userId:', this.userId, ', arguments: ', arguments);
const end = RocketChat.metrics.meteorSubscriptions.startTimer({subscription: name});

@ -1681,6 +1681,30 @@ RocketChat.settings.addGroup('Logs', function() {
type: 'int'
});
this.add('Log_Trace_Methods', false, {
type: 'boolean'
});
this.add('Log_Trace_Methods_Filter', '', {
type: 'string',
enableQuery: {
_id: 'Log_Trace_Methods',
value: true
}
});
this.add('Log_Trace_Subscriptions', false, {
type: 'boolean'
});
this.add('Log_Trace_Subscriptions_Filter', '', {
type: 'string',
enableQuery: {
_id: 'Log_Trace_Subscriptions',
value: true
}
});
this.section('Prometheus', function() {
this.add('Prometheus_Enabled', false, {
type: 'boolean',

Loading…
Cancel
Save