diff --git a/server/server/src/apm.ts b/server/server/src/apm.ts index 2601a3a1d1c..754a19b035e 100644 --- a/server/server/src/apm.ts +++ b/server/server/src/apm.ts @@ -1,4 +1,4 @@ -import { MeasureContext, MeasureLogger, ParamType } from '@hcengineering/core' +import { MeasureContext, MeasureLogger, ParamType, ParamsType } from '@hcengineering/core' import apm, { Agent, Span, Transaction } from 'elastic-apm-node' /** @@ -65,8 +65,9 @@ export class APMMeasureContext implements MeasureContext { async with( name: string, - params: Record, - op: (ctx: MeasureContext) => T | Promise + params: ParamsType, + op: (ctx: MeasureContext) => T | Promise, + fullParams?: ParamsType ): Promise { const c = this.newChild(name, params) try { @@ -82,6 +83,18 @@ export class APMMeasureContext implements MeasureContext { } } + async withLog( + name: string, + params: ParamsType, + op: (ctx: MeasureContext) => T | Promise, + fullParams?: ParamsType + ): Promise { + const st = Date.now() + const r = await this.with(name, params, op, fullParams) + this.logger.logOperation(name, Date.now() - st, { ...params, ...fullParams }) + return r + } + async error (message: string, ...args: any[]): Promise { this.logger.error(message, args)