Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(packages/sui-logger): add missed Trackers in client and server level #1846

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/sui-logger/src/client.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/sui-logger/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
7 changes: 6 additions & 1 deletion packages/sui-logger/test/server/indexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,27 @@ 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', () => {
const error = 'Error Message'
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)
Expand Down