-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathplugin.server.js
46 lines (44 loc) · 1.39 KB
/
plugin.server.js
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
44
45
46
<% if (options.tracing) { %>
import { getActiveSpan, getDynamicSamplingContextFromSpan, spanToTraceHeader } from '~@sentry/core'
import { dynamicSamplingContextToSentryBaggageHeader } from '~@sentry/utils'
<% } %>
/** @type {import('@nuxt/types').Plugin} */
export default function (ctx, inject) {
const sentry = process.sentry || null
if (!sentry) {
return
}
inject('sentry', sentry)
ctx.$sentry = sentry
<% if (options.tracing) { %>
connectBackendTraces(ctx)
<% } %>
<% if (options.lazy) { %>
const sentryReady = () => Promise.resolve(sentry)
inject('sentryReady', sentryReady)
ctx.$sentryReady = sentryReady
<% } %>
}
<% if (options.tracing) { %>
/** @param {import('@nuxt/types').Context} ctx */
function connectBackendTraces (ctx) {
const { head } = ctx.app
if (!head || head instanceof Function) {
console.warn('[@nuxtjs/sentry] can not connect backend and frontend traces because app.head is a function or missing!')
return
}
const span = getActiveSpan()
if (!span) {
return
}
head.meta = head.meta || []
head.meta.push({ hid: 'sentry-trace', name: 'sentry-trace', content: spanToTraceHeader(span) })
const dsc = getDynamicSamplingContextFromSpan(span)
if (dsc) {
const baggage = dynamicSamplingContextToSentryBaggageHeader(dsc)
if (baggage) {
head.meta.push({ hid: 'sentry-baggage', name: 'baggage', content: baggage })
}
}
}
<% } %>