dd error ctx improvements

This commit is contained in:
Kristaps Fabians Geikins
2024-03-29 21:58:10 +02:00
parent 76bfd9121f
commit c81d6f281d
2 changed files with 17 additions and 0 deletions
@@ -0,0 +1,4 @@
import { H3Error } from 'h3'
export const isH3Error = (error: unknown): error is H3Error =>
!!(error && error instanceof H3Error)
+13
View File
@@ -5,6 +5,7 @@ import {
} from '~/lib/auth/composables/auth'
import { useCreateErrorLoggingTransport } from '~/lib/core/composables/error'
import type { Plugin } from 'nuxt/dist/app/nuxt'
import { isH3Error } from '~/lib/common/helpers/error'
type PluginNuxtApp = Parameters<Plugin>[0]
@@ -103,6 +104,16 @@ async function initRumClient(app: PluginNuxtApp) {
window.DD_RUM_START_VIEW?.(realPath, routeName)
})
const resolveH3Data = (error: unknown) =>
error && isH3Error(error)
? {
statusCode: error.statusCode,
fatal: error.fatal,
statusMessage: error.statusMessage,
h3Data: error.data
}
: {}
registerErrorTransport({
onError: ({ args, firstError, firstString, otherData, nonObjectOtherData }) => {
if (!datadog || !('addError' in datadog)) return
@@ -110,6 +121,7 @@ async function initRumClient(app: PluginNuxtApp) {
const error = firstError || firstString || args[0]
datadog.addError(error, {
...otherData,
...resolveH3Data(firstError),
extraData: nonObjectOtherData,
mainErrorMessage: firstString,
isProperlySentError: true
@@ -119,6 +131,7 @@ async function initRumClient(app: PluginNuxtApp) {
if (!datadog || !('addError' in datadog)) return
datadog.addError(error || message, {
...resolveH3Data(error),
isUnhandledRejection,
message,
mainErrorMessage: message,