Skip to content
Snippets Groups Projects
Unverified Commit 9d31aa05 authored by Pierre-Yves Bigourdan's avatar Pierre-Yves Bigourdan Committed by GitHub
Browse files

Add CF-Ray header value to Sentry errors if available (#10339)

parent e685b1a8
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment