From 2727df2215436e179c2119a5c941767e5c3453e8 Mon Sep 17 00:00:00 2001 From: Tom Smithhisler Date: Wed, 8 Jan 2025 16:52:51 -0500 Subject: [PATCH] fix(instrumentation-fastify): add missing module export fastify v4.8+ exports an object named `errorCodes` as both a property of the default export and as a named export. The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236. This closes #2027. --- .../src/instrumentation.ts | 5 +++++ .../test/instrumentation.test.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts index 72d8b8c9b7..0ccc2c3a44 100644 --- a/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts @@ -27,6 +27,7 @@ import type { FastifyInstance, FastifyRequest, FastifyReply, + FastifyErrorCodes, } from 'fastify'; import { hooksNamesToWrap } from './constants'; import { @@ -185,6 +186,7 @@ export class FastifyInstrumentation extends InstrumentationBase FastifyInstance; + errorCodes: FastifyErrorCodes | undefined; }): () => FastifyInstance { const instrumentation = this; @@ -198,6 +200,9 @@ export class FastifyInstrumentation extends InstrumentationBase { }, }); }); + + it('should expose errorCodes', async function () { + // errorCodes was added in v4.8.0 + // ref: https://github.com/fastify/fastify/compare/v4.7.0...v4.8.0 + if (semver.lt(fastifyVersion, '4.8.0')) { + this.skip(); + } + assert.ok(Fastify.errorCodes); + assert.strictEqual(typeof Fastify.errorCodes, 'object'); + assert.ok('FST_ERR_NOT_FOUND' in Fastify.errorCodes); + }); });