File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,12 @@ import {
55 enrichLoggerContextWithSentryTraceId ,
66} from '$lib/shared/logging/utils' ;
77import type { LogLevelName } from './types' ;
8- import { logLevelColors , logLevels , logTimestampColors } from './utils' ;
8+ import {
9+ enrichLoggerContextWithPosthogSessionId ,
10+ logLevelColors ,
11+ logLevels ,
12+ logTimestampColors ,
13+ } from './utils' ;
914
1015export const logger = ( function ( ) {
1116 const createLogger = ( methodName : LogLevelName ) => {
@@ -18,7 +23,8 @@ export const logger = (function () {
1823 return ;
1924 }
2025
21- const contextClone = enrichLoggerContextWithSentryTraceId ( context ) ;
26+ let contextClone = enrichLoggerContextWithSentryTraceId ( context ) ;
27+ contextClone = enrichLoggerContextWithPosthogSessionId ( contextClone ) ;
2228
2329 console [ methodName ] (
2430 ...createLogPrefixStrings ( methodName ) ,
Original file line number Diff line number Diff line change 1+ import { posthog } from '$lib/client/posthog' ;
2+ import { getSessionId } from '$lib/client/posthog/utils' ;
3+ import type { LoggerContext } from '$lib/shared/logging/types' ;
14import type { LogLevelName } from '../types' ;
25
36export const logLevels = {
@@ -52,3 +55,21 @@ export const logTimestampColors = {
5255} satisfies {
5356 [ key in LogLevelName ] : { color : string } ;
5457} ;
58+
59+ export function enrichLoggerContextWithPosthogSessionId (
60+ context : LoggerContext ,
61+ ) : LoggerContext {
62+ if ( ! posthog ) {
63+ return { ...context } ;
64+ }
65+
66+ const sessionId = getSessionId ( ) ;
67+ if ( ! sessionId ) {
68+ return { ...context } ;
69+ }
70+
71+ return {
72+ ...context ,
73+ posthogSessionId : getSessionId ( ) ,
74+ } ;
75+ }
You can’t perform that action at this time.
0 commit comments