Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fe2): add extra metadata to seq logs for improved observability #4073

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/frontend-2/lib/core/helpers/observability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function enableCustomLoggerHandling(params: {

const firstString = args.find(isString)
const otherData: unknown[] = args.filter(
(o) => !(o instanceof Error) && o !== firstString
(o) => o !== firstString && o !== firstError
)

const errorMessage = firstError?.message ?? firstString ?? `Unknown error`
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend-2/plugins/001-logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { collectLongTrace } from '@speckle/shared'
import { omit } from 'lodash-es'
import type { SetRequired } from 'type-fest'
import { useReadUserId } from '~/lib/auth/composables/activeUser'
Expand Down Expand Up @@ -170,6 +171,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
}) => {
if (!args.length) return

const stack = collectLongTrace()
const isError = ['error', 'fatal'].includes(level)
const isImportant = !!otherData?.important
if (!isError && !isImportant) return
Expand All @@ -189,6 +191,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
properties: {
mainSeqErrorMessage: errorMessage, // weird name to avoid collision with otherData
extraData: nonObjectOtherData,
stack,
firstError,
firstString,
...otherData,
...collectCoreInfo()
},
Expand All @@ -202,6 +207,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
properties: {
extraData: nonObjectOtherData,
firstError,
stack,
...otherData,
...collectCoreInfo()
}
Expand Down
10 changes: 7 additions & 3 deletions packages/shared/src/core/helpers/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ export const isNonNullable = <V>(v: V): v is NonNullable<typeof v> => !!v
/**
* Make the promise throw after enough time has passed. Useful for implementing timeout functionality in various flows.
*/
export const timeoutAt = (ms: number, optionalMessage?: string) =>
new Promise<never>((_resolve, reject) =>
export const timeoutAt = (ms: number, optionalMessage?: string) => {
// create error beforehand, so we have a better stack trace
const err = new TimeoutError(optionalMessage || 'timeoutAt() timed out')

return new Promise<never>((_resolve, reject) =>
setTimeout(() => {
reject(new TimeoutError(optionalMessage || 'timeoutAt() timed out'))
reject(err)
}, ms)
)
}

/**
* Invoke and return fn(), but retry it up to n times if it throws
Expand Down
Loading