@defra-fish/connectors-lib 1.64.0 → 1.65.0-airbrake-debugging-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/src/airbrake.js +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/connectors-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.65.0-airbrake-debugging-2",
|
|
4
4
|
"description": "Shared connectors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
"ioredis": "4.28.5",
|
|
46
46
|
"node-fetch": "2.7.0",
|
|
47
47
|
"redlock": "4.2.0"
|
|
48
|
-
}
|
|
49
|
-
"gitHead": "d6a3d30c7a20169fdf5afb1a93eb1d411fe96abf"
|
|
48
|
+
}
|
|
50
49
|
}
|
package/src/airbrake.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import db from 'debug'
|
|
1
2
|
import { Notifier } from '@airbrake/node'
|
|
2
3
|
import { formatWithOptions, inspect } from 'util'
|
|
4
|
+
const debug = db('connectors:airbrake')
|
|
3
5
|
const INSPECT_OPTS = { depth: null, maxStringLength: null, maxArrayLength: null, breakLength: null, compact: true, showHidden: true }
|
|
4
6
|
|
|
5
7
|
let airbrake = null
|
|
@@ -25,15 +27,18 @@ export const initialise = () => {
|
|
|
25
27
|
errorNotifications: true,
|
|
26
28
|
remoteConfig: false
|
|
27
29
|
})
|
|
30
|
+
console.log(`created new Notifier with error notifications set ${airbrake._opt.errorNotifications ? 'on' : 'off'}`)
|
|
28
31
|
|
|
29
32
|
// Proxy the console.warn and console.error methods, notifying airbrake/errbit asynchronously
|
|
30
33
|
const nativeConsoleMethods = {}
|
|
31
34
|
;['warn', 'error'].forEach(method => {
|
|
35
|
+
console.log(`replacing console.${method} function`)
|
|
32
36
|
nativeConsoleMethods[method] = console[method].bind(console)
|
|
33
37
|
console[method] = (...args) => {
|
|
34
38
|
const error = args.find(arg => arg instanceof Error) ?? new Error(formatWithOptions(INSPECT_OPTS, ...args))
|
|
35
39
|
const request = args.find(arg => Object.prototype.hasOwnProperty.call(arg, 'headers'))
|
|
36
|
-
|
|
40
|
+
console.log(`notifying airbrake for console.${method}, error notifications is ${airbrake._opt.errorNotifications ? 'on' : 'off'}`, INSPECT_OPTS)
|
|
41
|
+
const res = airbrake.notify({
|
|
37
42
|
error,
|
|
38
43
|
params: { consoleInvocationDetails: { method, arguments: { ...args.map(arg => inspect(arg, INSPECT_OPTS)) } } },
|
|
39
44
|
environment: {
|
|
@@ -46,6 +51,7 @@ export const initialise = () => {
|
|
|
46
51
|
...(request?.headers?.['user-agent'] && { userAgent: request?.headers?.['user-agent'] })
|
|
47
52
|
}
|
|
48
53
|
})
|
|
54
|
+
console.log(`Notify result: ${JSON.stringify(res)}`, res.id, res.url, res.error)
|
|
49
55
|
nativeConsoleMethods[method](...args)
|
|
50
56
|
}
|
|
51
57
|
})
|
|
@@ -55,6 +61,8 @@ export const initialise = () => {
|
|
|
55
61
|
|
|
56
62
|
// Override the @airbrake/node uncaughtException/unhandledRejection handlers with our own as errors were not flushing correctly.
|
|
57
63
|
const flushAndDie = async () => {
|
|
64
|
+
console.log('Airbrake connector flushing and dying...')
|
|
65
|
+
debug('Airbrake connector flushing and dying...')
|
|
58
66
|
await airbrake.flush()
|
|
59
67
|
process.exit(1)
|
|
60
68
|
}
|
|
@@ -71,6 +79,8 @@ export const initialise = () => {
|
|
|
71
79
|
*/
|
|
72
80
|
export const flush = async () => {
|
|
73
81
|
if (initialise()) {
|
|
82
|
+
console.log('Airbrake connector flushing...')
|
|
83
|
+
debug('Airbrake connector flushing...')
|
|
74
84
|
await airbrake.flush()
|
|
75
85
|
airbrake.close()
|
|
76
86
|
}
|