diff --git a/apps/meteor/app/apps/server/bridges/experimental.ts b/apps/meteor/app/apps/server/bridges/experimental.ts index 6c3f551db0d15..203097afeea7a 100644 --- a/apps/meteor/app/apps/server/bridges/experimental.ts +++ b/apps/meteor/app/apps/server/bridges/experimental.ts @@ -2,16 +2,30 @@ import type { IAppServerOrchestrator } from '@rocket.chat/apps'; import { ExperimentalBridge } from '@rocket.chat/apps-engine/server/bridges'; import { Subscriptions } from '@rocket.chat/models'; +import { metrics } from '../../../metrics/server/lib/metrics'; + export class AppExperimentalBridge extends ExperimentalBridge { constructor(private readonly orch: IAppServerOrchestrator) { super(); } protected async getUserRoomIds(userId: string, appId: string): Promise { - this.orch.debugLog(`The App ${appId} is getting the room ids for the user: "${userId}"`); + const stopTimer = metrics.appBridgeMethods.startTimer({ + bridge: 'experimental', + method: 'getUserRoomIds', + app_id: appId, + }); + + try { + this.orch.debugLog(`The App ${appId} is getting the room ids for the user: "${userId}"`); + + const subscriptions = await Subscriptions.findByUserId(userId, { projection: { rid: 1 } }).toArray(); - const subscriptions = await Subscriptions.findByUserId(userId, { projection: { rid: 1 } }).toArray(); + const result = subscriptions.map((subscription) => subscription.rid); - return subscriptions.map((subscription) => subscription.rid); + return result; + } finally { + stopTimer(); + } } } diff --git a/apps/meteor/app/metrics/server/lib/metrics.ts b/apps/meteor/app/metrics/server/lib/metrics.ts index 2f1d1d9e7a852..36967954a8dbb 100644 --- a/apps/meteor/app/metrics/server/lib/metrics.ts +++ b/apps/meteor/app/metrics/server/lib/metrics.ts @@ -199,6 +199,12 @@ export const metrics = { name: 'rocketchat_apps_failed', help: 'total apps that failed to load', }), + appBridgeMethods: new client.Summary({ + name: 'rocketchat_apps_bridge_methods', + help: 'summary of app bridge method calls count and time', + labelNames: ['bridge', 'method', 'app_id'], + percentiles, + }), // Meteor Facts meteorFacts: new client.Gauge({