diff --git a/lib/adapters/default.js b/lib/adapters/default.js index 7032a0e..35bff5b 100644 --- a/lib/adapters/default.js +++ b/lib/adapters/default.js @@ -103,6 +103,10 @@ function extractLogCtx(ctx) { } function onInboundRequest({ ctx }) { + if (this.inbound.blacklistedPaths?.includes(ctx.request?.path)) { + return; + } + extractLogCtx.call(this, ctx); const { @@ -129,6 +133,10 @@ function onInboundRequest({ ctx }) { } function onOutboundResponse({ ctx }) { + if (this.inbound.blacklistedPaths?.includes(ctx.request?.path)) { + return; + } + if (!ctx.logCtx) { extractLogCtx.call(this, ctx); } diff --git a/lib/options.js b/lib/options.js index 0ac5b84..a319b14 100644 --- a/lib/options.js +++ b/lib/options.js @@ -33,7 +33,8 @@ module.exports = (options = {}) => { }, level: 'info', includeHost: false, - maxBodyValueChars: undefined + maxBodyValueChars: undefined, + blacklistedPaths: undefined }, outbound: { enabled: true, diff --git a/test/lib/adapters/default/onOutboundResponseTest.js b/test/lib/adapters/default/onOutboundResponseTest.js index 3e9f9a3..94eca08 100644 --- a/test/lib/adapters/default/onOutboundResponseTest.js +++ b/test/lib/adapters/default/onOutboundResponseTest.js @@ -489,5 +489,36 @@ describe('#defaultAdapter', () => { duration: NaN }); }); + it('should respect inbound blacklisted paths', () => { + const ctx = { + state: {}, + request: { + method: 'GET', + headers: { + test_user_id_header: 'test-user-id' + }, + path: '/health', + req: { + url: '/health' + } + }, + req: { + headers: { + 'x-ap-id': uuid + } + }, + originalUrl: '/health', + response: { + status: 200 + } + }; + const opts = getOpts(sandbox); + opts.inbound.blacklistedPaths = ['/health']; + + defaultAdapter.onInboundRequest.call(opts, { ctx }); + defaultAdapter.onOutboundResponse.call(opts, { ctx }); + opts.logger.info.args.should.be.empty(); + opts.logger.info.called.should.be.false(); + }); }); }); diff --git a/types/riviere.d.ts b/types/riviere.d.ts index ad2ec11..f40b4b4 100644 --- a/types/riviere.d.ts +++ b/types/riviere.d.ts @@ -18,7 +18,8 @@ export function riviere(options?: { enabled: boolean }, level: string, - maxBodyValueChars?: number + maxBodyValueChars?: number, + blacklistedPaths?: string[] }, outbound?: { enabled: boolean,