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