Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
139 lines
3.8 KiB
JavaScript
139 lines
3.8 KiB
JavaScript
import { InstanceStatus } from '@rocket.chat/instance-status';
|
|
import { Logger } from '@rocket.chat/logger';
|
|
import { tracerActiveSpan } from '@rocket.chat/tracing';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { WebApp } from 'meteor/webapp';
|
|
import _ from 'underscore';
|
|
|
|
import { getMethodArgs } from './logger/logPayloads';
|
|
import { metrics } from './metrics';
|
|
import { settings } from '../settings';
|
|
import { getModifiedHttpHeaders } from './shared/getModifiedHttpHeaders';
|
|
|
|
const logger = new Logger('Meteor');
|
|
|
|
let Log_Trace_Methods;
|
|
let Log_Trace_Subscriptions;
|
|
settings.watch('Log_Trace_Methods', (value) => {
|
|
Log_Trace_Methods = value;
|
|
});
|
|
settings.watch('Log_Trace_Subscriptions', (value) => {
|
|
Log_Trace_Subscriptions = value;
|
|
});
|
|
|
|
let Log_Trace_Methods_Filter;
|
|
let Log_Trace_Subscriptions_Filter;
|
|
settings.watch('Log_Trace_Methods_Filter', (value) => {
|
|
Log_Trace_Methods_Filter = value ? new RegExp(value) : undefined;
|
|
});
|
|
settings.watch('Log_Trace_Subscriptions_Filter', (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: getModifiedHttpHeaders(connection.httpHeaders),
|
|
userId,
|
|
});
|
|
} else {
|
|
console.log(name, 'no-connection');
|
|
}
|
|
};
|
|
|
|
const wrapMethods = function (name, originalHandler, methodsMap) {
|
|
methodsMap[name] = function (...originalArgs) {
|
|
traceConnection(Log_Trace_Methods, Log_Trace_Methods_Filter, 'method', name, this.connection, this.userId);
|
|
|
|
const method = name === 'stream' ? `${name}:${originalArgs[0]}` : name;
|
|
|
|
const meteorMethodLabels = {
|
|
method,
|
|
has_connection: this.connection != null,
|
|
has_user: this.userId != null,
|
|
};
|
|
|
|
const end = metrics.meteorMethods.startTimer(meteorMethodLabels);
|
|
const endHistogram = metrics.meteorMethodsSeconds.startTimer(meteorMethodLabels);
|
|
|
|
logger.method({
|
|
method,
|
|
userId: Meteor.userId(),
|
|
userAgent: this.connection?.httpHeaders['user-agent'],
|
|
referer: this.connection?.httpHeaders.referer,
|
|
remoteIP: this.connection?.clientAddress,
|
|
instanceId: InstanceStatus.id(),
|
|
...getMethodArgs(name, originalArgs),
|
|
});
|
|
|
|
return tracerActiveSpan(
|
|
`Method ${name}`,
|
|
{
|
|
attributes: {
|
|
method: name,
|
|
userId: this.userId,
|
|
},
|
|
},
|
|
async () => {
|
|
const result = await originalHandler.apply(this, originalArgs);
|
|
end();
|
|
endHistogram();
|
|
return result;
|
|
},
|
|
);
|
|
};
|
|
};
|
|
|
|
const originalMeteorMethods = Meteor.methods;
|
|
|
|
Meteor.methods = function (methodMap) {
|
|
_.each(methodMap, (handler, name) => {
|
|
wrapMethods(name, handler, methodMap);
|
|
});
|
|
originalMeteorMethods(methodMap);
|
|
};
|
|
|
|
const originalMeteorPublish = Meteor.publish;
|
|
|
|
Meteor.publish = function (name, func) {
|
|
return originalMeteorPublish(name, function (...args) {
|
|
traceConnection(Log_Trace_Subscriptions, Log_Trace_Subscriptions_Filter, 'subscription', name, this.connection, this.userId);
|
|
|
|
logger.subscription({
|
|
publication: name,
|
|
userId: this.userId,
|
|
userAgent: this.connection?.httpHeaders['user-agent'],
|
|
referer: this.connection?.httpHeaders.referer,
|
|
remoteIP: this.connection?.clientAddress,
|
|
instanceId: InstanceStatus.id(),
|
|
});
|
|
|
|
const end = metrics.meteorSubscriptions.startTimer({ subscription: name });
|
|
const endHistogram = metrics.meteorSubscriptionsSeconds.startTimer({ subscription: name });
|
|
|
|
const originalReady = this.ready;
|
|
this.ready = function () {
|
|
end();
|
|
endHistogram();
|
|
return originalReady.apply(this, args);
|
|
};
|
|
|
|
return func.apply(this, args);
|
|
});
|
|
};
|
|
|
|
WebApp.rawConnectHandlers.use((req, res, next) => {
|
|
res.setHeader('X-Instance-ID', InstanceStatus.id());
|
|
return next();
|
|
});
|