Skip to content

Commit 1a6839b

Browse files
fix(instrumentation-fastify): add missing module export (#2633)
Co-authored-by: Marc Pichler <[email protected]>
1 parent bda9632 commit 1a6839b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 5 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 | undefined;
188190
}): () => FastifyInstance {
189191
const instrumentation = this;
190192

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

203+
if (moduleExports.errorCodes !== undefined) {
204+
fastify.errorCodes = moduleExports.errorCodes;
205+
}
201206
fastify.fastify = fastify;
202207
fastify.default = fastify;
203208
return fastify;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,15 @@ describe('fastify', () => {
560560
},
561561
});
562562
});
563+
564+
it('should expose errorCodes', async function () {
565+
// errorCodes was added in v4.8.0
566+
// ref: https://github.com/fastify/fastify/compare/v4.7.0...v4.8.0
567+
if (semver.lt(fastifyVersion, '4.8.0')) {
568+
this.skip();
569+
}
570+
assert.ok(Fastify.errorCodes);
571+
assert.strictEqual(typeof Fastify.errorCodes, 'object');
572+
assert.ok('FST_ERR_NOT_FOUND' in Fastify.errorCodes);
573+
});
563574
});

0 commit comments

Comments
 (0)