@sentry/react-router 10.68.0 → 11.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/client/createClientInstrumentation.js +18 -12
- package/build/cjs/client/createClientInstrumentation.js.map +1 -1
- package/build/cjs/client/hydratedRouter.js +4 -1
- package/build/cjs/client/hydratedRouter.js.map +1 -1
- package/build/cjs/client/tracingIntegration.js +1 -0
- package/build/cjs/client/tracingIntegration.js.map +1 -1
- package/build/cjs/client/utils.js +6 -2
- package/build/cjs/client/utils.js.map +1 -1
- package/build/cjs/index.server.js +0 -4
- package/build/cjs/index.server.js.map +1 -1
- package/build/cjs/server/createSentryHandleRequest.js.map +1 -1
- package/build/cjs/server/createServerInstrumentation.js +71 -65
- package/build/cjs/server/createServerInstrumentation.js.map +1 -1
- package/build/cjs/server/integration/reactRouterServer.js +1 -40
- package/build/cjs/server/integration/reactRouterServer.js.map +1 -1
- package/build/cjs/server/serverBuild.js +0 -4
- package/build/cjs/server/serverBuild.js.map +1 -1
- package/build/cjs/server/serverGlobals.js +0 -9
- package/build/cjs/server/serverGlobals.js.map +1 -1
- package/build/cjs/vite/buildEnd/handleOnBuildEnd.js +26 -14
- package/build/cjs/vite/buildEnd/handleOnBuildEnd.js.map +1 -1
- package/build/cjs/vite/makeCustomSentryVitePlugins.js +29 -10
- package/build/cjs/vite/makeCustomSentryVitePlugins.js.map +1 -1
- package/build/cjs/vite/makeServerBuildCapturePlugin.js +2 -6
- package/build/cjs/vite/makeServerBuildCapturePlugin.js.map +1 -1
- package/build/cjs/vite/plugin.js +2 -0
- package/build/cjs/vite/plugin.js.map +1 -1
- package/build/esm/client/createClientInstrumentation.js +20 -14
- package/build/esm/client/createClientInstrumentation.js.map +1 -1
- package/build/esm/client/hydratedRouter.js +4 -1
- package/build/esm/client/hydratedRouter.js.map +1 -1
- package/build/esm/client/tracingIntegration.js +1 -0
- package/build/esm/client/tracingIntegration.js.map +1 -1
- package/build/esm/client/utils.js +7 -3
- package/build/esm/client/utils.js.map +1 -1
- package/build/esm/index.server.js +0 -2
- package/build/esm/index.server.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/server/createSentryHandleRequest.js.map +1 -1
- package/build/esm/server/createServerInstrumentation.js +73 -67
- package/build/esm/server/createServerInstrumentation.js.map +1 -1
- package/build/esm/server/integration/reactRouterServer.js +3 -41
- package/build/esm/server/integration/reactRouterServer.js.map +1 -1
- package/build/esm/server/serverBuild.js +1 -4
- package/build/esm/server/serverBuild.js.map +1 -1
- package/build/esm/server/serverGlobals.js +1 -8
- package/build/esm/server/serverGlobals.js.map +1 -1
- package/build/esm/vite/buildEnd/handleOnBuildEnd.js +26 -14
- package/build/esm/vite/buildEnd/handleOnBuildEnd.js.map +1 -1
- package/build/esm/vite/makeCustomSentryVitePlugins.js +28 -9
- package/build/esm/vite/makeCustomSentryVitePlugins.js.map +1 -1
- package/build/esm/vite/makeServerBuildCapturePlugin.js +2 -6
- package/build/esm/vite/makeServerBuildCapturePlugin.js.map +1 -1
- package/build/esm/vite/plugin.js +2 -0
- package/build/esm/vite/plugin.js.map +1 -1
- package/build/types/client/createClientInstrumentation.d.ts.map +1 -1
- package/build/types/client/hydratedRouter.d.ts.map +1 -1
- package/build/types/client/tracingIntegration.d.ts.map +1 -1
- package/build/types/client/utils.d.ts.map +1 -1
- package/build/types/index.types.d.ts +1 -0
- package/build/types/index.types.d.ts.map +1 -1
- package/build/types/server/createSentryHandleRequest.d.ts.map +1 -1
- package/build/types/server/createServerInstrumentation.d.ts.map +1 -1
- package/build/types/server/index.d.ts +0 -2
- package/build/types/server/index.d.ts.map +1 -1
- package/build/types/server/integration/reactRouterServer.d.ts +0 -3
- package/build/types/server/integration/reactRouterServer.d.ts.map +1 -1
- package/build/types/server/serverGlobals.d.ts +0 -10
- package/build/types/server/serverGlobals.d.ts.map +1 -1
- package/build/types/vite/buildEnd/handleOnBuildEnd.d.ts.map +1 -1
- package/build/types/vite/makeCustomSentryVitePlugins.d.ts.map +1 -1
- package/build/types/vite/makeServerBuildCapturePlugin.d.ts.map +1 -1
- package/build/types/vite/plugin.d.ts.map +1 -1
- package/build/types/vite/types.d.ts +1 -1
- package/build/types/vite/types.d.ts.map +1 -1
- package/package.json +14 -14
- package/build/cjs/server/instrumentation/reactRouter.js +0 -106
- package/build/cjs/server/instrumentation/reactRouter.js.map +0 -1
- package/build/cjs/server/instrumentation/util.js +0 -24
- package/build/cjs/server/instrumentation/util.js.map +0 -1
- package/build/cjs/server/wrapServerAction.js +0 -56
- package/build/cjs/server/wrapServerAction.js.map +0 -1
- package/build/cjs/server/wrapServerLoader.js +0 -56
- package/build/cjs/server/wrapServerLoader.js.map +0 -1
- package/build/esm/server/instrumentation/reactRouter.js +0 -104
- package/build/esm/server/instrumentation/reactRouter.js.map +0 -1
- package/build/esm/server/instrumentation/util.js +0 -18
- package/build/esm/server/instrumentation/util.js.map +0 -1
- package/build/esm/server/wrapServerAction.js +0 -54
- package/build/esm/server/wrapServerAction.js.map +0 -1
- package/build/esm/server/wrapServerLoader.js +0 -54
- package/build/esm/server/wrapServerLoader.js.map +0 -1
- package/build/types/server/instrumentation/reactRouter.d.ts +0 -19
- package/build/types/server/instrumentation/reactRouter.d.ts.map +0 -1
- package/build/types/server/instrumentation/util.d.ts +0 -31
- package/build/types/server/instrumentation/util.d.ts.map +0 -1
- package/build/types/server/wrapServerAction.d.ts +0 -33
- package/build/types/server/wrapServerAction.d.ts.map +0 -1
- package/build/types/server/wrapServerLoader.d.ts +0 -33
- package/build/types/server/wrapServerLoader.d.ts.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const api = require('@opentelemetry/api');
|
|
4
3
|
const attributes = require('@sentry/conventions/attributes');
|
|
4
|
+
const op = require('@sentry/conventions/op');
|
|
5
5
|
const core = require('@sentry/core');
|
|
6
6
|
const debugBuild = require('../common/debug-build.js');
|
|
7
7
|
const utils = require('../common/utils.js');
|
|
8
8
|
const serverBuild = require('./serverBuild.js');
|
|
9
9
|
const serverGlobals = require('./serverGlobals.js');
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const middlewareCountersByRootSpan = /* @__PURE__ */ new WeakMap();
|
|
12
12
|
function createSentryServerInstrumentation(options = {}) {
|
|
13
13
|
const { captureErrors = true } = options;
|
|
14
14
|
debugBuild.DEBUG_BUILD && core.debug.log("React Router server instrumentation created.");
|
|
@@ -20,61 +20,57 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
20
20
|
const pathname = utils.getPathFromRequest(info.request);
|
|
21
21
|
const activeSpan = core.getActiveSpan();
|
|
22
22
|
const existingRootSpan = activeSpan ? core.getRootSpan(activeSpan) : void 0;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
core.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"http.method": info.request.method,
|
|
41
|
-
"http.url": pathname
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
} finally {
|
|
45
|
-
await core.flushIfServerless();
|
|
23
|
+
if (existingRootSpan) {
|
|
24
|
+
core.updateSpanName(existingRootSpan, `${info.request.method} ${pathname}`);
|
|
25
|
+
existingRootSpan.setAttributes({
|
|
26
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "http.server",
|
|
27
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.instrumentation_api",
|
|
28
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
|
|
29
|
+
[attributes.URL_FULL]: core.filterCollectedUrl(info.request.url),
|
|
30
|
+
[attributes.URL_PATH]: pathname
|
|
31
|
+
});
|
|
32
|
+
try {
|
|
33
|
+
const result = await handleRequest();
|
|
34
|
+
if (result.status === "error" && result.error instanceof Error) {
|
|
35
|
+
existingRootSpan.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" });
|
|
36
|
+
utils.captureInstrumentationError(result, captureErrors, "react_router.request_handler", {
|
|
37
|
+
"http.method": info.request.method,
|
|
38
|
+
[attributes.URL_FULL]: pathname
|
|
39
|
+
});
|
|
46
40
|
}
|
|
47
|
-
}
|
|
48
|
-
await core.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
41
|
+
} finally {
|
|
42
|
+
await core.flushIfServerless();
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
await core.startSpan(
|
|
46
|
+
{
|
|
47
|
+
name: `${info.request.method} ${pathname}`,
|
|
48
|
+
forceTransaction: true,
|
|
49
|
+
attributes: {
|
|
50
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "http.server",
|
|
51
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.instrumentation_api",
|
|
52
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
|
|
53
|
+
[attributes.HTTP_REQUEST_METHOD]: info.request.method,
|
|
54
|
+
[attributes.URL_PATH]: pathname,
|
|
55
|
+
[attributes.URL_FULL]: core.filterCollectedUrl(info.request.url)
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
async (span) => {
|
|
59
|
+
try {
|
|
60
|
+
const result = await handleRequest();
|
|
61
|
+
if (result.status === "error" && result.error instanceof Error) {
|
|
62
|
+
span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" });
|
|
63
|
+
utils.captureInstrumentationError(result, captureErrors, "react_router.request_handler", {
|
|
64
|
+
"http.method": info.request.method,
|
|
65
|
+
[attributes.URL_FULL]: pathname
|
|
66
|
+
});
|
|
73
67
|
}
|
|
68
|
+
} finally {
|
|
69
|
+
await core.flushIfServerless();
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
}
|
|
78
74
|
}
|
|
79
75
|
});
|
|
80
76
|
},
|
|
@@ -91,7 +87,8 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
91
87
|
{
|
|
92
88
|
name: routePattern,
|
|
93
89
|
attributes: {
|
|
94
|
-
[
|
|
90
|
+
[attributes.SENTRY_OP]: op.WEB_SERVER_FUNCTION_SPAN_OP,
|
|
91
|
+
[attributes.CODE_FUNCTION_NAME]: "loader",
|
|
95
92
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.react_router.instrumentation_api"
|
|
96
93
|
}
|
|
97
94
|
},
|
|
@@ -101,7 +98,7 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
101
98
|
span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" });
|
|
102
99
|
utils.captureInstrumentationError(result, captureErrors, "react_router.loader", {
|
|
103
100
|
"http.method": info.request.method,
|
|
104
|
-
|
|
101
|
+
[attributes.URL_FULL]: urlPath
|
|
105
102
|
});
|
|
106
103
|
}
|
|
107
104
|
}
|
|
@@ -116,7 +113,8 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
116
113
|
{
|
|
117
114
|
name: routePattern,
|
|
118
115
|
attributes: {
|
|
119
|
-
[
|
|
116
|
+
[attributes.SENTRY_OP]: op.WEB_SERVER_FUNCTION_SPAN_OP,
|
|
117
|
+
[attributes.CODE_FUNCTION_NAME]: "action",
|
|
120
118
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.react_router.instrumentation_api"
|
|
121
119
|
}
|
|
122
120
|
},
|
|
@@ -126,7 +124,7 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
126
124
|
span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" });
|
|
127
125
|
utils.captureInstrumentationError(result, captureErrors, "react_router.action", {
|
|
128
126
|
"http.method": info.request.method,
|
|
129
|
-
|
|
127
|
+
[attributes.URL_FULL]: urlPath
|
|
130
128
|
});
|
|
131
129
|
}
|
|
132
130
|
}
|
|
@@ -137,18 +135,25 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
137
135
|
const pattern = utils.getPattern(info);
|
|
138
136
|
const routePattern = utils.normalizeRoutePath(pattern) || urlPath;
|
|
139
137
|
updateRootSpanWithRoute(info.request.method, pattern, urlPath);
|
|
140
|
-
const
|
|
138
|
+
const activeSpan = core.getActiveSpan();
|
|
139
|
+
const rootSpan = activeSpan ? core.getRootSpan(activeSpan) : void 0;
|
|
141
140
|
let middlewareIndex = 0;
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
if (rootSpan) {
|
|
142
|
+
let counters = middlewareCountersByRootSpan.get(rootSpan);
|
|
143
|
+
if (!counters) {
|
|
144
|
+
counters = {};
|
|
145
|
+
middlewareCountersByRootSpan.set(rootSpan, counters);
|
|
146
|
+
}
|
|
147
|
+
middlewareIndex = counters[routeId] ?? 0;
|
|
148
|
+
counters[routeId] = middlewareIndex + 1;
|
|
145
149
|
}
|
|
146
150
|
const middlewareName = serverBuild.getMiddlewareName(routeId, middlewareIndex);
|
|
147
151
|
await core.startSpan(
|
|
148
152
|
{
|
|
149
153
|
name: `middleware ${middlewareName || routeId}`,
|
|
150
154
|
attributes: {
|
|
151
|
-
[
|
|
155
|
+
[attributes.SENTRY_OP]: op.WEB_SERVER_MIDDLEWARE_SPAN_OP,
|
|
156
|
+
[attributes.CODE_FUNCTION_NAME]: "middleware",
|
|
152
157
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.react_router.instrumentation_api",
|
|
153
158
|
"react_router.route.id": routeId,
|
|
154
159
|
[attributes.HTTP_ROUTE]: routePattern,
|
|
@@ -162,7 +167,7 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
162
167
|
span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" });
|
|
163
168
|
utils.captureInstrumentationError(result, captureErrors, "react_router.middleware", {
|
|
164
169
|
"http.method": info.request.method,
|
|
165
|
-
|
|
170
|
+
[attributes.URL_FULL]: urlPath
|
|
166
171
|
});
|
|
167
172
|
}
|
|
168
173
|
}
|
|
@@ -173,7 +178,8 @@ function createSentryServerInstrumentation(options = {}) {
|
|
|
173
178
|
{
|
|
174
179
|
name: "Lazy Route Load",
|
|
175
180
|
attributes: {
|
|
176
|
-
[
|
|
181
|
+
[attributes.SENTRY_OP]: op.WEB_SERVER_FUNCTION_SPAN_OP,
|
|
182
|
+
[attributes.CODE_FUNCTION_NAME]: "lazy",
|
|
177
183
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.function.react_router.instrumentation_api"
|
|
178
184
|
}
|
|
179
185
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerInstrumentation.js","sources":["../../../src/server/createServerInstrumentation.ts"],"sourcesContent":["import { context, createContextKey } from '@opentelemetry/api';\nimport { HTTP_REQUEST_METHOD, HTTP_ROUTE, URL_FULL, URL_PATH } from '@sentry/conventions/attributes';\nimport {\n debug,\n flushIfServerless,\n getActiveSpan,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n SPAN_STATUS_ERROR,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { InstrumentableRequestHandler, InstrumentableRoute, ServerInstrumentation } from '../common/types';\nimport { captureInstrumentationError, getPathFromRequest, getPattern, normalizeRoutePath } from '../common/utils';\nimport { getMiddlewareName } from './serverBuild';\nimport { markInstrumentationApiUsed } from './serverGlobals';\n\nconst MIDDLEWARE_COUNTER_KEY = createContextKey('sentry_react_router_middleware_counter');\n\n// Re-export for backward compatibility and external use\nexport { isInstrumentationApiUsed } from './serverGlobals';\n\n/**\n * Options for creating Sentry server instrumentation.\n */\nexport interface CreateSentryServerInstrumentationOptions {\n /**\n * Whether to capture errors from loaders/actions automatically.\n * @default true\n */\n captureErrors?: boolean;\n}\n\n/**\n * Creates a Sentry server instrumentation for React Router's instrumentation API.\n */\nexport function createSentryServerInstrumentation(\n options: CreateSentryServerInstrumentationOptions = {},\n): ServerInstrumentation {\n const { captureErrors = true } = options;\n\n DEBUG_BUILD && debug.log('React Router server instrumentation created.');\n\n return {\n handler(handler: InstrumentableRequestHandler) {\n // Mark the instrumentation API active only when React Router actually invokes this\n markInstrumentationApiUsed();\n handler.instrument({\n async request(handleRequest, info) {\n const pathname = getPathFromRequest(info.request);\n const activeSpan = getActiveSpan();\n const existingRootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n\n const counterStore = { counters: {} as Record<string, number> };\n const ctx = context.active().setValue(MIDDLEWARE_COUNTER_KEY, counterStore);\n\n await context.with(ctx, async () => {\n if (existingRootSpan) {\n updateSpanName(existingRootSpan, `${info.request.method} ${pathname}`);\n existingRootSpan.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.instrumentation_api',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [URL_FULL]: info.request.url,\n [URL_PATH]: pathname,\n });\n\n try {\n const result = await handleRequest();\n if (result.status === 'error' && result.error instanceof Error) {\n existingRootSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.request_handler', {\n 'http.method': info.request.method,\n 'http.url': pathname,\n });\n }\n } finally {\n await flushIfServerless();\n }\n } else {\n await startSpan(\n {\n name: `${info.request.method} ${pathname}`,\n forceTransaction: true,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.instrumentation_api',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [HTTP_REQUEST_METHOD]: info.request.method,\n [URL_PATH]: pathname,\n [URL_FULL]: info.request.url,\n },\n },\n async span => {\n try {\n const result = await handleRequest();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.request_handler', {\n 'http.method': info.request.method,\n 'http.url': pathname,\n });\n }\n } finally {\n await flushIfServerless();\n }\n },\n );\n }\n });\n },\n });\n },\n\n route(route: InstrumentableRoute) {\n // Also mark active here, in case route registration runs (mirrors the handler callback above).\n markInstrumentationApiUsed();\n const routeId = route.id;\n\n route.instrument({\n async loader(callLoader, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = getPattern(info);\n const routePattern = normalizeRoutePath(pattern) || urlPath;\n updateRootSpanWithRoute(info.request.method, pattern, urlPath);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLoader();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.loader', {\n 'http.method': info.request.method,\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async action(callAction, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = getPattern(info);\n const routePattern = normalizeRoutePath(pattern) || urlPath;\n updateRootSpanWithRoute(info.request.method, pattern, urlPath);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.action',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callAction();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.action', {\n 'http.method': info.request.method,\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async middleware(callMiddleware, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = getPattern(info);\n const routePattern = normalizeRoutePath(pattern) || urlPath;\n\n updateRootSpanWithRoute(info.request.method, pattern, urlPath);\n\n const counterStore = context.active().getValue(MIDDLEWARE_COUNTER_KEY) as\n | { counters: Record<string, number> }\n | undefined;\n let middlewareIndex = 0;\n if (counterStore) {\n middlewareIndex = counterStore.counters[routeId] ?? 0;\n counterStore.counters[routeId] = middlewareIndex + 1;\n }\n\n const middlewareName = getMiddlewareName(routeId, middlewareIndex);\n\n await startSpan(\n {\n name: `middleware ${middlewareName || routeId}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.middleware',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n 'react_router.route.id': routeId,\n [HTTP_ROUTE]: routePattern,\n ...(middlewareName && { 'react_router.middleware.name': middlewareName }),\n 'react_router.middleware.index': middlewareIndex,\n },\n },\n async span => {\n const result = await callMiddleware();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.middleware', {\n 'http.method': info.request.method,\n 'http.url': urlPath,\n });\n }\n },\n );\n },\n\n async lazy(callLazy) {\n await startSpan(\n {\n name: 'Lazy Route Load',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.lazy',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLazy();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.lazy', {});\n }\n },\n );\n },\n });\n },\n };\n}\n\nfunction updateRootSpanWithRoute(method: string, pattern: string | undefined, urlPath: string): void {\n const activeSpan = getActiveSpan();\n if (!activeSpan) return;\n const rootSpan = getRootSpan(activeSpan);\n if (!rootSpan) return;\n\n // Skip update if URL path is invalid (failed to parse)\n if (!urlPath || urlPath === '<unknown>') {\n DEBUG_BUILD && debug.warn('Cannot update span with invalid URL path:', urlPath);\n return;\n }\n\n const hasPattern = !!pattern;\n const routeName = hasPattern ? normalizeRoutePath(pattern) || urlPath : urlPath;\n\n const transactionName = `${method} ${routeName}`;\n updateSpanName(rootSpan, transactionName);\n rootSpan.setAttributes({\n [HTTP_ROUTE]: routeName,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: hasPattern ? 'route' : 'url',\n });\n\n // Also update the scope's transaction name so errors captured during this request\n // have the correct transaction name (not the initial placeholder like \"GET *\")\n getCurrentScope().setTransactionName(transactionName);\n}\n"],"names":["createContextKey","DEBUG_BUILD","debug","markInstrumentationApiUsed","getPathFromRequest","getActiveSpan","getRootSpan","context","updateSpanName","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","URL_FULL","URL_PATH","SPAN_STATUS_ERROR","captureInstrumentationError","flushIfServerless","startSpan","HTTP_REQUEST_METHOD","getPattern","normalizeRoutePath","getMiddlewareName","HTTP_ROUTE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U,CAAA;AACvC,EAAA,IAAI,CAAC,QAAA,EAAU;AAGf,EAAA,IAAI,CAAC,OAAA,IAAW,OAAA,KAAY,WAAA,EAAa;AACvC,IAAAL,sBAAA,IAAeC,UAAA,CAAM,IAAA,CAAK,2CAAA,EAA6C,OAAO,CAAA;AAC9E,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAAa,CAAC,CAAC,OAAA;AACrB,EAAA,MAAM,SAAA,GAAY,UAAA,GAAakB,wBAAA,CAAmB,OAAO,KAAK,OAAA,GAAU,OAAA;AAExE,EAAA,MAAM,eAAA,GAAkB,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA;AAC9C,EAAAZ,mBAAA,CAAe,UAAU,eAAe,CAAA;AACxC,EAAA,QAAA,CAAS,aAAA,CAAc;AAAA,IACrB,CAACc,qBAAU,GAAG,SAAA;AAAA,IACd,CAACX,qCAAgC,GAAG,UAAA,GAAa,OAAA,GAAU;AAAA,GAC5D,CAAA;AAID,EAAAY,oBAAA,EAAgB,CAAE,mBAAmB,eAAe,CAAA;AACtD;;;;;"}
|
|
1
|
+
{"version":3,"file":"createServerInstrumentation.js","sources":["../../../src/server/createServerInstrumentation.ts"],"sourcesContent":["import {\n CODE_FUNCTION_NAME,\n HTTP_REQUEST_METHOD,\n HTTP_ROUTE,\n SENTRY_OP,\n URL_FULL,\n URL_PATH,\n} from '@sentry/conventions/attributes';\nimport { WEB_SERVER_FUNCTION_SPAN_OP, WEB_SERVER_MIDDLEWARE_SPAN_OP } from '@sentry/conventions/op';\nimport {\n debug,\n flushIfServerless,\n getActiveSpan,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n SPAN_STATUS_ERROR,\n startSpan,\n updateSpanName,\n filterCollectedUrl,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport type { InstrumentableRequestHandler, InstrumentableRoute, ServerInstrumentation } from '../common/types';\nimport { captureInstrumentationError, getPathFromRequest, getPattern, normalizeRoutePath } from '../common/utils';\nimport { getMiddlewareName } from './serverBuild';\nimport { markInstrumentationApiUsed } from './serverGlobals';\n\n// Per-request middleware counters, keyed by the request's root span (the one transaction all of a\n// request's middlewares run under). The root span is the same instance across those middleware hooks\n// whether or not a Sentry OpenTelemetry tracer provider is set up, unlike the OTel context the counter\n// used to live on (which does not propagate without a provider).\nconst middlewareCountersByRootSpan = new WeakMap<object, Record<string, number>>();\n\n// Re-export for backward compatibility and external use\nexport { isInstrumentationApiUsed } from './serverGlobals';\n\n/**\n * Options for creating Sentry server instrumentation.\n */\nexport interface CreateSentryServerInstrumentationOptions {\n /**\n * Whether to capture errors from loaders/actions automatically.\n * @default true\n */\n captureErrors?: boolean;\n}\n\n/**\n * Creates a Sentry server instrumentation for React Router's instrumentation API.\n */\nexport function createSentryServerInstrumentation(\n options: CreateSentryServerInstrumentationOptions = {},\n): ServerInstrumentation {\n const { captureErrors = true } = options;\n\n DEBUG_BUILD && debug.log('React Router server instrumentation created.');\n\n return {\n handler(handler: InstrumentableRequestHandler) {\n // Mark the instrumentation API active only when React Router actually invokes this\n markInstrumentationApiUsed();\n handler.instrument({\n async request(handleRequest, info) {\n const pathname = getPathFromRequest(info.request);\n const activeSpan = getActiveSpan();\n const existingRootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n\n if (existingRootSpan) {\n updateSpanName(existingRootSpan, `${info.request.method} ${pathname}`);\n existingRootSpan.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.instrumentation_api',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [URL_FULL]: filterCollectedUrl(info.request.url),\n [URL_PATH]: pathname,\n });\n\n try {\n const result = await handleRequest();\n if (result.status === 'error' && result.error instanceof Error) {\n existingRootSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.request_handler', {\n 'http.method': info.request.method,\n [URL_FULL]: pathname,\n });\n }\n } finally {\n await flushIfServerless();\n }\n } else {\n await startSpan(\n {\n name: `${info.request.method} ${pathname}`,\n forceTransaction: true,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.instrumentation_api',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [HTTP_REQUEST_METHOD]: info.request.method,\n [URL_PATH]: pathname,\n [URL_FULL]: filterCollectedUrl(info.request.url),\n },\n },\n async span => {\n try {\n const result = await handleRequest();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.request_handler', {\n 'http.method': info.request.method,\n [URL_FULL]: pathname,\n });\n }\n } finally {\n await flushIfServerless();\n }\n },\n );\n }\n },\n });\n },\n\n route(route: InstrumentableRoute) {\n // Also mark active here, in case route registration runs (mirrors the handler callback above).\n markInstrumentationApiUsed();\n const routeId = route.id;\n\n route.instrument({\n async loader(callLoader, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = getPattern(info);\n const routePattern = normalizeRoutePath(pattern) || urlPath;\n updateRootSpanWithRoute(info.request.method, pattern, urlPath);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SENTRY_OP]: WEB_SERVER_FUNCTION_SPAN_OP,\n [CODE_FUNCTION_NAME]: 'loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLoader();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.loader', {\n 'http.method': info.request.method,\n [URL_FULL]: urlPath,\n });\n }\n },\n );\n },\n\n async action(callAction, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = getPattern(info);\n const routePattern = normalizeRoutePath(pattern) || urlPath;\n updateRootSpanWithRoute(info.request.method, pattern, urlPath);\n\n await startSpan(\n {\n name: routePattern,\n attributes: {\n [SENTRY_OP]: WEB_SERVER_FUNCTION_SPAN_OP,\n [CODE_FUNCTION_NAME]: 'action',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callAction();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.action', {\n 'http.method': info.request.method,\n [URL_FULL]: urlPath,\n });\n }\n },\n );\n },\n\n async middleware(callMiddleware, info) {\n const urlPath = getPathFromRequest(info.request);\n const pattern = getPattern(info);\n const routePattern = normalizeRoutePath(pattern) || urlPath;\n\n updateRootSpanWithRoute(info.request.method, pattern, urlPath);\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n let middlewareIndex = 0;\n if (rootSpan) {\n let counters = middlewareCountersByRootSpan.get(rootSpan);\n if (!counters) {\n counters = {};\n middlewareCountersByRootSpan.set(rootSpan, counters);\n }\n middlewareIndex = counters[routeId] ?? 0;\n counters[routeId] = middlewareIndex + 1;\n }\n\n const middlewareName = getMiddlewareName(routeId, middlewareIndex);\n\n await startSpan(\n {\n name: `middleware ${middlewareName || routeId}`,\n attributes: {\n [SENTRY_OP]: WEB_SERVER_MIDDLEWARE_SPAN_OP,\n [CODE_FUNCTION_NAME]: 'middleware',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n 'react_router.route.id': routeId,\n [HTTP_ROUTE]: routePattern,\n ...(middlewareName && { 'react_router.middleware.name': middlewareName }),\n 'react_router.middleware.index': middlewareIndex,\n },\n },\n async span => {\n const result = await callMiddleware();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.middleware', {\n 'http.method': info.request.method,\n [URL_FULL]: urlPath,\n });\n }\n },\n );\n },\n\n async lazy(callLazy) {\n await startSpan(\n {\n name: 'Lazy Route Load',\n attributes: {\n [SENTRY_OP]: WEB_SERVER_FUNCTION_SPAN_OP,\n [CODE_FUNCTION_NAME]: 'lazy',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.react_router.instrumentation_api',\n },\n },\n async span => {\n const result = await callLazy();\n if (result.status === 'error' && result.error instanceof Error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'internal_error' });\n captureInstrumentationError(result, captureErrors, 'react_router.lazy', {});\n }\n },\n );\n },\n });\n },\n };\n}\n\nfunction updateRootSpanWithRoute(method: string, pattern: string | undefined, urlPath: string): void {\n const activeSpan = getActiveSpan();\n if (!activeSpan) return;\n const rootSpan = getRootSpan(activeSpan);\n if (!rootSpan) return;\n\n // Skip update if URL path is invalid (failed to parse)\n if (!urlPath || urlPath === '<unknown>') {\n DEBUG_BUILD && debug.warn('Cannot update span with invalid URL path:', urlPath);\n return;\n }\n\n const hasPattern = !!pattern;\n const routeName = hasPattern ? normalizeRoutePath(pattern) || urlPath : urlPath;\n\n const transactionName = `${method} ${routeName}`;\n updateSpanName(rootSpan, transactionName);\n rootSpan.setAttributes({\n [HTTP_ROUTE]: routeName,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: hasPattern ? 'route' : 'url',\n });\n\n // Also update the scope's transaction name so errors captured during this request\n // have the correct transaction name (not the initial placeholder like \"GET *\")\n getCurrentScope().setTransactionName(transactionName);\n}\n"],"names":["DEBUG_BUILD","debug","markInstrumentationApiUsed","getPathFromRequest","getActiveSpan","getRootSpan","updateSpanName","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","URL_FULL","filterCollectedUrl","URL_PATH","SPAN_STATUS_ERROR","captureInstrumentationError","flushIfServerless","startSpan","HTTP_REQUEST_METHOD","getPattern","normalizeRoutePath","SENTRY_OP","WEB_SERVER_FUNCTION_SPAN_OP","CODE_FUNCTION_NAME","getMiddlewareName","WEB_SERVER_MIDDLEWARE_SPAN_OP","HTTP_ROUTE","getCurrentScope"],"mappings":";;;;;;;;;;AAiCA,MAAM,4BAAA,uBAAmC,OAAA,EAAwC;AAmB1E,SAAS,iCAAA,CACd,OAAA,GAAoD,EAAC,EAC9B;AACvB,EAAA,MAAM,EAAE,aAAA,GAAgB,IAAA,EAAK,GAAI,OAAA;AAEjC,EAAAA,sBAAA,IAAeC,UAAA,CAAM,IAAI,8CAA8C,CAAA;AAEvE,EAAA,OAAO;AAAA,IACL,QAAQ,OAAA,EAAuC;AAE7C,MAAAC,wCAAA,EAA2B;AAC3B,MAAA,OAAA,CAAQ,UAAA,CAAW;AAAA,QACjB,MAAM,OAAA,CAAQ,aAAA,EAAe,IAAA,EAAM;AACjC,UAAA,MAAM,QAAA,GAAWC,wBAAA,CAAmB,IAAA,CAAK,OAAO,CAAA;AAChD,UAAA,MAAM,aAAaC,kBAAA,EAAc;AACjC,UAAA,MAAM,gBAAA,GAAmB,UAAA,GAAaC,gBAAA,CAAY,UAAU,CAAA,GAAI,MAAA;AAEhE,UAAA,IAAI,gBAAA,EAAkB;AACpB,YAAAC,mBAAA,CAAe,kBAAkB,CAAA,EAAG,IAAA,CAAK,QAAQ,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAE,CAAA;AACrE,YAAA,gBAAA,CAAiB,aAAA,CAAc;AAAA,cAC7B,CAACC,iCAA4B,GAAG,aAAA;AAAA,cAChC,CAACC,qCAAgC,GAAG,4CAAA;AAAA,cACpC,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1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const attributes = require('@sentry/conventions/attributes');
|
|
4
3
|
const core = require('@sentry/core');
|
|
5
|
-
const node = require('@sentry/node');
|
|
6
|
-
const reactRouter = require('../instrumentation/reactRouter.js');
|
|
7
4
|
const serverBuild = require('../serverBuild.js');
|
|
8
|
-
const serverGlobals = require('../serverGlobals.js');
|
|
9
5
|
|
|
10
6
|
const INTEGRATION_NAME = "ReactRouterServer";
|
|
11
|
-
const instrumentReactRouter = node.generateInstrumentOnce(INTEGRATION_NAME, () => {
|
|
12
|
-
return new reactRouter.ReactRouterInstrumentation();
|
|
13
|
-
});
|
|
14
|
-
const instrumentReactRouterServer = Object.assign(
|
|
15
|
-
() => {
|
|
16
|
-
instrumentReactRouter();
|
|
17
|
-
serverBuild.registerServerBuildGlobal();
|
|
18
|
-
},
|
|
19
|
-
{ id: INTEGRATION_NAME }
|
|
20
|
-
);
|
|
21
7
|
const reactRouterServerIntegration = core.defineIntegration(() => {
|
|
22
8
|
return {
|
|
23
9
|
name: INTEGRATION_NAME,
|
|
24
10
|
setupOnce() {
|
|
25
|
-
|
|
26
|
-
serverGlobals.enableOtelDataLoaderSpanCreation();
|
|
27
|
-
}
|
|
28
|
-
instrumentReactRouterServer();
|
|
29
|
-
},
|
|
30
|
-
processEvent(event) {
|
|
31
|
-
if (event.type === "transaction" && event.contexts?.trace?.data && event.contexts.trace.data[attributes.HTTP_ROUTE] === "*") {
|
|
32
|
-
const origin = event.contexts.trace.origin;
|
|
33
|
-
const isInstrumentationApiOrigin = origin?.includes("instrumentation_api");
|
|
34
|
-
if (isInstrumentationApiOrigin || !event.transaction?.endsWith(" *")) {
|
|
35
|
-
delete event.contexts.trace.data[attributes.HTTP_ROUTE];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return event;
|
|
39
|
-
},
|
|
40
|
-
processSegmentSpan(span) {
|
|
41
|
-
const attributes$1 = span.attributes;
|
|
42
|
-
if (attributes$1?.[attributes.HTTP_ROUTE] !== "*") {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const origin = attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN];
|
|
46
|
-
const isInstrumentationApiOrigin = typeof origin === "string" && origin.includes("instrumentation_api");
|
|
47
|
-
if (isInstrumentationApiOrigin || !span.name?.endsWith(" *")) {
|
|
48
|
-
delete attributes$1[attributes.HTTP_ROUTE];
|
|
49
|
-
}
|
|
11
|
+
serverBuild.registerServerBuildGlobal();
|
|
50
12
|
}
|
|
51
13
|
};
|
|
52
14
|
});
|
|
53
15
|
|
|
54
|
-
exports.instrumentReactRouterServer = instrumentReactRouterServer;
|
|
55
16
|
exports.reactRouterServerIntegration = reactRouterServerIntegration;
|
|
56
17
|
//# sourceMappingURL=reactRouterServer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactRouterServer.js","sources":["../../../../src/server/integration/reactRouterServer.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"reactRouterServer.js","sources":["../../../../src/server/integration/reactRouterServer.ts"],"sourcesContent":["import { defineIntegration } from '@sentry/core';\nimport { registerServerBuildGlobal } from '../serverBuild';\n\nconst INTEGRATION_NAME = 'ReactRouterServer' as const;\n\n/**\n * Integration capturing tracing data for React Router server functions.\n */\nexport const reactRouterServerIntegration = defineIntegration(() => {\n return {\n name: INTEGRATION_NAME,\n setupOnce() {\n // Register global for Vite plugin ServerBuild capture (used for middleware name resolution).\n registerServerBuildGlobal();\n },\n };\n});\n"],"names":["defineIntegration","registerServerBuildGlobal"],"mappings":";;;;;AAGA,MAAM,gBAAA,GAAmB,mBAAA;AAKlB,MAAM,4BAAA,GAA+BA,uBAAkB,MAAM;AAClE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,SAAA,GAAY;AAEV,MAAAC,qCAAA,EAA0B;AAAA,IAC5B;AAAA,GACF;AACF,CAAC;;;;"}
|
|
@@ -4,9 +4,6 @@ const core = require('@sentry/core');
|
|
|
4
4
|
|
|
5
5
|
const GLOBAL_KEY = "__sentrySetServerBuild";
|
|
6
6
|
let _serverBuild;
|
|
7
|
-
function isServerBuildLike(build) {
|
|
8
|
-
return build !== null && typeof build === "object" && "routes" in build && build.routes !== null && typeof build.routes === "object";
|
|
9
|
-
}
|
|
10
7
|
function setServerBuild(build) {
|
|
11
8
|
_serverBuild = build;
|
|
12
9
|
}
|
|
@@ -23,7 +20,6 @@ function registerServerBuildGlobal() {
|
|
|
23
20
|
|
|
24
21
|
exports.GLOBAL_KEY = GLOBAL_KEY;
|
|
25
22
|
exports.getMiddlewareName = getMiddlewareName;
|
|
26
|
-
exports.isServerBuildLike = isServerBuildLike;
|
|
27
23
|
exports.registerServerBuildGlobal = registerServerBuildGlobal;
|
|
28
24
|
exports.setServerBuild = setServerBuild;
|
|
29
25
|
//# sourceMappingURL=serverBuild.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverBuild.js","sources":["../../../src/server/serverBuild.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\n/**\n * Subset of ServerBuild shape for middleware name lookup.\n * The official React Router types don't expose `middleware` on route modules yet.\n * @internal\n */\ninterface ServerBuildLike {\n routes?: Record<\n string,\n {\n module?: {\n middleware?: Array<{ name?: string }>;\n };\n }\n >;\n}\n\n/** @internal */\nexport const GLOBAL_KEY = '__sentrySetServerBuild';\n\ntype GlobalObjWithBuildCapture = typeof GLOBAL_OBJ & {\n [GLOBAL_KEY]?: (build: ServerBuildLike) => void;\n};\n\n// ServerBuild reference for middleware name lookup. Updated on each createRequestHandler call.\nlet _serverBuild: ServerBuildLike | undefined;\n\n/** @internal */\nexport function isServerBuildLike(build: unknown): build is ServerBuildLike {\n return (\n build !== null &&\n typeof build === 'object' &&\n 'routes' in build &&\n build.routes !== null &&\n typeof build.routes === 'object'\n );\n}\n\n/** @internal */\nexport function setServerBuild(build: ServerBuildLike): void {\n _serverBuild = build;\n}\n\n/** @internal */\nexport function getMiddlewareName(routeId: string, index: number): string | undefined {\n if (!_serverBuild?.routes) return undefined;\n\n const route = _serverBuild.routes[routeId];\n if (!route?.module?.middleware) return undefined;\n\n const middlewareFn = route.module.middleware[index];\n return middlewareFn?.name || undefined;\n}\n\n/** @internal */\nexport function registerServerBuildGlobal(): void {\n (GLOBAL_OBJ as GlobalObjWithBuildCapture)[GLOBAL_KEY] = setServerBuild;\n}\n\n/** @internal Exported for testing. */\nexport function _resetServerBuild(): void {\n _serverBuild = undefined;\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete (GLOBAL_OBJ as GlobalObjWithBuildCapture)[GLOBAL_KEY];\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAmBO,MAAM,UAAA,GAAa;AAO1B,IAAI,YAAA;
|
|
1
|
+
{"version":3,"file":"serverBuild.js","sources":["../../../src/server/serverBuild.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\n/**\n * Subset of ServerBuild shape for middleware name lookup.\n * The official React Router types don't expose `middleware` on route modules yet.\n * @internal\n */\ninterface ServerBuildLike {\n routes?: Record<\n string,\n {\n module?: {\n middleware?: Array<{ name?: string }>;\n };\n }\n >;\n}\n\n/** @internal */\nexport const GLOBAL_KEY = '__sentrySetServerBuild';\n\ntype GlobalObjWithBuildCapture = typeof GLOBAL_OBJ & {\n [GLOBAL_KEY]?: (build: ServerBuildLike) => void;\n};\n\n// ServerBuild reference for middleware name lookup. Updated on each createRequestHandler call.\nlet _serverBuild: ServerBuildLike | undefined;\n\n/** @internal */\nexport function isServerBuildLike(build: unknown): build is ServerBuildLike {\n return (\n build !== null &&\n typeof build === 'object' &&\n 'routes' in build &&\n build.routes !== null &&\n typeof build.routes === 'object'\n );\n}\n\n/** @internal */\nexport function setServerBuild(build: ServerBuildLike): void {\n _serverBuild = build;\n}\n\n/** @internal */\nexport function getMiddlewareName(routeId: string, index: number): string | undefined {\n if (!_serverBuild?.routes) return undefined;\n\n const route = _serverBuild.routes[routeId];\n if (!route?.module?.middleware) return undefined;\n\n const middlewareFn = route.module.middleware[index];\n return middlewareFn?.name || undefined;\n}\n\n/** @internal */\nexport function registerServerBuildGlobal(): void {\n (GLOBAL_OBJ as GlobalObjWithBuildCapture)[GLOBAL_KEY] = setServerBuild;\n}\n\n/** @internal Exported for testing. */\nexport function _resetServerBuild(): void {\n _serverBuild = undefined;\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete (GLOBAL_OBJ as GlobalObjWithBuildCapture)[GLOBAL_KEY];\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAmBO,MAAM,UAAA,GAAa;AAO1B,IAAI,YAAA;AAcG,SAAS,eAAe,KAAA,EAA8B;AAC3D,EAAA,YAAA,GAAe,KAAA;AACjB;AAGO,SAAS,iBAAA,CAAkB,SAAiB,KAAA,EAAmC;AACpF,EAAA,IAAI,CAAC,YAAA,EAAc,MAAA,EAAQ,OAAO,MAAA;AAElC,EAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,MAAA,CAAO,OAAO,CAAA;AACzC,EAAA,IAAI,CAAC,KAAA,EAAO,MAAA,EAAQ,UAAA,EAAY,OAAO,MAAA;AAEvC,EAAA,MAAM,YAAA,GAAe,KAAA,CAAM,MAAA,CAAO,UAAA,CAAW,KAAK,CAAA;AAClD,EAAA,OAAO,cAAc,IAAA,IAAQ,MAAA;AAC/B;AAGO,SAAS,yBAAA,GAAkC;AAChD,EAACA,eAAA,CAAyC,UAAU,CAAA,GAAI,cAAA;AAC1D;;;;;;;"}
|
|
@@ -3,22 +3,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
|
|
5
5
|
const SENTRY_SERVER_INSTRUMENTATION_FLAG = "__sentryReactRouterServerInstrumentationUsed";
|
|
6
|
-
const SENTRY_OTEL_SPAN_CREATION_FLAG = "__sentryReactRouterOtelSpanCreationEnabled";
|
|
7
6
|
function markInstrumentationApiUsed() {
|
|
8
7
|
core.GLOBAL_OBJ[SENTRY_SERVER_INSTRUMENTATION_FLAG] = true;
|
|
9
8
|
}
|
|
10
9
|
function isInstrumentationApiUsed() {
|
|
11
10
|
return !!core.GLOBAL_OBJ[SENTRY_SERVER_INSTRUMENTATION_FLAG];
|
|
12
11
|
}
|
|
13
|
-
function enableOtelDataLoaderSpanCreation() {
|
|
14
|
-
core.GLOBAL_OBJ[SENTRY_OTEL_SPAN_CREATION_FLAG] = true;
|
|
15
|
-
}
|
|
16
|
-
function isOtelDataLoaderSpanCreationEnabled() {
|
|
17
|
-
return !!core.GLOBAL_OBJ[SENTRY_OTEL_SPAN_CREATION_FLAG];
|
|
18
|
-
}
|
|
19
12
|
|
|
20
|
-
exports.enableOtelDataLoaderSpanCreation = enableOtelDataLoaderSpanCreation;
|
|
21
13
|
exports.isInstrumentationApiUsed = isInstrumentationApiUsed;
|
|
22
|
-
exports.isOtelDataLoaderSpanCreationEnabled = isOtelDataLoaderSpanCreationEnabled;
|
|
23
14
|
exports.markInstrumentationApiUsed = markInstrumentationApiUsed;
|
|
24
15
|
//# sourceMappingURL=serverGlobals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverGlobals.js","sources":["../../../src/server/serverGlobals.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\nconst SENTRY_SERVER_INSTRUMENTATION_FLAG = '__sentryReactRouterServerInstrumentationUsed';\
|
|
1
|
+
{"version":3,"file":"serverGlobals.js","sources":["../../../src/server/serverGlobals.ts"],"sourcesContent":["import { GLOBAL_OBJ } from '@sentry/core';\n\nconst SENTRY_SERVER_INSTRUMENTATION_FLAG = '__sentryReactRouterServerInstrumentationUsed';\n\ntype GlobalObjWithFlag = typeof GLOBAL_OBJ & {\n [SENTRY_SERVER_INSTRUMENTATION_FLAG]?: boolean;\n};\n\n/**\n * Mark that the React Router instrumentation API is being used on the server.\n * @internal\n */\nexport function markInstrumentationApiUsed(): void {\n (GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_SERVER_INSTRUMENTATION_FLAG] = true;\n}\n\n/**\n * Check if React Router's instrumentation API is being used on the server.\n */\nexport function isInstrumentationApiUsed(): boolean {\n return !!(GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_SERVER_INSTRUMENTATION_FLAG];\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAEA,MAAM,kCAAA,GAAqC,8CAAA;AAUpC,SAAS,0BAAA,GAAmC;AACjD,EAACA,eAAA,CAAiC,kCAAkC,CAAA,GAAI,IAAA;AAC1E;AAKO,SAAS,wBAAA,GAAoC;AAClD,EAAA,OAAO,CAAC,CAAEA,eAAA,CAAiC,kCAAkC,CAAA;AAC/E;;;;;"}
|
|
@@ -10,6 +10,12 @@ function getSentryConfig(viteConfig) {
|
|
|
10
10
|
}
|
|
11
11
|
return viteConfig.sentryConfig;
|
|
12
12
|
}
|
|
13
|
+
function resolveSourceMapsDisable(sentryConfig) {
|
|
14
|
+
if (sentryConfig.sourceMapsUploadOptions?.enabled === false) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return sentryConfig.sourcemaps?.disable ?? sentryConfig.unstable_sentryVitePluginOptions?.sourcemaps?.disable;
|
|
18
|
+
}
|
|
13
19
|
const sentryOnBuildEnd = async ({ reactRouterConfig, viteConfig }) => {
|
|
14
20
|
const sentryConfig = getSentryConfig(viteConfig);
|
|
15
21
|
const {
|
|
@@ -33,8 +39,7 @@ const sentryOnBuildEnd = async ({ reactRouterConfig, viteConfig }) => {
|
|
|
33
39
|
...unstableSentryVitePluginOptions?.sourcemaps,
|
|
34
40
|
...sentryConfig.sourcemaps,
|
|
35
41
|
...sourceMapsUploadOptions,
|
|
36
|
-
|
|
37
|
-
disable: sourceMapsUploadOptions?.enabled === false ? true : sentryConfig.sourcemaps?.disable
|
|
42
|
+
disable: resolveSourceMapsDisable(sentryConfig)
|
|
38
43
|
},
|
|
39
44
|
release: {
|
|
40
45
|
...unstableSentryVitePluginOptions?.release,
|
|
@@ -56,7 +61,9 @@ const sentryOnBuildEnd = async ({ reactRouterConfig, viteConfig }) => {
|
|
|
56
61
|
console.error("[Sentry] Could not create release", error);
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
const sourceMapsFullyDisabled = sourcemaps?.disable === true;
|
|
65
|
+
const uploadDisabled = sourceMapsFullyDisabled || sourcemaps?.disable === "disable-upload";
|
|
66
|
+
if (!sourceMapsFullyDisabled && viteConfig.build.sourcemap !== false) {
|
|
60
67
|
try {
|
|
61
68
|
await cliInstance.execute(
|
|
62
69
|
["sourcemaps", "inject", reactRouterConfig.buildDirectory],
|
|
@@ -65,19 +72,24 @@ const sentryOnBuildEnd = async ({ reactRouterConfig, viteConfig }) => {
|
|
|
65
72
|
} catch (error) {
|
|
66
73
|
console.error("[Sentry] Could not inject debug ids", error);
|
|
67
74
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
if (!uploadDisabled) {
|
|
76
|
+
try {
|
|
77
|
+
await cliInstance.releases.uploadSourceMaps(release?.name || "undefined", {
|
|
78
|
+
include: [
|
|
79
|
+
{
|
|
80
|
+
paths: [reactRouterConfig.buildDirectory]
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
live: "rejectOnError"
|
|
84
|
+
});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error("[Sentry] Could not upload sourcemaps", error);
|
|
87
|
+
}
|
|
79
88
|
}
|
|
80
89
|
}
|
|
90
|
+
if (uploadDisabled) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
81
93
|
let updatedFilesToDeleteAfterUpload = await sourcemaps?.filesToDeleteAfterUpload;
|
|
82
94
|
if (typeof updatedFilesToDeleteAfterUpload === "undefined") {
|
|
83
95
|
updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleOnBuildEnd.js","sources":["../../../../src/vite/buildEnd/handleOnBuildEnd.ts"],"sourcesContent":["import { rm } from 'node:fs/promises';\nimport type { Config } from '@react-router/dev/config';\nimport SentryCli from '@sentry/cli';\nimport type { SentryVitePluginOptions } from '@sentry/vite-plugin';\nimport { glob } from 'glob';\nimport type { SentryReactRouterBuildOptions } from '../types';\n\ntype BuildEndHook = NonNullable<Config['buildEnd']>;\n\nfunction getSentryConfig(viteConfig: unknown): SentryReactRouterBuildOptions {\n if (!viteConfig || typeof viteConfig !== 'object' || !('sentryConfig' in viteConfig)) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] sentryConfig not found - it needs to be passed to vite.config.ts');\n }\n\n return (viteConfig as { sentryConfig: SentryReactRouterBuildOptions }).sentryConfig;\n}\n\n/**\n * A build end hook that handles Sentry release creation and source map uploads.\n * It creates a new Sentry release if configured, uploads source maps to Sentry,\n * and optionally deletes the source map files after upload.\n */\nexport const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteConfig }) => {\n const sentryConfig = getSentryConfig(viteConfig);\n\n // todo(v11): Remove deprecated sourceMapsUploadOptions support (no need for spread/pick anymore)\n const {\n sourceMapsUploadOptions, // extract to exclude from rest config\n ...sentryConfigWithoutDeprecatedSourceMapOption\n } = sentryConfig;\n\n const unstableSentryVitePluginOptions = sentryConfig.unstable_sentryVitePluginOptions;\n\n const {\n authToken,\n org,\n project,\n release,\n sourcemaps = { disable: false },\n debug = false,\n }: Omit<SentryReactRouterBuildOptions, 'sourcemaps' | 'sourceMapsUploadOptions'> &\n // Pick 'sourcemaps' from Vite plugin options as the types allow more (e.g. Promise values for `deleteFilesAfterUpload`)\n Pick<SentryVitePluginOptions, 'sourcemaps'> = {\n ...unstableSentryVitePluginOptions,\n ...sentryConfigWithoutDeprecatedSourceMapOption, // spread in the config without the deprecated sourceMapsUploadOptions\n sourcemaps: {\n ...unstableSentryVitePluginOptions?.sourcemaps,\n ...sentryConfig.sourcemaps,\n ...sourceMapsUploadOptions,\n // eslint-disable-next-line typescript/no-deprecated\n disable: sourceMapsUploadOptions?.enabled === false ? true : sentryConfig.sourcemaps?.disable,\n },\n release: {\n ...unstableSentryVitePluginOptions?.release,\n ...sentryConfig.release,\n },\n project: unstableSentryVitePluginOptions?.project\n ? Array.isArray(unstableSentryVitePluginOptions?.project)\n ? unstableSentryVitePluginOptions?.project[0]\n : unstableSentryVitePluginOptions?.project\n : sentryConfigWithoutDeprecatedSourceMapOption.project,\n };\n\n const cliInstance = new SentryCli(null, {\n authToken,\n org,\n ...sentryConfig.unstable_sentryVitePluginOptions,\n // same handling as in bundler plugins: https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/05084f214c763a05137d863ff5a05ef38254f68d/packages/bundler-plugin-core/src/build-plugin-manager.ts#L102-L103\n project: Array.isArray(project) ? project[0] : project,\n });\n\n // check if release should be created\n if (release?.name) {\n try {\n await cliInstance.releases.new(release.name);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] Could not create release', error);\n }\n }\n\n if (!sourcemaps?.disable && viteConfig.build.sourcemap !== false) {\n // inject debugIds\n try {\n await cliInstance.execute(\n ['sourcemaps', 'inject', reactRouterConfig.buildDirectory],\n debug ? 'rejectOnError' : false,\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] Could not inject debug ids', error);\n }\n\n // upload sourcemaps\n try {\n await cliInstance.releases.uploadSourceMaps(release?.name || 'undefined', {\n include: [\n {\n paths: [reactRouterConfig.buildDirectory],\n },\n ],\n live: 'rejectOnError',\n });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] Could not upload sourcemaps', error);\n }\n }\n // delete sourcemaps after upload\n let updatedFilesToDeleteAfterUpload = await sourcemaps?.filesToDeleteAfterUpload;\n\n // set a default value no option was set\n if (typeof updatedFilesToDeleteAfterUpload === 'undefined') {\n updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];\n debug &&\n // eslint-disable-next-line no-console\n console.info(\n `[Sentry] Automatically setting \\`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify(\n updatedFilesToDeleteAfterUpload,\n )}\\` to delete generated source maps after they were uploaded to Sentry.`,\n );\n }\n if (updatedFilesToDeleteAfterUpload) {\n try {\n const filePathsToDelete = await glob(updatedFilesToDeleteAfterUpload, {\n absolute: true,\n nodir: true,\n });\n if (debug) {\n filePathsToDelete.forEach(filePathToDelete => {\n // eslint-disable-next-line no-console\n console.info(`Deleting asset after upload: ${filePathToDelete}`);\n });\n }\n await Promise.all(\n filePathsToDelete.map(filePathToDelete =>\n rm(filePathToDelete, { force: true }).catch((e: unknown) => {\n // This is allowed to fail - we just don't do anything\n debug &&\n // eslint-disable-next-line no-console\n console.debug(`An error occurred while attempting to delete asset: ${filePathToDelete}`, e);\n }),\n ),\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error deleting files after sourcemap upload:', error);\n }\n }\n};\n"],"names":["SentryCli","glob","rm"],"mappings":";;;;;;AASA,SAAS,gBAAgB,UAAA,EAAoD;AAC3E,EAAA,IAAI,CAAC,UAAA,IAAc,OAAO,eAAe,QAAA,IAAY,EAAE,kBAAkB,UAAA,CAAA,EAAa;AAEpF,IAAA,OAAA,CAAQ,MAAM,2EAA2E,CAAA;AAAA,EAC3F;AAEA,EAAA,OAAQ,UAAA,CAA+D,YAAA;AACzE;AAOO,MAAM,gBAAA,GAAiC,OAAO,EAAE,iBAAA,EAAmB,YAAW,KAAM;AACzF,EAAA,MAAM,YAAA,GAAe,gBAAgB,UAAU,CAAA;AAG/C,EAAA,MAAM;AAAA,IACJ,uBAAA;AAAA;AAAA,IACA,GAAG;AAAA,GACL,GAAI,YAAA;AAEJ,EAAA,MAAM,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,QACpE,QAAA,EAAU,IAAA;AAAA,QACV,KAAA,EAAO;AAAA,OACR,CAAA;AACD,MAAA,IAAI,KAAA,EAAO;AACT,QAAA,iBAAA,CAAkB,QAAQ,CAAA,gBAAA,KAAoB;AAE5C,UAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,6BAAA,EAAgC,gBAAgB,CAAA,CAAE,CAAA;AAAA,QACjE,CAAC,CAAA;AAAA,MACH;AACA,MAAA,MAAM,OAAA,CAAQ,GAAA;AAAA,QACZ,iBAAA,CAAkB,GAAA;AAAA,UAAI,CAAA,gBAAA,KACpBC,WAAA,CAAG,gBAAA,EAAkB,EAAE,KAAA,EAAO,MAAM,CAAA,CAAE,KAAA,CAAM,CAAC,CAAA,KAAe;AAE1D,YAAA,KAAA;AAAA,YAEE,OAAA,CAAQ,KAAA,CAAM,CAAA,oDAAA,EAAuD,gBAAgB,IAAI,CAAC,CAAA;AAAA,UAC9F,CAAC;AAAA;AACH,OACF;AAAA,IACF,SAAS,KAAA,EAAO;AAEd,MAAA,OAAA,CAAQ,KAAA,CAAM,gDAAgD,KAAK,CAAA;AAAA,IACrE;AAAA,EACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"handleOnBuildEnd.js","sources":["../../../../src/vite/buildEnd/handleOnBuildEnd.ts"],"sourcesContent":["import { rm } from 'node:fs/promises';\nimport type { Config } from '@react-router/dev/config';\nimport SentryCli from '@sentry/cli';\nimport type { SentryVitePluginOptions } from '@sentry/bundler-plugins/vite';\nimport { glob } from 'glob';\nimport type { SentryReactRouterBuildOptions } from '../types';\n\ntype BuildEndHook = NonNullable<Config['buildEnd']>;\n\nfunction getSentryConfig(viteConfig: unknown): SentryReactRouterBuildOptions {\n if (!viteConfig || typeof viteConfig !== 'object' || !('sentryConfig' in viteConfig)) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] sentryConfig not found - it needs to be passed to vite.config.ts');\n }\n\n return (viteConfig as { sentryConfig: SentryReactRouterBuildOptions }).sentryConfig;\n}\n\n/**\n * This hook is the only place that injects debug IDs and uploads source maps for React\n * Router, so `disable` has to be honoured wherever the user set it. Reading it from the\n * top-level config only would silently ignore `unstable_sentryVitePluginOptions`.\n */\nfunction resolveSourceMapsDisable(sentryConfig: SentryReactRouterBuildOptions): boolean | 'disable-upload' | undefined {\n // eslint-disable-next-line typescript/no-deprecated\n if (sentryConfig.sourceMapsUploadOptions?.enabled === false) {\n return true;\n }\n\n return sentryConfig.sourcemaps?.disable ?? sentryConfig.unstable_sentryVitePluginOptions?.sourcemaps?.disable;\n}\n\n/**\n * A build end hook that handles Sentry release creation and source map uploads.\n * It creates a new Sentry release if configured, uploads source maps to Sentry,\n * and optionally deletes the source map files after upload.\n */\nexport const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteConfig }) => {\n const sentryConfig = getSentryConfig(viteConfig);\n\n // todo(v11): Remove deprecated sourceMapsUploadOptions support (no need for spread/pick anymore)\n const {\n sourceMapsUploadOptions, // extract to exclude from rest config\n ...sentryConfigWithoutDeprecatedSourceMapOption\n } = sentryConfig;\n\n const unstableSentryVitePluginOptions = sentryConfig.unstable_sentryVitePluginOptions;\n\n const {\n authToken,\n org,\n project,\n release,\n sourcemaps = { disable: false },\n debug = false,\n }: Omit<SentryReactRouterBuildOptions, 'sourcemaps' | 'sourceMapsUploadOptions'> &\n // Pick 'sourcemaps' from Vite plugin options as the types allow more (e.g. Promise values for `deleteFilesAfterUpload`)\n Pick<SentryVitePluginOptions, 'sourcemaps'> = {\n ...unstableSentryVitePluginOptions,\n ...sentryConfigWithoutDeprecatedSourceMapOption, // spread in the config without the deprecated sourceMapsUploadOptions\n sourcemaps: {\n ...unstableSentryVitePluginOptions?.sourcemaps,\n ...sentryConfig.sourcemaps,\n ...sourceMapsUploadOptions,\n disable: resolveSourceMapsDisable(sentryConfig),\n },\n release: {\n ...unstableSentryVitePluginOptions?.release,\n ...sentryConfig.release,\n },\n project: unstableSentryVitePluginOptions?.project\n ? Array.isArray(unstableSentryVitePluginOptions?.project)\n ? unstableSentryVitePluginOptions?.project[0]\n : unstableSentryVitePluginOptions?.project\n : sentryConfigWithoutDeprecatedSourceMapOption.project,\n };\n\n const cliInstance = new SentryCli(null, {\n authToken,\n org,\n ...sentryConfig.unstable_sentryVitePluginOptions,\n // same handling as in bundler plugins: https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/05084f214c763a05137d863ff5a05ef38254f68d/packages/bundler-plugin-core/src/build-plugin-manager.ts#L102-L103\n project: Array.isArray(project) ? project[0] : project,\n });\n\n // check if release should be created\n if (release?.name) {\n try {\n await cliInstance.releases.new(release.name);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] Could not create release', error);\n }\n }\n\n // `disable: 'disable-upload'` still injects debug IDs, so that source maps can be\n // uploaded manually at a later point - only `true` turns source maps off entirely.\n const sourceMapsFullyDisabled = sourcemaps?.disable === true;\n const uploadDisabled = sourceMapsFullyDisabled || sourcemaps?.disable === 'disable-upload';\n\n if (!sourceMapsFullyDisabled && viteConfig.build.sourcemap !== false) {\n // inject debugIds\n try {\n await cliInstance.execute(\n ['sourcemaps', 'inject', reactRouterConfig.buildDirectory],\n debug ? 'rejectOnError' : false,\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] Could not inject debug ids', error);\n }\n\n if (!uploadDisabled) {\n // upload sourcemaps\n try {\n await cliInstance.releases.uploadSourceMaps(release?.name || 'undefined', {\n include: [\n {\n paths: [reactRouterConfig.buildDirectory],\n },\n ],\n live: 'rejectOnError',\n });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('[Sentry] Could not upload sourcemaps', error);\n }\n }\n }\n\n // Only clean up source maps that were actually uploaded. Deleting them after skipping\n // the upload would leave the user with neither, breaking a manual upload.\n if (uploadDisabled) {\n return;\n }\n\n // delete sourcemaps after upload\n let updatedFilesToDeleteAfterUpload = await sourcemaps?.filesToDeleteAfterUpload;\n\n // set a default value no option was set\n if (typeof updatedFilesToDeleteAfterUpload === 'undefined') {\n updatedFilesToDeleteAfterUpload = [`${reactRouterConfig.buildDirectory}/**/*.map`];\n debug &&\n // eslint-disable-next-line no-console\n console.info(\n `[Sentry] Automatically setting \\`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify(\n updatedFilesToDeleteAfterUpload,\n )}\\` to delete generated source maps after they were uploaded to Sentry.`,\n );\n }\n if (updatedFilesToDeleteAfterUpload) {\n try {\n const filePathsToDelete = await glob(updatedFilesToDeleteAfterUpload, {\n absolute: true,\n nodir: true,\n });\n if (debug) {\n filePathsToDelete.forEach(filePathToDelete => {\n // eslint-disable-next-line no-console\n console.info(`Deleting asset after upload: ${filePathToDelete}`);\n });\n }\n await Promise.all(\n filePathsToDelete.map(filePathToDelete =>\n rm(filePathToDelete, { force: true }).catch((e: unknown) => {\n // This is allowed to fail - we just don't do anything\n debug &&\n // eslint-disable-next-line no-console\n console.debug(`An error occurred while attempting to delete asset: ${filePathToDelete}`, e);\n }),\n ),\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error deleting files after sourcemap upload:', error);\n }\n }\n};\n"],"names":["SentryCli","glob","rm"],"mappings":";;;;;;AASA,SAAS,gBAAgB,UAAA,EAAoD;AAC3E,EAAA,IAAI,CAAC,UAAA,IAAc,OAAO,eAAe,QAAA,IAAY,EAAE,kBAAkB,UAAA,CAAA,EAAa;AAEpF,IAAA,OAAA,CAAQ,MAAM,2EAA2E,CAAA;AAAA,EAC3F;AAEA,EAAA,OAAQ,UAAA,CAA+D,YAAA;AACzE;AAOA,SAAS,yBAAyB,YAAA,EAAqF;AAErH,EAAA,IAAI,YAAA,CAAa,uBAAA,EAAyB,OAAA,KAAY,KAAA,EAAO;AAC3D,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,YAAA,CAAa,UAAA,EAAY,OAAA,IAAW,YAAA,CAAa,kCAAkC,UAAA,EAAY,OAAA;AACxG;AAOO,MAAM,gBAAA,GAAiC,OAAO,EAAE,iBAAA,EAAmB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