Add CF-Ray header value to Sentry errors if available (#10339)
This commit is contained in:
committed by
GitHub
parent
e685b1a8bf
commit
9d31aa057e
@@ -6,6 +6,8 @@ const defaultErrorMessages = {
|
||||
429: 'rate limited by upstream service',
|
||||
}
|
||||
|
||||
const headersToInclude = ['cf-ray']
|
||||
|
||||
export default function checkErrorResponse(httpErrors = {}, logErrors = [429]) {
|
||||
return async function ({ buffer, res }) {
|
||||
let error
|
||||
@@ -28,7 +30,17 @@ export default function checkErrorResponse(httpErrors = {}, logErrors = [429]) {
|
||||
}
|
||||
|
||||
if (logErrors.includes(res.statusCode)) {
|
||||
log.error(new Error(`${res.statusCode} calling ${res.requestUrl.origin}`))
|
||||
const tags = {}
|
||||
for (const headerKey of headersToInclude) {
|
||||
const headerValue = res.headers[headerKey]
|
||||
if (headerValue) {
|
||||
tags[`header-${headerKey}`] = headerValue
|
||||
}
|
||||
}
|
||||
log.error(
|
||||
new Error(`${res.statusCode} calling ${res.requestUrl.origin}`),
|
||||
tags,
|
||||
)
|
||||
}
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -47,7 +47,11 @@ describe('async error handler', function () {
|
||||
|
||||
context('when status is 429', function () {
|
||||
const buffer = Buffer.from('some stuff')
|
||||
const res = { statusCode: 429, requestUrl: new URL('https://example.com/') }
|
||||
const res = {
|
||||
statusCode: 429,
|
||||
headers: { 'some-key': 'some-value' },
|
||||
requestUrl: new URL('https://example.com/'),
|
||||
}
|
||||
|
||||
it('throws InvalidResponse', async function () {
|
||||
try {
|
||||
|
||||
@@ -28,10 +28,12 @@ const log = (...msg) => {
|
||||
console.log(d, ...msg)
|
||||
}
|
||||
|
||||
const error = err => {
|
||||
const error = (err, tags) => {
|
||||
const d = date()
|
||||
listeners.forEach(f => f(d, err))
|
||||
Sentry.captureException(err)
|
||||
Sentry.captureException(err, {
|
||||
tags,
|
||||
})
|
||||
console.error(d, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user