-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathutils.ts
43 lines (37 loc) · 1.22 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { getTraceMetaTags } from '@sentry/core';
import type { Context } from '@sentry/types';
import { dropUndefinedKeys } from '@sentry/utils';
import type { CapturedErrorContext } from 'nitropack';
import type { NuxtRenderHTMLContext } from 'nuxt/app';
/**
* Extracts the relevant context information from the error context (H3Event in Nitro Error)
* and created a structured context object.
*/
export function extractErrorContext(errorContext: CapturedErrorContext): Context {
const structuredContext: Context = {
method: undefined,
path: undefined,
tags: undefined,
};
if (errorContext) {
if (errorContext.event) {
structuredContext.method = errorContext.event._method || undefined;
structuredContext.path = errorContext.event._path || undefined;
}
if (Array.isArray(errorContext.tags)) {
structuredContext.tags = errorContext.tags || undefined;
}
}
return dropUndefinedKeys(structuredContext);
}
/**
* Adds Sentry tracing <meta> tags to the returned html page.
*
* Exported only for testing
*/
export function addSentryTracingMetaTags(head: NuxtRenderHTMLContext['head']): void {
const metaTags = getTraceMetaTags();
if (metaTags) {
head.push(metaTags);
}
}