@takeshape/logger
Advanced tools
Comparing version 11.17.0 to 11.17.3
@@ -9,3 +9,2 @@ "use strict"; | ||
const merge_js_1 = __importDefault(require("lodash/merge.js")); | ||
const isPlainObject_js_1 = __importDefault(require("lodash/isPlainObject.js")); | ||
const constants_js_1 = require("./constants.js"); | ||
@@ -109,20 +108,44 @@ const noop = () => { | ||
function getGraphQLErrorExtras(error) { | ||
const { path, nodes, extensions } = error; | ||
const { path, nodes } = error; | ||
const fieldName = nodes?.find(isFieldNode)?.name.value; | ||
return { | ||
path, | ||
fieldName, | ||
extensions | ||
fieldName | ||
}; | ||
} | ||
function getAggregateErrorExtras(error) { | ||
const errors = error.errors.map(e => { | ||
if (Array.isArray(e)) { | ||
return e.join(', '); | ||
} | ||
if (typeof e === 'object') { | ||
return e?.message; | ||
} | ||
return e; | ||
}); | ||
return { | ||
errors | ||
}; | ||
} | ||
function getSentryExtras(error) { | ||
let extras = {}; | ||
if (isGraphQLError(error)) { | ||
return getGraphQLErrorExtras(error); | ||
extras = { | ||
...extras, | ||
...getGraphQLErrorExtras(error) | ||
}; | ||
if (error.originalError) { | ||
extras = { | ||
...extras, | ||
...getSentryExtras(error.originalError) | ||
}; | ||
} | ||
} | ||
if ('extensions' in error && (0, isPlainObject_js_1.default)(error.extensions)) { | ||
return { | ||
extensions: error.extensions | ||
if (error instanceof AggregateError) { | ||
extras = { | ||
...extras, | ||
...getAggregateErrorExtras(error) | ||
}; | ||
} | ||
return {}; | ||
return extras; | ||
} | ||
@@ -155,3 +178,3 @@ function shouldReportToSentry(error) { | ||
if (metadata) { | ||
const { message, error, ...rest } = metadata; | ||
const { error, ...rest } = metadata; | ||
// Merge passed context with the base context, and exclude any message, and the error | ||
@@ -169,2 +192,7 @@ metadata = (0, merge_js_1.default)({}, entry, rest); | ||
scope.setLevel(sentryLevel); | ||
scope.addBreadcrumb({ | ||
type: 'error', | ||
message, | ||
level: sentryLevel | ||
}); | ||
if (entry.context?.user?.id) { | ||
@@ -171,0 +199,0 @@ scope.setUser(entry.context.user); |
import cloneDeep from 'lodash/cloneDeep.js'; | ||
import merge from 'lodash/merge.js'; | ||
import isPlainObject from 'lodash/isPlainObject.js'; | ||
import { logLevels } from './constants.js'; | ||
@@ -101,20 +100,44 @@ const noop = () => { | ||
function getGraphQLErrorExtras(error) { | ||
const { path, nodes, extensions } = error; | ||
const { path, nodes } = error; | ||
const fieldName = nodes?.find(isFieldNode)?.name.value; | ||
return { | ||
path, | ||
fieldName, | ||
extensions | ||
fieldName | ||
}; | ||
} | ||
function getAggregateErrorExtras(error) { | ||
const errors = error.errors.map(e => { | ||
if (Array.isArray(e)) { | ||
return e.join(', '); | ||
} | ||
if (typeof e === 'object') { | ||
return e?.message; | ||
} | ||
return e; | ||
}); | ||
return { | ||
errors | ||
}; | ||
} | ||
function getSentryExtras(error) { | ||
let extras = {}; | ||
if (isGraphQLError(error)) { | ||
return getGraphQLErrorExtras(error); | ||
extras = { | ||
...extras, | ||
...getGraphQLErrorExtras(error) | ||
}; | ||
if (error.originalError) { | ||
extras = { | ||
...extras, | ||
...getSentryExtras(error.originalError) | ||
}; | ||
} | ||
} | ||
if ('extensions' in error && isPlainObject(error.extensions)) { | ||
return { | ||
extensions: error.extensions | ||
if (error instanceof AggregateError) { | ||
extras = { | ||
...extras, | ||
...getAggregateErrorExtras(error) | ||
}; | ||
} | ||
return {}; | ||
return extras; | ||
} | ||
@@ -146,3 +169,3 @@ export function shouldReportToSentry(error) { | ||
if (metadata) { | ||
const { message, error, ...rest } = metadata; | ||
const { error, ...rest } = metadata; | ||
// Merge passed context with the base context, and exclude any message, and the error | ||
@@ -160,2 +183,7 @@ metadata = merge({}, entry, rest); | ||
scope.setLevel(sentryLevel); | ||
scope.addBreadcrumb({ | ||
type: 'error', | ||
message, | ||
level: sentryLevel | ||
}); | ||
if (entry.context?.user?.id) { | ||
@@ -162,0 +190,0 @@ scope.setUser(entry.context.user); |
{ | ||
"name": "@takeshape/logger", | ||
"version": "11.17.0", | ||
"version": "11.17.3", | ||
"description": "Logging utility.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://www.takeshape.io", |
Sorry, the diff of this file is not supported yet
101350
876