From 9c181798ef1467df9109ed54bbd4a612382a6490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Mon, 25 Mar 2024 01:59:13 +0000 Subject: [PATCH] feat: set name of middleware function to improve interop with monitoring tools (#159) Set name of middleware function to improve interop with monitoring tools. Tools like [@opentelemetry/instrumentation-koa](https://www.npmjs.com/package/@opentelemetry/instrumentation-koa) use function names to generate span names. These names appear in UI of monitoring tools, such as datadog. Because the returned function doesn't have a name, there's no hint about the actual middleware associated with that span. See below: Screenshot 2024-03-24 at 13 03 42 In v4 the returned middleware had a name but in v5 got removed, see: https://github.com/koajs/bodyparser/blob/5678a79e64d7833e0dd7734c9e9de40126e14d98/index.js#L63. --- src/body-parser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/body-parser.ts b/src/body-parser.ts index 3b9993c..569a9e2 100644 --- a/src/body-parser.ts +++ b/src/body-parser.ts @@ -73,7 +73,8 @@ export function bodyParserWrapper(opts: BodyParserOptions = {}) { >; } - return async function (ctx: Koa.Context, next: Koa.Next) { + // eslint-disable-next-line func-names + return async function bodyParser(ctx: Koa.Context, next: Koa.Next) { if ( // method souldn't be parsed !parsedMethods.includes(ctx.method.toUpperCase()) ||