@sentry/react-router 10.53.1 → 10.54.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 +104 -175
- package/build/cjs/client/createClientInstrumentation.js.map +1 -1
- package/build/cjs/client/hydratedRouter.js +27 -74
- package/build/cjs/client/hydratedRouter.js.map +1 -1
- package/build/cjs/client/sdk.js +5 -16
- package/build/cjs/client/sdk.js.map +1 -1
- package/build/cjs/client/sentryOnError.js +4 -27
- package/build/cjs/client/sentryOnError.js.map +1 -1
- package/build/cjs/client/tracingIntegration.js +4 -18
- package/build/cjs/client/tracingIntegration.js.map +1 -1
- package/build/cjs/client/utils.js +5 -17
- package/build/cjs/client/utils.js.map +1 -1
- package/build/cjs/cloudflare/index.js +2 -15
- package/build/cjs/cloudflare/index.js.map +1 -1
- package/build/cjs/common/debug-build.js +0 -5
- package/build/cjs/common/debug-build.js.map +1 -1
- package/build/cjs/common/utils.js +8 -33
- package/build/cjs/common/utils.js.map +1 -1
- package/build/cjs/server/createSentryHandleError.js +4 -13
- package/build/cjs/server/createSentryHandleError.js.map +1 -1
- package/build/cjs/server/createSentryHandleRequest.js +14 -49
- package/build/cjs/server/createSentryHandleRequest.js.map +1 -1
- package/build/cjs/server/createServerInstrumentation.js +76 -114
- package/build/cjs/server/createServerInstrumentation.js.map +1 -1
- package/build/cjs/server/getMetaTagTransformer.js +2 -8
- package/build/cjs/server/getMetaTagTransformer.js.map +1 -1
- package/build/cjs/server/instrumentation/reactRouter.js +21 -47
- package/build/cjs/server/instrumentation/reactRouter.js.map +1 -1
- package/build/cjs/server/instrumentation/util.js +5 -41
- package/build/cjs/server/instrumentation/util.js.map +1 -1
- package/build/cjs/server/integration/lowQualityTransactionsFilterIntegration.js +5 -12
- package/build/cjs/server/integration/lowQualityTransactionsFilterIntegration.js.map +1 -1
- package/build/cjs/server/integration/reactRouterServer.js +10 -42
- package/build/cjs/server/integration/reactRouterServer.js.map +1 -1
- package/build/cjs/server/sdk.js +6 -20
- package/build/cjs/server/sdk.js.map +1 -1
- package/build/cjs/server/serverBuild.js +6 -31
- package/build/cjs/server/serverBuild.js.map +1 -1
- package/build/cjs/server/serverGlobals.js +6 -26
- package/build/cjs/server/serverGlobals.js.map +1 -1
- package/build/cjs/server/wrapSentryHandleRequest.js +13 -53
- package/build/cjs/server/wrapSentryHandleRequest.js.map +1 -1
- package/build/cjs/server/wrapServerAction.js +12 -44
- package/build/cjs/server/wrapServerAction.js.map +1 -1
- package/build/cjs/server/wrapServerLoader.js +12 -44
- package/build/cjs/server/wrapServerLoader.js.map +1 -1
- package/build/cjs/vite/buildEnd/handleOnBuildEnd.js +38 -72
- package/build/cjs/vite/buildEnd/handleOnBuildEnd.js.map +1 -1
- package/build/cjs/vite/makeConfigInjectorPlugin.js +4 -12
- package/build/cjs/vite/makeConfigInjectorPlugin.js.map +1 -1
- package/build/cjs/vite/makeCustomSentryVitePlugins.js +10 -15
- package/build/cjs/vite/makeCustomSentryVitePlugins.js.map +1 -1
- package/build/cjs/vite/makeEnableSourceMapsPlugin.js +19 -51
- package/build/cjs/vite/makeEnableSourceMapsPlugin.js.map +1 -1
- package/build/cjs/vite/makeServerBuildCapturePlugin.js +4 -15
- package/build/cjs/vite/makeServerBuildCapturePlugin.js.map +1 -1
- package/build/cjs/vite/plugin.js +3 -16
- package/build/cjs/vite/plugin.js.map +1 -1
- package/build/esm/client/createClientInstrumentation.js +104 -175
- package/build/esm/client/createClientInstrumentation.js.map +1 -1
- package/build/esm/client/hydratedRouter.js +27 -74
- package/build/esm/client/hydratedRouter.js.map +1 -1
- package/build/esm/client/sdk.js +5 -16
- package/build/esm/client/sdk.js.map +1 -1
- package/build/esm/client/sentryOnError.js +4 -27
- package/build/esm/client/sentryOnError.js.map +1 -1
- package/build/esm/client/tracingIntegration.js +4 -18
- package/build/esm/client/tracingIntegration.js.map +1 -1
- package/build/esm/client/utils.js +5 -17
- package/build/esm/client/utils.js.map +1 -1
- package/build/esm/cloudflare/index.js +2 -15
- package/build/esm/cloudflare/index.js.map +1 -1
- package/build/esm/common/debug-build.js +0 -5
- package/build/esm/common/debug-build.js.map +1 -1
- package/build/esm/common/utils.js +8 -33
- package/build/esm/common/utils.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/server/createSentryHandleError.js +4 -13
- package/build/esm/server/createSentryHandleError.js.map +1 -1
- package/build/esm/server/createSentryHandleRequest.js +14 -49
- package/build/esm/server/createSentryHandleRequest.js.map +1 -1
- package/build/esm/server/createServerInstrumentation.js +76 -114
- package/build/esm/server/createServerInstrumentation.js.map +1 -1
- package/build/esm/server/getMetaTagTransformer.js +2 -8
- package/build/esm/server/getMetaTagTransformer.js.map +1 -1
- package/build/esm/server/instrumentation/reactRouter.js +21 -47
- package/build/esm/server/instrumentation/reactRouter.js.map +1 -1
- package/build/esm/server/instrumentation/util.js +5 -41
- package/build/esm/server/instrumentation/util.js.map +1 -1
- package/build/esm/server/integration/lowQualityTransactionsFilterIntegration.js +5 -12
- package/build/esm/server/integration/lowQualityTransactionsFilterIntegration.js.map +1 -1
- package/build/esm/server/integration/reactRouterServer.js +10 -42
- package/build/esm/server/integration/reactRouterServer.js.map +1 -1
- package/build/esm/server/sdk.js +6 -20
- package/build/esm/server/sdk.js.map +1 -1
- package/build/esm/server/serverBuild.js +6 -31
- package/build/esm/server/serverBuild.js.map +1 -1
- package/build/esm/server/serverGlobals.js +6 -26
- package/build/esm/server/serverGlobals.js.map +1 -1
- package/build/esm/server/wrapSentryHandleRequest.js +13 -53
- package/build/esm/server/wrapSentryHandleRequest.js.map +1 -1
- package/build/esm/server/wrapServerAction.js +12 -44
- package/build/esm/server/wrapServerAction.js.map +1 -1
- package/build/esm/server/wrapServerLoader.js +12 -44
- package/build/esm/server/wrapServerLoader.js.map +1 -1
- package/build/esm/vite/buildEnd/handleOnBuildEnd.js +38 -72
- package/build/esm/vite/buildEnd/handleOnBuildEnd.js.map +1 -1
- package/build/esm/vite/makeConfigInjectorPlugin.js +4 -12
- package/build/esm/vite/makeConfigInjectorPlugin.js.map +1 -1
- package/build/esm/vite/makeCustomSentryVitePlugins.js +10 -15
- package/build/esm/vite/makeCustomSentryVitePlugins.js.map +1 -1
- package/build/esm/vite/makeEnableSourceMapsPlugin.js +19 -51
- package/build/esm/vite/makeEnableSourceMapsPlugin.js.map +1 -1
- package/build/esm/vite/makeServerBuildCapturePlugin.js +4 -15
- package/build/esm/vite/makeServerBuildCapturePlugin.js.map +1 -1
- package/build/esm/vite/plugin.js +3 -16
- package/build/esm/vite/plugin.js.map +1 -1
- package/build/types/client/hydratedRouter.d.ts.map +1 -1
- package/package.json +5 -5
package/build/cjs/server/sdk.js
CHANGED
|
@@ -6,37 +6,23 @@ const debugBuild = require('../common/debug-build.js');
|
|
|
6
6
|
const lowQualityTransactionsFilterIntegration = require('./integration/lowQualityTransactionsFilterIntegration.js');
|
|
7
7
|
const reactRouterServer = require('./integration/reactRouterServer.js');
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Returns the default integrations for the React Router SDK.
|
|
11
|
-
* @param options The options for the SDK.
|
|
12
|
-
*/
|
|
13
9
|
function getDefaultReactRouterServerIntegrations(options) {
|
|
14
10
|
return [
|
|
15
11
|
...node.getDefaultIntegrations(options),
|
|
16
12
|
lowQualityTransactionsFilterIntegration.lowQualityTransactionsFilterIntegration(options),
|
|
17
|
-
reactRouterServer.reactRouterServerIntegration()
|
|
13
|
+
reactRouterServer.reactRouterServerIntegration()
|
|
18
14
|
];
|
|
19
15
|
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Initializes the server side of the React Router SDK
|
|
23
|
-
*/
|
|
24
16
|
function init(options) {
|
|
25
17
|
const opts = {
|
|
26
18
|
...options,
|
|
27
|
-
defaultIntegrations: getDefaultReactRouterServerIntegrations(options)
|
|
19
|
+
defaultIntegrations: getDefaultReactRouterServerIntegrations(options)
|
|
28
20
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
core.applySdkMetadata(opts, 'react-router', ['react-router', 'node']);
|
|
33
|
-
|
|
21
|
+
debugBuild.DEBUG_BUILD && core.debug.log("Initializing SDK...");
|
|
22
|
+
core.applySdkMetadata(opts, "react-router", ["react-router", "node"]);
|
|
34
23
|
const client = node.init(opts);
|
|
35
|
-
|
|
36
|
-
core.
|
|
37
|
-
|
|
38
|
-
debugBuild.DEBUG_BUILD && core.debug.log('SDK successfully initialized');
|
|
39
|
-
|
|
24
|
+
core.setTag("runtime", "node");
|
|
25
|
+
debugBuild.DEBUG_BUILD && core.debug.log("SDK successfully initialized");
|
|
40
26
|
return client;
|
|
41
27
|
}
|
|
42
28
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { applySdkMetadata, debug, setTag } from '@sentry/core';\nimport type { NodeClient, NodeOptions } from '@sentry/node';\nimport { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk } from '@sentry/node';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { lowQualityTransactionsFilterIntegration } from './integration/lowQualityTransactionsFilterIntegration';\nimport { reactRouterServerIntegration } from './integration/reactRouterServer';\n\n/**\n * Returns the default integrations for the React Router SDK.\n * @param options The options for the SDK.\n */\nexport function getDefaultReactRouterServerIntegrations(options: NodeOptions): Integration[] {\n return [\n ...getNodeDefaultIntegrations(options),\n lowQualityTransactionsFilterIntegration(options),\n reactRouterServerIntegration(),\n ];\n}\n\n/**\n * Initializes the server side of the React Router SDK\n */\nexport function init(options: NodeOptions): NodeClient | undefined {\n const opts: NodeOptions = {\n ...options,\n defaultIntegrations: getDefaultReactRouterServerIntegrations(options),\n };\n\n DEBUG_BUILD && debug.log('Initializing SDK...');\n\n applySdkMetadata(opts, 'react-router', ['react-router', 'node']);\n\n const client = initNodeSdk(opts);\n\n setTag('runtime', 'node');\n\n DEBUG_BUILD && debug.log('SDK successfully initialized');\n\n return client;\n}\n"],"names":["getNodeDefaultIntegrations","lowQualityTransactionsFilterIntegration","reactRouterServerIntegration","DEBUG_BUILD","debug","applySdkMetadata","initNodeSdk","setTag"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"sdk.js","sources":["../../../src/server/sdk.ts"],"sourcesContent":["import type { Integration } from '@sentry/core';\nimport { applySdkMetadata, debug, setTag } from '@sentry/core';\nimport type { NodeClient, NodeOptions } from '@sentry/node';\nimport { getDefaultIntegrations as getNodeDefaultIntegrations, init as initNodeSdk } from '@sentry/node';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { lowQualityTransactionsFilterIntegration } from './integration/lowQualityTransactionsFilterIntegration';\nimport { reactRouterServerIntegration } from './integration/reactRouterServer';\n\n/**\n * Returns the default integrations for the React Router SDK.\n * @param options The options for the SDK.\n */\nexport function getDefaultReactRouterServerIntegrations(options: NodeOptions): Integration[] {\n return [\n ...getNodeDefaultIntegrations(options),\n lowQualityTransactionsFilterIntegration(options),\n reactRouterServerIntegration(),\n ];\n}\n\n/**\n * Initializes the server side of the React Router SDK\n */\nexport function init(options: NodeOptions): NodeClient | undefined {\n const opts: NodeOptions = {\n ...options,\n defaultIntegrations: getDefaultReactRouterServerIntegrations(options),\n };\n\n DEBUG_BUILD && debug.log('Initializing SDK...');\n\n applySdkMetadata(opts, 'react-router', ['react-router', 'node']);\n\n const client = initNodeSdk(opts);\n\n setTag('runtime', 'node');\n\n DEBUG_BUILD && debug.log('SDK successfully initialized');\n\n return client;\n}\n"],"names":["getNodeDefaultIntegrations","lowQualityTransactionsFilterIntegration","reactRouterServerIntegration","DEBUG_BUILD","debug","applySdkMetadata","initNodeSdk","setTag"],"mappings":";;;;;;;;AAYO,SAAS,wCAAwC,OAAA,EAAqC;AAC3F,EAAA,OAAO;AAAA,IACL,GAAGA,4BAA2B,OAAO,CAAA;AAAA,IACrCC,gFAAwC,OAAO,CAAA;AAAA,IAC/CC,8CAAA;AAA6B,GAC/B;AACF;AAKO,SAAS,KAAK,OAAA,EAA8C;AACjE,EAAA,MAAM,IAAA,GAAoB;AAAA,IACxB,GAAG,OAAA;AAAA,IACH,mBAAA,EAAqB,wCAAwC,OAAO;AAAA,GACtE;AAEA,EAAAC,sBAAA,IAAeC,UAAA,CAAM,IAAI,qBAAqB,CAAA;AAE9C,EAAAC,qBAAA,CAAiB,IAAA,EAAM,cAAA,EAAgB,CAAC,cAAA,EAAgB,MAAM,CAAC,CAAA;AAE/D,EAAA,MAAM,MAAA,GAASC,UAAY,IAAI,CAAA;AAE/B,EAAAC,WAAA,CAAO,WAAW,MAAM,CAAA;AAExB,EAAAJ,sBAAA,IAAeC,UAAA,CAAM,IAAI,8BAA8B,CAAA;AAEvD,EAAA,OAAO,MAAA;AACT;;;;;"}
|
|
@@ -2,48 +2,23 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Subset of ServerBuild shape for middleware name lookup.
|
|
7
|
-
* The official React Router types don't expose `middleware` on route modules yet.
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** @internal */
|
|
12
|
-
const GLOBAL_KEY = '__sentrySetServerBuild';
|
|
13
|
-
|
|
14
|
-
// ServerBuild reference for middleware name lookup. Updated on each createRequestHandler call.
|
|
5
|
+
const GLOBAL_KEY = "__sentrySetServerBuild";
|
|
15
6
|
let _serverBuild;
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
7
|
function isServerBuildLike(build) {
|
|
19
|
-
return
|
|
20
|
-
build !== null &&
|
|
21
|
-
typeof build === 'object' &&
|
|
22
|
-
'routes' in build &&
|
|
23
|
-
build.routes !== null &&
|
|
24
|
-
typeof build.routes === 'object'
|
|
25
|
-
);
|
|
8
|
+
return build !== null && typeof build === "object" && "routes" in build && build.routes !== null && typeof build.routes === "object";
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
/** @internal */
|
|
29
10
|
function setServerBuild(build) {
|
|
30
11
|
_serverBuild = build;
|
|
31
12
|
}
|
|
32
|
-
|
|
33
|
-
/** @internal */
|
|
34
13
|
function getMiddlewareName(routeId, index) {
|
|
35
|
-
if (!_serverBuild?.routes) return
|
|
36
|
-
|
|
14
|
+
if (!_serverBuild?.routes) return void 0;
|
|
37
15
|
const route = _serverBuild.routes[routeId];
|
|
38
|
-
if (!route?.module?.middleware) return
|
|
39
|
-
|
|
16
|
+
if (!route?.module?.middleware) return void 0;
|
|
40
17
|
const middlewareFn = route.module.middleware[index];
|
|
41
|
-
return middlewareFn?.name ||
|
|
18
|
+
return middlewareFn?.name || void 0;
|
|
42
19
|
}
|
|
43
|
-
|
|
44
|
-
/** @internal */
|
|
45
20
|
function registerServerBuildGlobal() {
|
|
46
|
-
|
|
21
|
+
core.GLOBAL_OBJ[GLOBAL_KEY] = setServerBuild;
|
|
47
22
|
}
|
|
48
23
|
|
|
49
24
|
exports.GLOBAL_KEY = GLOBAL_KEY;
|
|
@@ -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":";;;;
|
|
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;AAGG,SAAS,kBAAkB,KAAA,EAA0C;AAC1E,EAAA,OACE,KAAA,KAAU,IAAA,IACV,OAAO,KAAA,KAAU,QAAA,IACjB,QAAA,IAAY,KAAA,IACZ,KAAA,CAAM,MAAA,KAAW,IAAA,IACjB,OAAO,KAAA,CAAM,MAAA,KAAW,QAAA;AAE5B;AAGO,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;;;;;;;;"}
|
|
@@ -2,39 +2,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const core = require('@sentry/core');
|
|
4
4
|
|
|
5
|
-
const SENTRY_SERVER_INSTRUMENTATION_FLAG =
|
|
6
|
-
const SENTRY_OTEL_SPAN_CREATION_FLAG =
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Mark that the React Router instrumentation API is being used on the server.
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
5
|
+
const SENTRY_SERVER_INSTRUMENTATION_FLAG = "__sentryReactRouterServerInstrumentationUsed";
|
|
6
|
+
const SENTRY_OTEL_SPAN_CREATION_FLAG = "__sentryReactRouterOtelSpanCreationEnabled";
|
|
12
7
|
function markInstrumentationApiUsed() {
|
|
13
|
-
|
|
8
|
+
core.GLOBAL_OBJ[SENTRY_SERVER_INSTRUMENTATION_FLAG] = true;
|
|
14
9
|
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Check if React Router's instrumentation API is being used on the server.
|
|
18
|
-
* @experimental
|
|
19
|
-
*/
|
|
20
10
|
function isInstrumentationApiUsed() {
|
|
21
|
-
return !!
|
|
11
|
+
return !!core.GLOBAL_OBJ[SENTRY_SERVER_INSTRUMENTATION_FLAG];
|
|
22
12
|
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Enable OTEL data-loader span creation for React Router server.
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
13
|
function enableOtelDataLoaderSpanCreation() {
|
|
29
|
-
|
|
14
|
+
core.GLOBAL_OBJ[SENTRY_OTEL_SPAN_CREATION_FLAG] = true;
|
|
30
15
|
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Check if OTEL data-loader span creation is enabled for React Router server.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
16
|
function isOtelDataLoaderSpanCreationEnabled() {
|
|
37
|
-
return !!
|
|
17
|
+
return !!core.GLOBAL_OBJ[SENTRY_OTEL_SPAN_CREATION_FLAG];
|
|
38
18
|
}
|
|
39
19
|
|
|
40
20
|
exports.enableOtelDataLoaderSpanCreation = enableOtelDataLoaderSpanCreation;
|
|
@@ -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';\nconst SENTRY_OTEL_SPAN_CREATION_FLAG = '__sentryReactRouterOtelSpanCreationEnabled';\n\ntype GlobalObjWithFlag = typeof GLOBAL_OBJ & {\n [SENTRY_SERVER_INSTRUMENTATION_FLAG]?: boolean;\n [SENTRY_OTEL_SPAN_CREATION_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 * @experimental\n */\nexport function isInstrumentationApiUsed(): boolean {\n return !!(GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_SERVER_INSTRUMENTATION_FLAG];\n}\n\n/**\n * Enable OTEL data-loader span creation for React Router server.\n * @internal\n */\nexport function enableOtelDataLoaderSpanCreation(): void {\n (GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_OTEL_SPAN_CREATION_FLAG] = true;\n}\n\n/**\n * Check if OTEL data-loader span creation is enabled for React Router server.\n * @internal\n */\nexport function isOtelDataLoaderSpanCreationEnabled(): boolean {\n return !!(GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_OTEL_SPAN_CREATION_FLAG];\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAEA,MAAM,kCAAA,GAAqC,
|
|
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';\nconst SENTRY_OTEL_SPAN_CREATION_FLAG = '__sentryReactRouterOtelSpanCreationEnabled';\n\ntype GlobalObjWithFlag = typeof GLOBAL_OBJ & {\n [SENTRY_SERVER_INSTRUMENTATION_FLAG]?: boolean;\n [SENTRY_OTEL_SPAN_CREATION_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 * @experimental\n */\nexport function isInstrumentationApiUsed(): boolean {\n return !!(GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_SERVER_INSTRUMENTATION_FLAG];\n}\n\n/**\n * Enable OTEL data-loader span creation for React Router server.\n * @internal\n */\nexport function enableOtelDataLoaderSpanCreation(): void {\n (GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_OTEL_SPAN_CREATION_FLAG] = true;\n}\n\n/**\n * Check if OTEL data-loader span creation is enabled for React Router server.\n * @internal\n */\nexport function isOtelDataLoaderSpanCreationEnabled(): boolean {\n return !!(GLOBAL_OBJ as GlobalObjWithFlag)[SENTRY_OTEL_SPAN_CREATION_FLAG];\n}\n"],"names":["GLOBAL_OBJ"],"mappings":";;;;AAEA,MAAM,kCAAA,GAAqC,8CAAA;AAC3C,MAAM,8BAAA,GAAiC,4CAAA;AAWhC,SAAS,0BAAA,GAAmC;AACjD,EAACA,eAAA,CAAiC,kCAAkC,CAAA,GAAI,IAAA;AAC1E;AAMO,SAAS,wBAAA,GAAoC;AAClD,EAAA,OAAO,CAAC,CAAEA,eAAA,CAAiC,kCAAkC,CAAA;AAC/E;AAMO,SAAS,gCAAA,GAAyC;AACvD,EAACA,eAAA,CAAiC,8BAA8B,CAAA,GAAI,IAAA;AACtE;AAMO,SAAS,mCAAA,GAA+C;AAC7D,EAAA,OAAO,CAAC,CAAEA,eAAA,CAAiC,8BAA8B,CAAA;AAC3E;;;;;;;"}
|
|
@@ -6,99 +6,59 @@ const semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
|
6
6
|
const core = require('@sentry/core');
|
|
7
7
|
const serverGlobals = require('./serverGlobals.js');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @param originalHandle - The original handleRequest function to wrap
|
|
13
|
-
* @returns A wrapped version of the handle request function with Sentry instrumentation
|
|
14
|
-
*/
|
|
15
|
-
function wrapSentryHandleRequest(
|
|
16
|
-
originalHandle,
|
|
17
|
-
) {
|
|
18
|
-
return async function sentryInstrumentedHandleRequest(
|
|
19
|
-
request,
|
|
20
|
-
responseStatusCode,
|
|
21
|
-
responseHeaders,
|
|
22
|
-
routerContext,
|
|
23
|
-
loadContext,
|
|
24
|
-
) {
|
|
25
|
-
const parameterizedPath =
|
|
26
|
-
routerContext?.staticHandlerContext?.matches?.[routerContext.staticHandlerContext.matches.length - 1]?.route.path;
|
|
27
|
-
|
|
9
|
+
function wrapSentryHandleRequest(originalHandle) {
|
|
10
|
+
return async function sentryInstrumentedHandleRequest(request, responseStatusCode, responseHeaders, routerContext, loadContext) {
|
|
11
|
+
const parameterizedPath = routerContext?.staticHandlerContext?.matches?.[routerContext.staticHandlerContext.matches.length - 1]?.route.path;
|
|
28
12
|
const activeSpan = core.getActiveSpan();
|
|
29
|
-
const rootSpan = activeSpan ? core.getRootSpan(activeSpan) :
|
|
30
|
-
|
|
13
|
+
const rootSpan = activeSpan ? core.getRootSpan(activeSpan) : void 0;
|
|
31
14
|
if (parameterizedPath && rootSpan) {
|
|
32
|
-
|
|
33
|
-
const routeName = parameterizedPath.startsWith('/') ? parameterizedPath : `/${parameterizedPath}`;
|
|
34
|
-
|
|
35
|
-
// The express instrumentation writes on the rpcMetadata and that ends up stomping on the `http.route` attribute.
|
|
15
|
+
const routeName = parameterizedPath.startsWith("/") ? parameterizedPath : `/${parameterizedPath}`;
|
|
36
16
|
const rpcMetadata = core$1.getRPCMetadata(api.context.active());
|
|
37
|
-
|
|
38
17
|
if (rpcMetadata?.type === core$1.RPCType.HTTP) {
|
|
39
18
|
rpcMetadata.route = routeName;
|
|
40
19
|
}
|
|
41
|
-
|
|
42
20
|
const transactionName = `${request.method} ${routeName}`;
|
|
43
|
-
|
|
44
21
|
core.updateSpanName(rootSpan, transactionName);
|
|
45
22
|
core.getCurrentScope().setTransactionName(transactionName);
|
|
46
|
-
|
|
47
|
-
// Set route attributes - acts as fallback for lazy-only routes when using instrumentation API
|
|
48
|
-
// Don't override origin when instrumentation API is used (preserve instrumentation_api origin)
|
|
49
23
|
if (serverGlobals.isInstrumentationApiUsed()) {
|
|
50
24
|
rootSpan.setAttributes({
|
|
51
25
|
[semanticConventions.ATTR_HTTP_ROUTE]: routeName,
|
|
52
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
26
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route"
|
|
53
27
|
});
|
|
54
28
|
} else {
|
|
55
29
|
rootSpan.setAttributes({
|
|
56
30
|
[semanticConventions.ATTR_HTTP_ROUTE]: routeName,
|
|
57
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
58
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
31
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "route",
|
|
32
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.request_handler"
|
|
59
33
|
});
|
|
60
34
|
}
|
|
61
35
|
}
|
|
62
|
-
|
|
63
36
|
try {
|
|
64
|
-
// Type guard to call the correct overload based on loadContext type
|
|
65
37
|
if (isRouterContextProvider(loadContext)) {
|
|
66
|
-
|
|
67
|
-
return await (originalHandle )(
|
|
38
|
+
return await originalHandle(
|
|
68
39
|
request,
|
|
69
40
|
responseStatusCode,
|
|
70
41
|
responseHeaders,
|
|
71
42
|
routerContext,
|
|
72
|
-
loadContext
|
|
43
|
+
loadContext
|
|
73
44
|
);
|
|
74
45
|
} else {
|
|
75
|
-
|
|
76
|
-
return await (originalHandle )(
|
|
46
|
+
return await originalHandle(
|
|
77
47
|
request,
|
|
78
48
|
responseStatusCode,
|
|
79
49
|
responseHeaders,
|
|
80
50
|
routerContext,
|
|
81
|
-
loadContext
|
|
51
|
+
loadContext
|
|
82
52
|
);
|
|
83
53
|
}
|
|
84
54
|
} finally {
|
|
85
55
|
await core.flushIfServerless();
|
|
86
56
|
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Helper type guard to determine if the context is a RouterContextProvider.
|
|
90
|
-
*
|
|
91
|
-
* @param ctx - The context to check
|
|
92
|
-
* @returns True if the context is a RouterContextProvider
|
|
93
|
-
*/
|
|
94
57
|
function isRouterContextProvider(ctx) {
|
|
95
|
-
return typeof
|
|
58
|
+
return typeof ctx?.get === "function";
|
|
96
59
|
}
|
|
97
60
|
};
|
|
98
61
|
}
|
|
99
|
-
|
|
100
|
-
// todo(v11): remove this
|
|
101
|
-
/** @deprecated Use `wrapSentryHandleRequest` instead. */
|
|
102
62
|
const sentryHandleRequest = wrapSentryHandleRequest;
|
|
103
63
|
|
|
104
64
|
exports.sentryHandleRequest = sentryHandleRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapSentryHandleRequest.js","sources":["../../../src/server/wrapSentryHandleRequest.ts"],"sourcesContent":["import { context } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport {\n flushIfServerless,\n getActiveSpan,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n updateSpanName,\n} from '@sentry/core';\nimport type { AppLoadContext, EntryContext, RouterContextProvider } from 'react-router';\nimport { isInstrumentationApiUsed } from './serverGlobals';\n\ntype OriginalHandleRequestWithoutMiddleware = (\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: AppLoadContext,\n) => Promise<unknown>;\n\ntype OriginalHandleRequestWithMiddleware = (\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: RouterContextProvider,\n) => Promise<unknown>;\n\n/**\n * Wraps the original handleRequest function to add Sentry instrumentation.\n *\n * @param originalHandle - The original handleRequest function to wrap\n * @returns A wrapped version of the handle request function with Sentry instrumentation\n */\nexport function wrapSentryHandleRequest(\n originalHandle: OriginalHandleRequestWithoutMiddleware,\n): OriginalHandleRequestWithoutMiddleware;\n/**\n * Wraps the original handleRequest function to add Sentry instrumentation.\n *\n * @param originalHandle - The original handleRequest function to wrap\n * @returns A wrapped version of the handle request function with Sentry instrumentation\n */\nexport function wrapSentryHandleRequest(\n originalHandle: OriginalHandleRequestWithMiddleware,\n): OriginalHandleRequestWithMiddleware;\n/**\n * Wraps the original handleRequest function to add Sentry instrumentation.\n *\n * @param originalHandle - The original handleRequest function to wrap\n * @returns A wrapped version of the handle request function with Sentry instrumentation\n */\nexport function wrapSentryHandleRequest(\n originalHandle: OriginalHandleRequestWithoutMiddleware | OriginalHandleRequestWithMiddleware,\n): OriginalHandleRequestWithoutMiddleware | OriginalHandleRequestWithMiddleware {\n return async function sentryInstrumentedHandleRequest(\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: AppLoadContext | RouterContextProvider,\n ) {\n const parameterizedPath =\n routerContext?.staticHandlerContext?.matches?.[routerContext.staticHandlerContext.matches.length - 1]?.route.path;\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n\n if (parameterizedPath && rootSpan) {\n // Normalize route name - avoid \"//\" for root routes\n const routeName = parameterizedPath.startsWith('/') ? parameterizedPath : `/${parameterizedPath}`;\n\n // The express instrumentation writes on the rpcMetadata and that ends up stomping on the `http.route` attribute.\n const rpcMetadata = getRPCMetadata(context.active());\n\n if (rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = routeName;\n }\n\n const transactionName = `${request.method} ${routeName}`;\n\n updateSpanName(rootSpan, transactionName);\n getCurrentScope().setTransactionName(transactionName);\n\n // Set route attributes - acts as fallback for lazy-only routes when using instrumentation API\n // Don't override origin when instrumentation API is used (preserve instrumentation_api origin)\n if (isInstrumentationApiUsed()) {\n rootSpan.setAttributes({\n [ATTR_HTTP_ROUTE]: routeName,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n });\n } else {\n rootSpan.setAttributes({\n [ATTR_HTTP_ROUTE]: routeName,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.request_handler',\n });\n }\n }\n\n try {\n // Type guard to call the correct overload based on loadContext type\n if (isRouterContextProvider(loadContext)) {\n // loadContext is RouterContextProvider\n return await (originalHandle as OriginalHandleRequestWithMiddleware)(\n request,\n responseStatusCode,\n responseHeaders,\n routerContext,\n loadContext,\n );\n } else {\n // loadContext is AppLoadContext\n return await (originalHandle as OriginalHandleRequestWithoutMiddleware)(\n request,\n responseStatusCode,\n responseHeaders,\n routerContext,\n loadContext,\n );\n }\n } finally {\n await flushIfServerless();\n }\n\n /**\n * Helper type guard to determine if the context is a RouterContextProvider.\n *\n * @param ctx - The context to check\n * @returns True if the context is a RouterContextProvider\n */\n function isRouterContextProvider(ctx: AppLoadContext | RouterContextProvider): ctx is RouterContextProvider {\n return typeof (ctx as RouterContextProvider)?.get === 'function';\n }\n };\n}\n\n// todo(v11): remove this\n/** @deprecated Use `wrapSentryHandleRequest` instead. */\nexport const sentryHandleRequest = wrapSentryHandleRequest;\n"],"names":["getActiveSpan","getRootSpan","getRPCMetadata","context","RPCType","updateSpanName","getCurrentScope","isInstrumentationApiUsed","ATTR_HTTP_ROUTE","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","flushIfServerless"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"wrapSentryHandleRequest.js","sources":["../../../src/server/wrapSentryHandleRequest.ts"],"sourcesContent":["import { context } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport {\n flushIfServerless,\n getActiveSpan,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n updateSpanName,\n} from '@sentry/core';\nimport type { AppLoadContext, EntryContext, RouterContextProvider } from 'react-router';\nimport { isInstrumentationApiUsed } from './serverGlobals';\n\ntype OriginalHandleRequestWithoutMiddleware = (\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: AppLoadContext,\n) => Promise<unknown>;\n\ntype OriginalHandleRequestWithMiddleware = (\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: RouterContextProvider,\n) => Promise<unknown>;\n\n/**\n * Wraps the original handleRequest function to add Sentry instrumentation.\n *\n * @param originalHandle - The original handleRequest function to wrap\n * @returns A wrapped version of the handle request function with Sentry instrumentation\n */\nexport function wrapSentryHandleRequest(\n originalHandle: OriginalHandleRequestWithoutMiddleware,\n): OriginalHandleRequestWithoutMiddleware;\n/**\n * Wraps the original handleRequest function to add Sentry instrumentation.\n *\n * @param originalHandle - The original handleRequest function to wrap\n * @returns A wrapped version of the handle request function with Sentry instrumentation\n */\nexport function wrapSentryHandleRequest(\n originalHandle: OriginalHandleRequestWithMiddleware,\n): OriginalHandleRequestWithMiddleware;\n/**\n * Wraps the original handleRequest function to add Sentry instrumentation.\n *\n * @param originalHandle - The original handleRequest function to wrap\n * @returns A wrapped version of the handle request function with Sentry instrumentation\n */\nexport function wrapSentryHandleRequest(\n originalHandle: OriginalHandleRequestWithoutMiddleware | OriginalHandleRequestWithMiddleware,\n): OriginalHandleRequestWithoutMiddleware | OriginalHandleRequestWithMiddleware {\n return async function sentryInstrumentedHandleRequest(\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: AppLoadContext | RouterContextProvider,\n ) {\n const parameterizedPath =\n routerContext?.staticHandlerContext?.matches?.[routerContext.staticHandlerContext.matches.length - 1]?.route.path;\n\n const activeSpan = getActiveSpan();\n const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;\n\n if (parameterizedPath && rootSpan) {\n // Normalize route name - avoid \"//\" for root routes\n const routeName = parameterizedPath.startsWith('/') ? parameterizedPath : `/${parameterizedPath}`;\n\n // The express instrumentation writes on the rpcMetadata and that ends up stomping on the `http.route` attribute.\n const rpcMetadata = getRPCMetadata(context.active());\n\n if (rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = routeName;\n }\n\n const transactionName = `${request.method} ${routeName}`;\n\n updateSpanName(rootSpan, transactionName);\n getCurrentScope().setTransactionName(transactionName);\n\n // Set route attributes - acts as fallback for lazy-only routes when using instrumentation API\n // Don't override origin when instrumentation API is used (preserve instrumentation_api origin)\n if (isInstrumentationApiUsed()) {\n rootSpan.setAttributes({\n [ATTR_HTTP_ROUTE]: routeName,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n });\n } else {\n rootSpan.setAttributes({\n [ATTR_HTTP_ROUTE]: routeName,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.request_handler',\n });\n }\n }\n\n try {\n // Type guard to call the correct overload based on loadContext type\n if (isRouterContextProvider(loadContext)) {\n // loadContext is RouterContextProvider\n return await (originalHandle as OriginalHandleRequestWithMiddleware)(\n request,\n responseStatusCode,\n responseHeaders,\n routerContext,\n loadContext,\n );\n } else {\n // loadContext is AppLoadContext\n return await (originalHandle as OriginalHandleRequestWithoutMiddleware)(\n request,\n responseStatusCode,\n responseHeaders,\n routerContext,\n loadContext,\n );\n }\n } finally {\n await flushIfServerless();\n }\n\n /**\n * Helper type guard to determine if the context is a RouterContextProvider.\n *\n * @param ctx - The context to check\n * @returns True if the context is a RouterContextProvider\n */\n function isRouterContextProvider(ctx: AppLoadContext | RouterContextProvider): ctx is RouterContextProvider {\n return typeof (ctx as RouterContextProvider)?.get === 'function';\n }\n };\n}\n\n// todo(v11): remove this\n/** @deprecated Use `wrapSentryHandleRequest` instead. */\nexport const sentryHandleRequest = wrapSentryHandleRequest;\n"],"names":["getActiveSpan","getRootSpan","getRPCMetadata","context","RPCType","updateSpanName","getCurrentScope","isInstrumentationApiUsed","ATTR_HTTP_ROUTE","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","flushIfServerless"],"mappings":";;;;;;;;AAuDO,SAAS,wBACd,cAAA,EAC8E;AAC9E,EAAA,OAAO,eAAe,+BAAA,CACpB,OAAA,EACA,kBAAA,EACA,eAAA,EACA,eACA,WAAA,EACA;AACA,IAAA,MAAM,iBAAA,GACJ,aAAA,EAAe,oBAAA,EAAsB,OAAA,GAAU,aAAA,CAAc,qBAAqB,OAAA,CAAQ,MAAA,GAAS,CAAC,CAAA,EAAG,KAAA,CAAM,IAAA;AAE/G,IAAA,MAAM,aAAaA,kBAAA,EAAc;AACjC,IAAA,MAAM,QAAA,GAAW,UAAA,GAAaC,gBAAA,CAAY,UAAU,CAAA,GAAI,MAAA;AAExD,IAAA,IAAI,qBAAqB,QAAA,EAAU;AAEjC,MAAA,MAAM,YAAY,iBAAA,CAAkB,UAAA,CAAW,GAAG,CAAA,GAAI,iBAAA,GAAoB,IAAI,iBAAiB,CAAA,CAAA;AAG/F,MAAA,MAAM,WAAA,GAAcC,qBAAA,CAAeC,WAAA,CAAQ,MAAA,EAAQ,CAAA;AAEnD,MAAA,IAAI,WAAA,EAAa,IAAA,KAASC,cAAA,CAAQ,IAAA,EAAM;AACtC,QAAA,WAAA,CAAY,KAAA,GAAQ,SAAA;AAAA,MACtB;AAEA,MAAA,MAAM,eAAA,GAAkB,CAAA,EAAG,OAAA,CAAQ,MAAM,IAAI,SAAS,CAAA,CAAA;AAEtD,MAAAC,mBAAA,CAAe,UAAU,eAAe,CAAA;AACxC,MAAAC,oBAAA,EAAgB,CAAE,mBAAmB,eAAe,CAAA;AAIpD,MAAA,IAAIC,wCAAyB,EAAG;AAC9B,QAAA,QAAA,CAAS,aAAA,CAAc;AAAA,UACrB,CAACC,mCAAe,GAAG,SAAA;AAAA,UACnB,CAACC,qCAAgC,GAAG;AAAA,SACrC,CAAA;AAAA,MACH,CAAA,MAAO;AACL,QAAA,QAAA,CAAS,aAAA,CAAc;AAAA,UACrB,CAACD,mCAAe,GAAG,SAAA;AAAA,UACnB,CAACC,qCAAgC,GAAG,OAAA;AAAA,UACpC,CAACC,qCAAgC,GAAG;AAAA,SACrC,CAAA;AAAA,MACH;AAAA,IACF;AAEA,IAAA,IAAI;AAEF,MAAA,IAAI,uBAAA,CAAwB,WAAW,CAAA,EAAG;AAExC,QAAA,OAAO,MAAO,cAAA;AAAA,UACZ,OAAA;AAAA,UACA,kBAAA;AAAA,UACA,eAAA;AAAA,UACA,aAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF,CAAA,MAAO;AAEL,QAAA,OAAO,MAAO,cAAA;AAAA,UACZ,OAAA;AAAA,UACA,kBAAA;AAAA,UACA,eAAA;AAAA,UACA,aAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF;AAAA,IACF,CAAA,SAAE;AACA,MAAA,MAAMC,sBAAA,EAAkB;AAAA,IAC1B;AAQA,IAAA,SAAS,wBAAwB,GAAA,EAA2E;AAC1G,MAAA,OAAO,OAAQ,KAA+B,GAAA,KAAQ,UAAA;AAAA,IACxD;AAAA,EACF,CAAA;AACF;AAIO,MAAM,mBAAA,GAAsB;;;;;"}
|
|
@@ -5,78 +5,46 @@ const core = require('@sentry/core');
|
|
|
5
5
|
const debugBuild = require('../common/debug-build.js');
|
|
6
6
|
const serverGlobals = require('./serverGlobals.js');
|
|
7
7
|
|
|
8
|
-
// Track if we've already warned about duplicate instrumentation
|
|
9
8
|
let hasWarnedAboutDuplicateActionInstrumentation = false;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* Wraps a React Router server action function with Sentry performance monitoring.
|
|
13
|
-
* @param options - Optional span configuration options including name, operation, description and attributes
|
|
14
|
-
* @param actionFn - The server action function to wrap
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* // Wrap an action function with custom span options
|
|
19
|
-
* export const action = wrapServerAction(
|
|
20
|
-
* {
|
|
21
|
-
* name: 'Submit Form Data',
|
|
22
|
-
* description: 'Processes form submission data',
|
|
23
|
-
* },
|
|
24
|
-
* async ({ request }) => {
|
|
25
|
-
* // ... your action logic
|
|
26
|
-
* }
|
|
27
|
-
* );
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function wrapServerAction(
|
|
31
|
-
options = {},
|
|
32
|
-
actionFn,
|
|
33
|
-
) {
|
|
34
|
-
return async function (args) {
|
|
35
|
-
// Skip instrumentation if instrumentation API is already handling it
|
|
9
|
+
function wrapServerAction(options = {}, actionFn) {
|
|
10
|
+
return async function(args) {
|
|
36
11
|
if (serverGlobals.isInstrumentationApiUsed()) {
|
|
37
12
|
if (debugBuild.DEBUG_BUILD && !hasWarnedAboutDuplicateActionInstrumentation) {
|
|
38
13
|
hasWarnedAboutDuplicateActionInstrumentation = true;
|
|
39
14
|
core.debug.warn(
|
|
40
|
-
|
|
41
|
-
'The action is already instrumented automatically. You can safely remove wrapServerAction.',
|
|
15
|
+
"wrapServerAction is redundant when using the instrumentation API. The action is already instrumented automatically. You can safely remove wrapServerAction."
|
|
42
16
|
);
|
|
43
17
|
}
|
|
44
18
|
return actionFn(args);
|
|
45
19
|
}
|
|
46
|
-
|
|
47
|
-
const name = options.name || 'Executing Server Action';
|
|
20
|
+
const name = options.name || "Executing Server Action";
|
|
48
21
|
const active = core.getActiveSpan();
|
|
49
22
|
if (active) {
|
|
50
23
|
const root = core.getRootSpan(active);
|
|
51
24
|
const spanData = core.spanToJSON(root);
|
|
52
|
-
if (spanData.origin ===
|
|
53
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
25
|
+
if (spanData.origin === "auto.http.otel.http") {
|
|
54
26
|
const target = spanData.data[semanticConventions.SEMATTRS_HTTP_TARGET];
|
|
55
|
-
|
|
56
27
|
if (target) {
|
|
57
|
-
// We cannot rely on the regular span name inferral here, as the express instrumentation sets `*` as the route
|
|
58
|
-
// So we force this to be a more sensible name here
|
|
59
28
|
core.updateSpanName(root, `${args.request.method} ${target}`);
|
|
60
29
|
root.setAttributes({
|
|
61
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
62
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
30
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
|
|
31
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.action"
|
|
63
32
|
});
|
|
64
33
|
}
|
|
65
34
|
}
|
|
66
35
|
}
|
|
67
|
-
|
|
68
36
|
try {
|
|
69
37
|
return await core.startSpan(
|
|
70
38
|
{
|
|
71
39
|
name,
|
|
72
40
|
...options,
|
|
73
41
|
attributes: {
|
|
74
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
75
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]:
|
|
76
|
-
...options.attributes
|
|
77
|
-
}
|
|
42
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.action",
|
|
43
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "function.react_router.action",
|
|
44
|
+
...options.attributes
|
|
45
|
+
}
|
|
78
46
|
},
|
|
79
|
-
() => actionFn(args)
|
|
47
|
+
() => actionFn(args)
|
|
80
48
|
);
|
|
81
49
|
} finally {
|
|
82
50
|
await core.flushIfServerless();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapServerAction.js","sources":["../../../src/server/wrapServerAction.ts"],"sourcesContent":["import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport {\n debug,\n flushIfServerless,\n getActiveSpan,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport type { ActionFunctionArgs } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isInstrumentationApiUsed } from './serverGlobals';\n\ntype SpanOptions = {\n name?: string;\n attributes?: SpanAttributes;\n};\n\n// Track if we've already warned about duplicate instrumentation\nlet hasWarnedAboutDuplicateActionInstrumentation = false;\n\n/**\n * Wraps a React Router server action function with Sentry performance monitoring.\n * @param options - Optional span configuration options including name, operation, description and attributes\n * @param actionFn - The server action function to wrap\n *\n * @example\n * ```ts\n * // Wrap an action function with custom span options\n * export const action = wrapServerAction(\n * {\n * name: 'Submit Form Data',\n * description: 'Processes form submission data',\n * },\n * async ({ request }) => {\n * // ... your action logic\n * }\n * );\n * ```\n */\nexport function wrapServerAction<T>(\n options: SpanOptions = {},\n actionFn: (args: ActionFunctionArgs) => Promise<T>,\n): (args: ActionFunctionArgs) => Promise<T> {\n return async function (args: ActionFunctionArgs): Promise<T> {\n // Skip instrumentation if instrumentation API is already handling it\n if (isInstrumentationApiUsed()) {\n if (DEBUG_BUILD && !hasWarnedAboutDuplicateActionInstrumentation) {\n hasWarnedAboutDuplicateActionInstrumentation = true;\n debug.warn(\n 'wrapServerAction is redundant when using the instrumentation API. ' +\n 'The action is already instrumented automatically. You can safely remove wrapServerAction.',\n );\n }\n return actionFn(args);\n }\n\n const name = options.name || 'Executing Server Action';\n const active = getActiveSpan();\n if (active) {\n const root = getRootSpan(active);\n const spanData = spanToJSON(root);\n if (spanData.origin === 'auto.http.otel.http') {\n // eslint-disable-next-line deprecation/deprecation\n const target = spanData.data[SEMATTRS_HTTP_TARGET];\n\n if (target) {\n // We cannot rely on the regular span name inferral here, as the express instrumentation sets `*` as the route\n // So we force this to be a more sensible name here\n updateSpanName(root, `${args.request.method} ${target}`);\n root.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.action',\n });\n }\n }\n }\n\n try {\n return await startSpan(\n {\n name,\n ...options,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.action',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.action',\n ...options.attributes,\n },\n },\n () => actionFn(args),\n );\n } finally {\n await flushIfServerless();\n }\n };\n}\n"],"names":["isInstrumentationApiUsed","DEBUG_BUILD","debug","getActiveSpan","getRootSpan","spanToJSON","SEMATTRS_HTTP_TARGET","updateSpanName","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","flushIfServerless"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"wrapServerAction.js","sources":["../../../src/server/wrapServerAction.ts"],"sourcesContent":["import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport {\n debug,\n flushIfServerless,\n getActiveSpan,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport type { ActionFunctionArgs } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isInstrumentationApiUsed } from './serverGlobals';\n\ntype SpanOptions = {\n name?: string;\n attributes?: SpanAttributes;\n};\n\n// Track if we've already warned about duplicate instrumentation\nlet hasWarnedAboutDuplicateActionInstrumentation = false;\n\n/**\n * Wraps a React Router server action function with Sentry performance monitoring.\n * @param options - Optional span configuration options including name, operation, description and attributes\n * @param actionFn - The server action function to wrap\n *\n * @example\n * ```ts\n * // Wrap an action function with custom span options\n * export const action = wrapServerAction(\n * {\n * name: 'Submit Form Data',\n * description: 'Processes form submission data',\n * },\n * async ({ request }) => {\n * // ... your action logic\n * }\n * );\n * ```\n */\nexport function wrapServerAction<T>(\n options: SpanOptions = {},\n actionFn: (args: ActionFunctionArgs) => Promise<T>,\n): (args: ActionFunctionArgs) => Promise<T> {\n return async function (args: ActionFunctionArgs): Promise<T> {\n // Skip instrumentation if instrumentation API is already handling it\n if (isInstrumentationApiUsed()) {\n if (DEBUG_BUILD && !hasWarnedAboutDuplicateActionInstrumentation) {\n hasWarnedAboutDuplicateActionInstrumentation = true;\n debug.warn(\n 'wrapServerAction is redundant when using the instrumentation API. ' +\n 'The action is already instrumented automatically. You can safely remove wrapServerAction.',\n );\n }\n return actionFn(args);\n }\n\n const name = options.name || 'Executing Server Action';\n const active = getActiveSpan();\n if (active) {\n const root = getRootSpan(active);\n const spanData = spanToJSON(root);\n if (spanData.origin === 'auto.http.otel.http') {\n // eslint-disable-next-line deprecation/deprecation\n const target = spanData.data[SEMATTRS_HTTP_TARGET];\n\n if (target) {\n // We cannot rely on the regular span name inferral here, as the express instrumentation sets `*` as the route\n // So we force this to be a more sensible name here\n updateSpanName(root, `${args.request.method} ${target}`);\n root.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.action',\n });\n }\n }\n }\n\n try {\n return await startSpan(\n {\n name,\n ...options,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.action',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.action',\n ...options.attributes,\n },\n },\n () => actionFn(args),\n );\n } finally {\n await flushIfServerless();\n }\n };\n}\n"],"names":["isInstrumentationApiUsed","DEBUG_BUILD","debug","getActiveSpan","getRootSpan","spanToJSON","SEMATTRS_HTTP_TARGET","updateSpanName","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","flushIfServerless"],"mappings":";;;;;;;AAwBA,IAAI,4CAAA,GAA+C,KAAA;AAqB5C,SAAS,gBAAA,CACd,OAAA,GAAuB,EAAC,EACxB,QAAA,EAC0C;AAC1C,EAAA,OAAO,eAAgB,IAAA,EAAsC;AAE3D,IAAA,IAAIA,wCAAyB,EAAG;AAC9B,MAAA,IAAIC,sBAAA,IAAe,CAAC,4CAAA,EAA8C;AAChE,QAAA,4CAAA,GAA+C,IAAA;AAC/C,QAAAC,UAAA,CAAM,IAAA;AAAA,UACJ;AAAA,SAEF;AAAA,MACF;AACA,MAAA,OAAO,SAAS,IAAI,CAAA;AAAA,IACtB;AAEA,IAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,yBAAA;AAC7B,IAAA,MAAM,SAASC,kBAAA,EAAc;AAC7B,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,MAAM,IAAA,GAAOC,iBAAY,MAAM,CAAA;AAC/B,MAAA,MAAM,QAAA,GAAWC,gBAAW,IAAI,CAAA;AAChC,MAAA,IAAI,QAAA,CAAS,WAAW,qBAAA,EAAuB;AAE7C,QAAA,MAAM,MAAA,GAAS,QAAA,CAAS,IAAA,CAAKC,wCAAoB,CAAA;AAEjD,QAAA,IAAI,MAAA,EAAQ;AAGV,UAAAC,mBAAA,CAAe,MAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,MAAM,CAAA,CAAA,EAAI,MAAM,CAAA,CAAE,CAAA;AACvD,UAAA,IAAA,CAAK,aAAA,CAAc;AAAA,YACjB,CAACC,qCAAgC,GAAG,KAAA;AAAA,YACpC,CAACC,qCAAgC,GAAG;AAAA,WACrC,CAAA;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,IAAA,IAAI;AACF,MAAA,OAAO,MAAMC,cAAA;AAAA,QACX;AAAA,UACE,IAAA;AAAA,UACA,GAAG,OAAA;AAAA,UACH,UAAA,EAAY;AAAA,YACV,CAACD,qCAAgC,GAAG,+BAAA;AAAA,YACpC,CAACE,iCAA4B,GAAG,8BAAA;AAAA,YAChC,GAAG,OAAA,CAAQ;AAAA;AACb,SACF;AAAA,QACA,MAAM,SAAS,IAAI;AAAA,OACrB;AAAA,IACF,CAAA,SAAE;AACA,MAAA,MAAMC,sBAAA,EAAkB;AAAA,IAC1B;AAAA,EACF,CAAA;AACF;;;;"}
|
|
@@ -5,62 +5,30 @@ const core = require('@sentry/core');
|
|
|
5
5
|
const debugBuild = require('../common/debug-build.js');
|
|
6
6
|
const serverGlobals = require('./serverGlobals.js');
|
|
7
7
|
|
|
8
|
-
// Track if we've already warned about duplicate instrumentation
|
|
9
8
|
let hasWarnedAboutDuplicateLoaderInstrumentation = false;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* Wraps a React Router server loader function with Sentry performance monitoring.
|
|
13
|
-
* @param options - Optional span configuration options including name, operation, description and attributes
|
|
14
|
-
* @param loaderFn - The server loader function to wrap
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* // Wrap a loader function with custom span options
|
|
19
|
-
* export const loader = wrapServerLoader(
|
|
20
|
-
* {
|
|
21
|
-
* name: 'Load Some Data',
|
|
22
|
-
* description: 'Loads some data from the db',
|
|
23
|
-
* },
|
|
24
|
-
* async ({ params }) => {
|
|
25
|
-
* // ... your loader logic
|
|
26
|
-
* }
|
|
27
|
-
* );
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function wrapServerLoader(
|
|
31
|
-
options = {},
|
|
32
|
-
loaderFn,
|
|
33
|
-
) {
|
|
34
|
-
return async function (args) {
|
|
35
|
-
// Skip instrumentation if instrumentation API is already handling it
|
|
9
|
+
function wrapServerLoader(options = {}, loaderFn) {
|
|
10
|
+
return async function(args) {
|
|
36
11
|
if (serverGlobals.isInstrumentationApiUsed()) {
|
|
37
12
|
if (debugBuild.DEBUG_BUILD && !hasWarnedAboutDuplicateLoaderInstrumentation) {
|
|
38
13
|
hasWarnedAboutDuplicateLoaderInstrumentation = true;
|
|
39
14
|
core.debug.warn(
|
|
40
|
-
|
|
41
|
-
'The loader is already instrumented automatically. You can safely remove wrapServerLoader.',
|
|
15
|
+
"wrapServerLoader is redundant when using the instrumentation API. The loader is already instrumented automatically. You can safely remove wrapServerLoader."
|
|
42
16
|
);
|
|
43
17
|
}
|
|
44
18
|
return loaderFn(args);
|
|
45
19
|
}
|
|
46
|
-
|
|
47
|
-
const name = options.name || 'Executing Server Loader';
|
|
20
|
+
const name = options.name || "Executing Server Loader";
|
|
48
21
|
const active = core.getActiveSpan();
|
|
49
|
-
|
|
50
22
|
if (active) {
|
|
51
23
|
const root = core.getRootSpan(active);
|
|
52
24
|
const spanData = core.spanToJSON(root);
|
|
53
|
-
if (spanData.origin ===
|
|
54
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
25
|
+
if (spanData.origin === "auto.http.otel.http") {
|
|
55
26
|
const target = spanData.data[semanticConventions.SEMATTRS_HTTP_TARGET];
|
|
56
|
-
|
|
57
27
|
if (target) {
|
|
58
|
-
// We cannot rely on the regular span name inferral here, as the express instrumentation sets `*` as the route
|
|
59
|
-
// So we force this to be a more sensible name here
|
|
60
28
|
core.updateSpanName(root, `${args.request.method} ${target}`);
|
|
61
29
|
root.setAttributes({
|
|
62
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]:
|
|
63
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
30
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: "url",
|
|
31
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.loader"
|
|
64
32
|
});
|
|
65
33
|
}
|
|
66
34
|
}
|
|
@@ -71,12 +39,12 @@ function wrapServerLoader(
|
|
|
71
39
|
name,
|
|
72
40
|
...options,
|
|
73
41
|
attributes: {
|
|
74
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
75
|
-
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]:
|
|
76
|
-
...options.attributes
|
|
77
|
-
}
|
|
42
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.http.react_router.loader",
|
|
43
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "function.react_router.loader",
|
|
44
|
+
...options.attributes
|
|
45
|
+
}
|
|
78
46
|
},
|
|
79
|
-
() => loaderFn(args)
|
|
47
|
+
() => loaderFn(args)
|
|
80
48
|
);
|
|
81
49
|
} finally {
|
|
82
50
|
await core.flushIfServerless();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapServerLoader.js","sources":["../../../src/server/wrapServerLoader.ts"],"sourcesContent":["import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport {\n debug,\n flushIfServerless,\n getActiveSpan,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport type { LoaderFunctionArgs } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isInstrumentationApiUsed } from './serverGlobals';\n\ntype SpanOptions = {\n name?: string;\n attributes?: SpanAttributes;\n};\n\n// Track if we've already warned about duplicate instrumentation\nlet hasWarnedAboutDuplicateLoaderInstrumentation = false;\n\n/**\n * Wraps a React Router server loader function with Sentry performance monitoring.\n * @param options - Optional span configuration options including name, operation, description and attributes\n * @param loaderFn - The server loader function to wrap\n *\n * @example\n * ```ts\n * // Wrap a loader function with custom span options\n * export const loader = wrapServerLoader(\n * {\n * name: 'Load Some Data',\n * description: 'Loads some data from the db',\n * },\n * async ({ params }) => {\n * // ... your loader logic\n * }\n * );\n * ```\n */\nexport function wrapServerLoader<T>(\n options: SpanOptions = {},\n loaderFn: (args: LoaderFunctionArgs) => Promise<T>,\n): (args: LoaderFunctionArgs) => Promise<T> {\n return async function (args: LoaderFunctionArgs): Promise<T> {\n // Skip instrumentation if instrumentation API is already handling it\n if (isInstrumentationApiUsed()) {\n if (DEBUG_BUILD && !hasWarnedAboutDuplicateLoaderInstrumentation) {\n hasWarnedAboutDuplicateLoaderInstrumentation = true;\n debug.warn(\n 'wrapServerLoader is redundant when using the instrumentation API. ' +\n 'The loader is already instrumented automatically. You can safely remove wrapServerLoader.',\n );\n }\n return loaderFn(args);\n }\n\n const name = options.name || 'Executing Server Loader';\n const active = getActiveSpan();\n\n if (active) {\n const root = getRootSpan(active);\n const spanData = spanToJSON(root);\n if (spanData.origin === 'auto.http.otel.http') {\n // eslint-disable-next-line deprecation/deprecation\n const target = spanData.data[SEMATTRS_HTTP_TARGET];\n\n if (target) {\n // We cannot rely on the regular span name inferral here, as the express instrumentation sets `*` as the route\n // So we force this to be a more sensible name here\n updateSpanName(root, `${args.request.method} ${target}`);\n root.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.loader',\n });\n }\n }\n }\n try {\n return await startSpan(\n {\n name,\n ...options,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.loader',\n ...options.attributes,\n },\n },\n () => loaderFn(args),\n );\n } finally {\n await flushIfServerless();\n }\n };\n}\n"],"names":["isInstrumentationApiUsed","DEBUG_BUILD","debug","getActiveSpan","getRootSpan","spanToJSON","SEMATTRS_HTTP_TARGET","updateSpanName","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","flushIfServerless"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"wrapServerLoader.js","sources":["../../../src/server/wrapServerLoader.ts"],"sourcesContent":["import { SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';\nimport type { SpanAttributes } from '@sentry/core';\nimport {\n debug,\n flushIfServerless,\n getActiveSpan,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n startSpan,\n updateSpanName,\n} from '@sentry/core';\nimport type { LoaderFunctionArgs } from 'react-router';\nimport { DEBUG_BUILD } from '../common/debug-build';\nimport { isInstrumentationApiUsed } from './serverGlobals';\n\ntype SpanOptions = {\n name?: string;\n attributes?: SpanAttributes;\n};\n\n// Track if we've already warned about duplicate instrumentation\nlet hasWarnedAboutDuplicateLoaderInstrumentation = false;\n\n/**\n * Wraps a React Router server loader function with Sentry performance monitoring.\n * @param options - Optional span configuration options including name, operation, description and attributes\n * @param loaderFn - The server loader function to wrap\n *\n * @example\n * ```ts\n * // Wrap a loader function with custom span options\n * export const loader = wrapServerLoader(\n * {\n * name: 'Load Some Data',\n * description: 'Loads some data from the db',\n * },\n * async ({ params }) => {\n * // ... your loader logic\n * }\n * );\n * ```\n */\nexport function wrapServerLoader<T>(\n options: SpanOptions = {},\n loaderFn: (args: LoaderFunctionArgs) => Promise<T>,\n): (args: LoaderFunctionArgs) => Promise<T> {\n return async function (args: LoaderFunctionArgs): Promise<T> {\n // Skip instrumentation if instrumentation API is already handling it\n if (isInstrumentationApiUsed()) {\n if (DEBUG_BUILD && !hasWarnedAboutDuplicateLoaderInstrumentation) {\n hasWarnedAboutDuplicateLoaderInstrumentation = true;\n debug.warn(\n 'wrapServerLoader is redundant when using the instrumentation API. ' +\n 'The loader is already instrumented automatically. You can safely remove wrapServerLoader.',\n );\n }\n return loaderFn(args);\n }\n\n const name = options.name || 'Executing Server Loader';\n const active = getActiveSpan();\n\n if (active) {\n const root = getRootSpan(active);\n const spanData = spanToJSON(root);\n if (spanData.origin === 'auto.http.otel.http') {\n // eslint-disable-next-line deprecation/deprecation\n const target = spanData.data[SEMATTRS_HTTP_TARGET];\n\n if (target) {\n // We cannot rely on the regular span name inferral here, as the express instrumentation sets `*` as the route\n // So we force this to be a more sensible name here\n updateSpanName(root, `${args.request.method} ${target}`);\n root.setAttributes({\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.loader',\n });\n }\n }\n }\n try {\n return await startSpan(\n {\n name,\n ...options,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.react_router.loader',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'function.react_router.loader',\n ...options.attributes,\n },\n },\n () => loaderFn(args),\n );\n } finally {\n await flushIfServerless();\n }\n };\n}\n"],"names":["isInstrumentationApiUsed","DEBUG_BUILD","debug","getActiveSpan","getRootSpan","spanToJSON","SEMATTRS_HTTP_TARGET","updateSpanName","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","startSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","flushIfServerless"],"mappings":";;;;;;;AAwBA,IAAI,4CAAA,GAA+C,KAAA;AAqB5C,SAAS,gBAAA,CACd,OAAA,GAAuB,EAAC,EACxB,QAAA,EAC0C;AAC1C,EAAA,OAAO,eAAgB,IAAA,EAAsC;AAE3D,IAAA,IAAIA,wCAAyB,EAAG;AAC9B,MAAA,IAAIC,sBAAA,IAAe,CAAC,4CAAA,EAA8C;AAChE,QAAA,4CAAA,GAA+C,IAAA;AAC/C,QAAAC,UAAA,CAAM,IAAA;AAAA,UACJ;AAAA,SAEF;AAAA,MACF;AACA,MAAA,OAAO,SAAS,IAAI,CAAA;AAAA,IACtB;AAEA,IAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,yBAAA;AAC7B,IAAA,MAAM,SAASC,kBAAA,EAAc;AAE7B,IAAA,IAAI,MAAA,EAAQ;AACV,MAAA,MAAM,IAAA,GAAOC,iBAAY,MAAM,CAAA;AAC/B,MAAA,MAAM,QAAA,GAAWC,gBAAW,IAAI,CAAA;AAChC,MAAA,IAAI,QAAA,CAAS,WAAW,qBAAA,EAAuB;AAE7C,QAAA,MAAM,MAAA,GAAS,QAAA,CAAS,IAAA,CAAKC,wCAAoB,CAAA;AAEjD,QAAA,IAAI,MAAA,EAAQ;AAGV,UAAAC,mBAAA,CAAe,MAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,MAAM,CAAA,CAAA,EAAI,MAAM,CAAA,CAAE,CAAA;AACvD,UAAA,IAAA,CAAK,aAAA,CAAc;AAAA,YACjB,CAACC,qCAAgC,GAAG,KAAA;AAAA,YACpC,CAACC,qCAAgC,GAAG;AAAA,WACrC,CAAA;AAAA,QACH;AAAA,MACF;AAAA,IACF;AACA,IAAA,IAAI;AACF,MAAA,OAAO,MAAMC,cAAA;AAAA,QACX;AAAA,UACE,IAAA;AAAA,UACA,GAAG,OAAA;AAAA,UACH,UAAA,EAAY;AAAA,YACV,CAACD,qCAAgC,GAAG,+BAAA;AAAA,YACpC,CAACE,iCAA4B,GAAG,8BAAA;AAAA,YAChC,GAAG,OAAA,CAAQ;AAAA;AACb,SACF;AAAA,QACA,MAAM,SAAS,IAAI;AAAA,OACrB;AAAA,IACF,CAAA,SAAE;AACA,MAAA,MAAMC,sBAAA,EAAkB;AAAA,IAC1B;AAAA,EACF,CAAA;AACF;;;;"}
|