forked from golyakov/winston-rollbar
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix stacktrace format for rollbar #5
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9ca4a2a
docs: switch to yarn
catnstein 18dc87e
fix: pass error object of stacktrace for rollbar dashboard correct fo…
catnstein a76b100
fix: guard for null rollbar config
catnstein 89a3e5a
test: for empty rollbar key and log messages params
catnstein e13cfe0
docs: add test command to docs
catnstein 77a46b6
bump minor version
catnstein 9c92338
feat: always send error object as payload to rollbar
catnstein 25ad2d6
fix: logging with appropriate rollbar methods; rewrote unit tests
catnstein 4673f11
v3.2.5
catnstein 4ee23bd
default to log level info if log method does not exist
catnstein 602fca3
v3.2.6
catnstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ const rollbar = require('rollbar'); | |
class RollbarTransport extends TransportStream { | ||
constructor(opts) { | ||
super(opts); | ||
if (!opts.rollbarConfig.accessToken) { | ||
if (!opts.rollbarConfig?.accessToken) { | ||
throw "winston-transport-rollbar requires a 'rollbarConfig.accessToken' property"; | ||
} | ||
|
||
|
@@ -28,10 +28,10 @@ class RollbarTransport extends TransportStream { | |
} | ||
|
||
log(info, callback) { | ||
const {level, message} = info; | ||
const { level, message } = info; | ||
|
||
process.nextTick(() => { | ||
const message = util.format(info.message, ...(info.splat || [])); | ||
const meta = info; | ||
const rollbarLevel = level === 'warn' ? 'warning' : level; | ||
|
||
const cb = err => { | ||
|
@@ -42,9 +42,9 @@ class RollbarTransport extends TransportStream { | |
this.emit('logged'); | ||
return callback(null, true); | ||
}; | ||
|
||
const logMethod = this.rollbar[rollbarLevel] || this.rollbar.log; | ||
return logMethod.apply(this.rollbar, [message, meta, cb]); | ||
return logMethod.apply(this.rollbar, [message, info, new Error(info.stack), cb]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating a new error here seems wrong to me |
||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const RollbarTransport = require('../lib/rollbar_transport'); | ||
const rollbar = require('rollbar'); | ||
|
||
jest.mock('rollbar'); | ||
|
||
describe('RollbarTransport', () => { | ||
let transport; | ||
let rollbarMock; | ||
|
||
beforeEach(() => { | ||
rollbarMock = { | ||
log: jest.fn(), | ||
warning: jest.fn(), | ||
error: jest.fn(), | ||
}; | ||
|
||
rollbar.mockReturnValue(rollbarMock); | ||
|
||
transport = new RollbarTransport({ | ||
rollbarConfig: { accessToken: 'test' }, | ||
}); | ||
}); | ||
|
||
it('throws an error if no accessToken is provided', () => { | ||
expect(() => new RollbarTransport({})).toThrow( | ||
"winston-transport-rollbar requires a 'rollbarConfig.accessToken' property" | ||
); | ||
}); | ||
|
||
it('logs messages with log level error', async () => { | ||
const logData = { level: 'error', message: 'test' }; | ||
transport.log(logData); | ||
|
||
// wait for process.nextTick | ||
await new Promise(resolve => setTimeout(resolve, 0)); | ||
|
||
expect(rollbarMock.error).toHaveBeenCalledWith(logData.message, logData, new Error(logData.stack), expect.any(Function)); | ||
}); | ||
|
||
|
||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strong tests 💪 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're changing a lot of code where I guess it's unclear why it was there in the first place. The git history doesn't tell a good story, and without unit tests it's hard to say why that has been there in the first place, so I think it's ok.