Last active
June 1, 2021 15:56
-
-
Save ahmadarif/05c16f9c141c3f2e54aee1bffac52223 to your computer and use it in GitHub Desktop.
Revisions
-
ahmadarif-lab revised this gist
Jun 1, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ Register middleware on root file ```ts require("elastic-apm-node").start(); // must be in the first line // other import libraries -
ahmadarif-lab created this gist
Jun 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import { ActionResult, CustomMiddleware, HttpStatusError, Invocation } from "@plumier/core"; import APM from 'elastic-apm-node'; export class APMMiddleware implements CustomMiddleware { async execute(next: Readonly<Invocation>): Promise<ActionResult> { if (next.ctx?.route?.url) { APM.setTransactionName(next.ctx.route.url); } else { APM.setTransactionName(next.ctx.url); } try { return await next.proceed(); } catch (e) { if (e instanceof HttpStatusError) { APM.captureError(e); } else { APM.captureError(e); } throw e; } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ Register middleware on root file ``` require("elastic-apm-node").start(); // must be in the first line // other import libraries ... new Plumier() .use(new APMMiddleware()) ... ```