Skip to content

Commit

Permalink
feat: set name of middleware function to improve interop with monitor…
Browse files Browse the repository at this point in the history
…ing 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:

<img width="227" alt="Screenshot 2024-03-24 at 13 03 42"
src="https://github.com/koajs/bodyparser/assets/1017236/e60cad1c-d348-4d2b-baca-486d0396ed9e">

In v4 the returned middleware had a name but in v5 got removed, see:
https://github.com/koajs/bodyparser/blob/5678a79e64d7833e0dd7734c9e9de40126e14d98/index.js#L63.
  • Loading branch information
satazor authored Mar 25, 2024
1 parent 664cd7c commit 9c18179
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/body-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) ||
Expand Down

0 comments on commit 9c18179

Please sign in to comment.