From 4106c993488d7b0afdd80503ccbd6a315b75be2c Mon Sep 17 00:00:00 2001 From: Joan Leon Date: Tue, 15 Oct 2024 17:02:20 +0200 Subject: [PATCH] refactor(packages/sui-logger): add missed Trackers in client and server level --- packages/sui-logger/src/client.js | 3 ++- packages/sui-logger/src/server.js | 3 ++- packages/sui-logger/test/server/indexSpec.js | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/sui-logger/src/client.js b/packages/sui-logger/src/client.js index bcc764162..0ed6436e5 100644 --- a/packages/sui-logger/src/client.js +++ b/packages/sui-logger/src/client.js @@ -1,7 +1,8 @@ import createLogger from './logger' -export const createClientLogger = ({userId, trackerName} = {}) => +export const createClientLogger = ({Trackers, userId, trackerName} = {}) => createLogger({ + Trackers, listenUnhandled: logError => { const handleWindowError = e => { const error = e.reason || e.error diff --git a/packages/sui-logger/src/server.js b/packages/sui-logger/src/server.js index a1b9ca97d..7f213e351 100644 --- a/packages/sui-logger/src/server.js +++ b/packages/sui-logger/src/server.js @@ -31,8 +31,9 @@ const extractFrom = req => { } } -export const logErrorsMiddleware = (error, req, res, next) => { +export const logErrorsMiddleware = (Trackers, error, req, res, next) => { const logger = createLogger({ + Trackers, ...extractFrom(req), forwardConsoleErrors: false }) diff --git a/packages/sui-logger/test/server/indexSpec.js b/packages/sui-logger/test/server/indexSpec.js index 5edeecf23..85623dd7c 100644 --- a/packages/sui-logger/test/server/indexSpec.js +++ b/packages/sui-logger/test/server/indexSpec.js @@ -68,14 +68,19 @@ describe('initTracker', () => { describe('logsErrorsMiddleware', () => { let logger let loggerPkgStub + let trackerStub + let TrackersCreateStub before(() => { logger = {error: sinon.stub()} loggerPkgStub = sinon.stub(loggerPkg, 'default').returns(logger) + trackerStub = {emit: sinon.stub()} + TrackersCreateStub = sinon.stub(Trackers, 'create').returns(trackerStub) }) after(() => { loggerPkgStub.restore() + TrackersCreateStub.restore() }) it('log the error and pass execution to next middleware', () => { @@ -83,7 +88,7 @@ describe('logsErrorsMiddleware', () => { const req = {headers: {}, url: '/'} const res = null const next = sinon.stub() - server.logErrorsMiddleware(error, req, res, next) + server.logErrorsMiddleware(trackerStub, error, req, res, next) expect(logger.error.calledWith(error)).to.equal(true) expect(next.calledWith(error)).to.equal(true)