Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 58 additions & 53 deletions src/helpers/logClientEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,59 +66,64 @@ const logClientEvent: LogFunction = async (opts) => {
}
}

// Send to server
return visitServerEndpoint({
path: LOG_ROUTE_PATH,
method: 'POST',
params: {
context: (
typeof opts.context === 'string'
? opts.context
: (
((opts.context as any) ?? {})._
?? LogBuiltInMetadata.Context.Uncategorized
)
),
subcontext: (
opts.subcontext
?? LogBuiltInMetadata.Context.Uncategorized
),
level: (
opts.level
?? LogLevel.Info
),
tags: JSON.stringify(opts.tags ?? []),
metadata: JSON.stringify(metadata),
errorMessage: (
(opts as any).error
? (opts as any).error.message
: undefined
),
errorCode: (
(opts as any).error
? (opts as any).error.code
: undefined
),
errorStack: (
(opts as any).error
? (opts as any).error.stack
: undefined
),
target: (
(opts as any).action
? (
(opts as any).target
?? LogBuiltInMetadata.Target.NoTarget
)
: undefined
),
action: (
(opts as any).action
? (opts as any).action
: undefined
),
},
});
try {
return await visitServerEndpoint({
path: LOG_ROUTE_PATH,
method: 'POST',
params: {
context: (
typeof opts.context === 'string'
? opts.context
: (
((opts.context as any) ?? {})._
?? LogBuiltInMetadata.Context.Uncategorized
)
),
subcontext: (
opts.subcontext
?? LogBuiltInMetadata.Context.Uncategorized
),
level: (
opts.level
?? LogLevel.Info
),
tags: JSON.stringify(opts.tags ?? []),
metadata: JSON.stringify(metadata),
errorMessage: (
(opts as any).error
? (opts as any).error.message
: undefined
),
errorCode: (
(opts as any).error
? (opts as any).error.code
: undefined
),
errorStack: (
(opts as any).error
? (opts as any).error.stack
: undefined
),
target: (
(opts as any).action
? (
(opts as any).target
?? LogBuiltInMetadata.Target.NoTarget
)
: undefined
),
action: (
(opts as any).action
? (opts as any).action
: undefined
),
},
});
} catch (err) {
// Logging is best-effort. Keep the signal without breaking the user flow.
// eslint-disable-next-line no-console
console.warn('Failed to log client event', err);
}
};

export default logClientEvent;