@@ -7,6 +7,8 @@ import type {
77 LoggerLoggingMethodName ,
88} from './types' ;
99import { serializeError } from 'serialize-error' ;
10+ import { sentry } from '../sentry' ;
11+ import { getTraceId } from '../sentry/utils' ;
1012
1113export const roarr = ( function ( ) {
1214 const createLogger = ( methodName : LoggerLoggingMethodName ) => {
@@ -15,11 +17,8 @@ export const roarr = (function () {
1517 return ;
1618 }
1719
18- const contextClone = { ...context } as LoggerContext ;
19- const errorContext = contextClone . error ;
20- if ( errorContext && errorContext instanceof Error ) {
21- contextClone . error = serializeError ( errorContext ) ;
22- }
20+ let contextClone = serializeErrorInContext ( context ) ;
21+ contextClone = enrichContextWithSentryTraceId ( contextClone ) ;
2322
2423 Roarr [ methodName ] (
2524 config . roarr . isDebugContextShown
@@ -62,13 +61,43 @@ function shouldBeLogged(methodName: LoggerLoggingMethodName): boolean {
6261 return requestedLogLevel >= minLogLevel ;
6362}
6463
64+ function serializeErrorInContext (
65+ context : LoggerContextWithError ,
66+ ) : LoggerContext {
67+ const errorContext = context . error ;
68+ if ( ! errorContext || ! ( errorContext instanceof Error ) ) {
69+ return { ...context } as LoggerContext ;
70+ }
71+
72+ return {
73+ ...context ,
74+ error : serializeError ( errorContext ) ,
75+ } ;
76+ }
77+
78+ function enrichContextWithSentryTraceId ( context : LoggerContext ) : LoggerContext {
79+ if ( ! sentry ) {
80+ return { ...context } ;
81+ }
82+
83+ const traceId = getTraceId ( ) ;
84+ if ( ! traceId ) {
85+ return { ...context } ;
86+ }
87+
88+ return {
89+ ...context ,
90+ sentryTraceId : traceId ,
91+ } ;
92+ }
93+
6594function enrichContextWithDebugInfo (
66- override : LoggerContext = { } ,
95+ context : LoggerContext = { } ,
6796) : LoggerContext {
6897 return {
98+ ...context ,
6999 callName : getCallName ( ) ,
70100 fileName : getFileName ( ) ,
71- ...override ,
72101 } ;
73102}
74103
0 commit comments