Skip to content

Commit 40997fc

Browse files
committed
fix(instrumentation-fastify): add missing module export
fastify v4.x+ 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.
1 parent 12ee8db commit 40997fc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
FastifyInstance,
2828
FastifyRequest,
2929
FastifyReply,
30+
FastifyErrorCodes,
3031
} from 'fastify';
3132
import { hooksNamesToWrap } from './constants';
3233
import {
@@ -185,6 +186,7 @@ export class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumen
185186

186187
private _patchConstructor(moduleExports: {
187188
fastify: () => FastifyInstance;
189+
errorCodes: FastifyErrorCodes;
188190
}): () => FastifyInstance {
189191
const instrumentation = this;
190192

@@ -198,6 +200,7 @@ export class FastifyInstrumentation extends InstrumentationBase<FastifyInstrumen
198200
return app;
199201
}
200202

203+
fastify.errorCodes = moduleExports.errorCodes
201204
fastify.fastify = fastify;
202205
fastify.default = fastify;
203206
return fastify;

plugins/node/opentelemetry-instrumentation-fastify/test/instrumentation.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,8 @@ describe('fastify', () => {
560560
},
561561
});
562562
});
563+
564+
it('should expose errorCodes', async () => {
565+
assert.ok(Fastify.errorCodes);
566+
})
563567
});

0 commit comments

Comments
 (0)