@@ -7,13 +7,19 @@ If you're using the Shopify Hydrogen framework, you can use the Sentry Remix SDK
7
7
8
8
## 1. Installing Sentry Remix SDK
9
9
10
- First, install the Sentry Remix SDK in your application. We recommend using the Sentry wizard to automatically install the SDK :
10
+ First, install the Sentry Remix SDK with your package manager :
11
11
12
- ``` bash
13
- npx @sentry/wizard@latest -i remix
12
+ ``` bash {tabTitle:npm}
13
+ npm install @sentry/remix --save
14
+ ```
15
+
16
+ ``` bash {tabTitle:yarn}
17
+ yarn add @sentry/remix
14
18
```
15
19
16
- If the wizard doesn't work for you, you can also [ set up the Remix SDK manually] ( /platforms/javascript/guides/remix/manual-setup/ ) .
20
+ ``` bash {tabTitle:pnpm}
21
+ pnpm add @sentry/remix
22
+ ```
17
23
18
24
## 2. Installing Sentry Cloudflare SDK
19
25
@@ -33,11 +39,19 @@ yarn add @sentry/cloudflare
33
39
pnpm add @sentry/cloudflare
34
40
```
35
41
42
+ ## 3. Instrumenting Your Server
36
43
37
44
Then update your ` server.ts ` file to use the ` wrapRequestHandler ` method:
38
45
39
46
``` ts {filename:server.ts}
40
- import { wrapRequestHandler } from " @sentry/cloudflare" ;
47
+ import { wrapRequestHandler } from " @sentry/cloudflare/request" ;
48
+ import { instrumentBuild } from " @sentry/remix/cloudflare" ;
49
+ // Virtual entry point for the app
50
+ import * as remixBuild from ' virtual:remix/server-build' ;
51
+
52
+ // Instrument your server build with Sentry
53
+ // and use the instrumented build inside the fetch handler
54
+ const instrumentedBuild = instrumentBuild (remixBuild )
41
55
42
56
/**
43
57
* Export a fetch handler in module format.
@@ -66,24 +80,54 @@ export default {
66
80
};
67
81
```
68
82
69
- To remove errors relating to ` node:async_hooks ` (which is included in the sdk, but not used by ` wrapRequestHandler ` ), add a custom vite plugin to your ` vite.config.ts ` file that will alias it to an empty module:
83
+ ## 4. Instrumenting Your Client
70
84
71
- ``` ts {filename:vite.config.ts}
72
- export function removeAsyncHooksPlugin(): Plugin {
73
- return {
74
- name: " remove-async-hooks" ,
75
- load : (id ) => {
76
- if (id === " node:async_hooks" ) {
77
- return " export default {}" ;
78
- }
79
- },
80
- };
85
+ Wrap your Remix root component using ` withSentry ` :
86
+
87
+ ``` tsx {filename:root.tsx}
88
+ import { withSentry } from " @sentry/remix/cloudflare" ;
89
+
90
+ function App({ children }) {
91
+ return <>{ children } </>;
81
92
}
82
93
83
- export default defineConfig ({
84
- plugins: [
85
- removeAsyncHooksPlugin (),
86
- // rest of your plugins
94
+ // Pass `useEffect`, `useLocation` and `useMatches` hooks to `withSentry`
95
+ export default withSentry (App , useEffect , useLocation , useMatches );
96
+ ```
97
+
98
+
99
+ Finally, update your ` entry.client.tsx ` file to initialize Sentry SDK on the client:
100
+
101
+ ``` tsx {filename:entry.client.tsx}
102
+ import * as Sentry from " @sentry/remix/cloudflare" ;
103
+
104
+ Sentry .init ({
105
+ dsn: " ___PUBLIC_DSN___" ,
106
+ integrations: [
107
+ Sentry .browserTracingIntegration ({
108
+ useEffect ,
109
+ useLocation ,
110
+ useMatches ,
111
+ }),
112
+ // Replay is only available in the client
113
+ Sentry .replayIntegration (),
87
114
],
115
+
116
+ // Set tracesSampleRate to 1.0 to capture 100%
117
+ // of transactions for tracing.
118
+ // We recommend adjusting this value in production
119
+ // Learn more at
120
+ // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
121
+ tracesSampleRate: 1.0 ,
122
+
123
+ // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
124
+ tracePropagationTargets: [" localhost" , / ^ https:\/\/ yourserver\. io\/ api/ ],
125
+
126
+ // Capture Replay for 10% of all sessions,
127
+ // plus for 100% of sessions with an error
128
+ // Learn more at
129
+ // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration
130
+ replaysSessionSampleRate: 0.1 ,
131
+ replaysOnErrorSampleRate: 1.0 ,
88
132
});
89
133
```
0 commit comments