Clean up metadata before passing to Bitdrift
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
|||||||
warn as bdWarn,
|
warn as bdWarn,
|
||||||
} from '#/lib/bitdrift'
|
} from '#/lib/bitdrift'
|
||||||
import {LogLevel, Transport} from '#/logger/types'
|
import {LogLevel, Transport} from '#/logger/types'
|
||||||
|
import {prepareMetadata} from '#/logger/util'
|
||||||
|
|
||||||
const logFunctions = {
|
const logFunctions = {
|
||||||
[LogLevel.Debug]: bdDebug,
|
[LogLevel.Debug]: bdDebug,
|
||||||
@@ -21,5 +22,5 @@ export const bitdriftTransport: Transport = (
|
|||||||
metadata,
|
metadata,
|
||||||
) => {
|
) => {
|
||||||
const log = logFunctions[level]
|
const log = logFunctions[level]
|
||||||
log(`(${context}) ${message}`, metadata)
|
log(`(${context}) ${message}`, prepareMetadata(metadata))
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
import type {Sentry} from '#/logger/sentry/lib'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DO NOT IMPORT THIS DIRECTLY
|
* DO NOT IMPORT THIS DIRECTLY
|
||||||
*
|
*
|
||||||
@@ -64,8 +62,8 @@ export type Metadata = {
|
|||||||
* Any additional data, passed through to Sentry as `extra` param on
|
* Any additional data, passed through to Sentry as `extra` param on
|
||||||
* exceptions, or the `data` param on breadcrumbs.
|
* exceptions, or the `data` param on breadcrumbs.
|
||||||
*/
|
*/
|
||||||
[key: string]: Serializable
|
[key: string]: Serializable | Error | unknown
|
||||||
} & Parameters<typeof Sentry.captureException>[1]
|
}
|
||||||
|
|
||||||
export type Serializable =
|
export type Serializable =
|
||||||
| string
|
| string
|
||||||
|
|||||||
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
import {LogLevel, Metadata} from '#/logger/types'
|
import {LogLevel, Metadata, Serializable} from '#/logger/types'
|
||||||
|
|
||||||
export const enabledLogLevels: {
|
export const enabledLogLevels: {
|
||||||
[key in LogLevel]: LogLevel[]
|
[key in LogLevel]: LogLevel[]
|
||||||
@@ -16,7 +16,9 @@ export const enabledLogLevels: {
|
|||||||
[LogLevel.Error]: [LogLevel.Error],
|
[LogLevel.Error]: [LogLevel.Error],
|
||||||
}
|
}
|
||||||
|
|
||||||
export function prepareMetadata(metadata: Metadata): Metadata {
|
export function prepareMetadata(
|
||||||
|
metadata: Metadata,
|
||||||
|
): Record<string, Serializable> {
|
||||||
return Object.keys(metadata).reduce((acc, key) => {
|
return Object.keys(metadata).reduce((acc, key) => {
|
||||||
let value = metadata[key]
|
let value = metadata[key]
|
||||||
if (value instanceof Error) {
|
if (value instanceof Error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user