@takeshape/logger
Advanced tools
Comparing version 11.15.3 to 11.15.4
@@ -6,5 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLogger = exports.getLogLevelScore = exports.formatLogEntry = void 0; | ||
exports.createLogger = exports.getLogLevelScore = exports.shouldReportToSentry = exports.formatLogEntry = void 0; | ||
const cloneDeep_js_1 = __importDefault(require("lodash/cloneDeep.js")); | ||
const merge_js_1 = __importDefault(require("lodash/merge.js")); | ||
const lodash_1 = require("lodash"); | ||
const constants_js_1 = require("./constants.js"); | ||
@@ -101,2 +102,41 @@ const noop = () => { | ||
exports.formatLogEntry = formatLogEntry; | ||
function isFieldNode(node) { | ||
return node.kind === 'Field'; | ||
} | ||
function isGraphQLError(error) { | ||
return error.name === 'GraphQLError'; | ||
} | ||
function getGraphQLErrorExtras(error) { | ||
const { path, nodes, extensions } = error; | ||
const fieldName = nodes?.find(isFieldNode)?.name.value; | ||
return { | ||
path, | ||
fieldName, | ||
extensions | ||
}; | ||
} | ||
function getSentryExtras(error) { | ||
if (isGraphQLError(error)) { | ||
return getGraphQLErrorExtras(error); | ||
} | ||
if ('extensions' in error && (0, lodash_1.isPlainObject)(error.extensions)) { | ||
return { | ||
extensions: error.extensions | ||
}; | ||
} | ||
return {}; | ||
} | ||
function shouldReportToSentry(error) { | ||
if (isGraphQLError(error)) { | ||
if (error.originalError) { | ||
return shouldReportToSentry(error.originalError); | ||
} | ||
return false; | ||
} | ||
if ('reportToSentry' in error) { | ||
return Boolean(error.reportToSentry); | ||
} | ||
return true; | ||
} | ||
exports.shouldReportToSentry = shouldReportToSentry; | ||
function decorateLogFn({ provider, level, sentryClient }, entry) { | ||
@@ -134,2 +174,5 @@ return (messageOrError, metadata) => { | ||
} | ||
if (error) { | ||
scope.setExtras(getSentryExtras(error)); | ||
} | ||
return scope; | ||
@@ -139,3 +182,5 @@ } | ||
if (error) { | ||
sentryClient.captureException(error, sentryHint); | ||
if (shouldReportToSentry(error)) { | ||
sentryClient.captureException(error, sentryHint); | ||
} | ||
} | ||
@@ -142,0 +187,0 @@ else { |
import cloneDeep from 'lodash/cloneDeep.js'; | ||
import merge from 'lodash/merge.js'; | ||
import { isPlainObject } from 'lodash'; | ||
import { logLevels } from './constants.js'; | ||
@@ -93,2 +94,40 @@ const noop = () => { | ||
} | ||
function isFieldNode(node) { | ||
return node.kind === 'Field'; | ||
} | ||
function isGraphQLError(error) { | ||
return error.name === 'GraphQLError'; | ||
} | ||
function getGraphQLErrorExtras(error) { | ||
const { path, nodes, extensions } = error; | ||
const fieldName = nodes?.find(isFieldNode)?.name.value; | ||
return { | ||
path, | ||
fieldName, | ||
extensions | ||
}; | ||
} | ||
function getSentryExtras(error) { | ||
if (isGraphQLError(error)) { | ||
return getGraphQLErrorExtras(error); | ||
} | ||
if ('extensions' in error && isPlainObject(error.extensions)) { | ||
return { | ||
extensions: error.extensions | ||
}; | ||
} | ||
return {}; | ||
} | ||
export function shouldReportToSentry(error) { | ||
if (isGraphQLError(error)) { | ||
if (error.originalError) { | ||
return shouldReportToSentry(error.originalError); | ||
} | ||
return false; | ||
} | ||
if ('reportToSentry' in error) { | ||
return Boolean(error.reportToSentry); | ||
} | ||
return true; | ||
} | ||
function decorateLogFn({ provider, level, sentryClient }, entry) { | ||
@@ -126,2 +165,5 @@ return (messageOrError, metadata) => { | ||
} | ||
if (error) { | ||
scope.setExtras(getSentryExtras(error)); | ||
} | ||
return scope; | ||
@@ -131,3 +173,5 @@ } | ||
if (error) { | ||
sentryClient.captureException(error, sentryHint); | ||
if (shouldReportToSentry(error)) { | ||
sentryClient.captureException(error, sentryHint); | ||
} | ||
} | ||
@@ -134,0 +178,0 @@ else { |
@@ -16,2 +16,3 @@ import type Sentry from '@sentry/types'; | ||
}): string; | ||
export declare function shouldReportToSentry(error: Error): boolean; | ||
export declare function getLogLevelScore(logLevel: string): number; | ||
@@ -18,0 +19,0 @@ type LoggerOptions = { |
{ | ||
"name": "@takeshape/logger", | ||
"version": "11.15.3", | ||
"version": "11.15.4", | ||
"description": "Logging utility.", | ||
@@ -28,4 +28,5 @@ "homepage": "https://www.takeshape.io", | ||
"devDependencies": { | ||
"@sentry/types": "^8.39.0", | ||
"@types/lodash": "^4.14.165" | ||
"@sentry/types": "^8.41.0", | ||
"@types/lodash": "^4.14.165", | ||
"graphql": "16.6.0" | ||
}, | ||
@@ -32,0 +33,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
164698
18
820
3