|
| 1 | +--- |
| 2 | +title: Shopify Hydrogen Guide |
| 3 | +description: "Learn how to use the Sentry Remix SDK to instrument your Shopify Hydrogen app." |
| 4 | +--- |
| 5 | + |
| 6 | +If you're using the Shopify Hydrogen framework, you can use the Sentry Remix SDK to add Sentry instrumentation to your app. |
| 7 | + |
| 8 | +First, install the Sentry Remix SDK in your application. We recommend using the Sentry wizard to automatically install the SDK: |
| 9 | + |
| 10 | +```bash |
| 11 | +npx @sentry/wizard@latest -i remix |
| 12 | +``` |
| 13 | + |
| 14 | +If the wizard doesn't work for you, you can also [set up the Remix SDK manually](/platforms/javascript/guides/remix/manual-setup/). |
| 15 | + |
| 16 | +After installing the Sentry Remix SDK, delete the newly generated `instrumentation.server.mjs` file and all newly generated code from `entry.server.tsx`. This instrumentation is not needed because you are going to use the Sentry Cloudflare SDK for server-side instrumentation. |
| 17 | + |
| 18 | +Now you can install the Sentry Cloudflare SDK. First, install the SDK with your package manager: |
| 19 | + |
| 20 | +<PlatformContent includePath="getting-started-install" /> |
| 21 | + |
| 22 | +Then update your `server.ts` file to use the `wrapRequestHandler` method: |
| 23 | + |
| 24 | +```ts {filename:server.ts} |
| 25 | +import { wrapRequestHandler } from "@sentry/cloudflare"; |
| 26 | + |
| 27 | +/** |
| 28 | + * Export a fetch handler in module format. |
| 29 | + */ |
| 30 | +export default { |
| 31 | + async fetch( |
| 32 | + request: Request, |
| 33 | + env: Env, |
| 34 | + executionContext: ExecutionContext |
| 35 | + ): Promise<Response> { |
| 36 | + return wrapRequestHandler( |
| 37 | + { |
| 38 | + options: { |
| 39 | + dsn: "YOUR_DSN_HERE", |
| 40 | + tracesSampleRate: 1.0, |
| 41 | + }, |
| 42 | + // Need to cast to any because this is not on cloudflare |
| 43 | + request: request as any, |
| 44 | + context: executionContext, |
| 45 | + }, |
| 46 | + async () => { |
| 47 | + // request handling logic |
| 48 | + } |
| 49 | + ); |
| 50 | + }, |
| 51 | +}; |
| 52 | +``` |
| 53 | + |
| 54 | +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: |
| 55 | + |
| 56 | +```ts {filename:vite.config.ts} |
| 57 | +export function removeAsyncHooksPlugin(): Plugin { |
| 58 | + return { |
| 59 | + name: "remove-async-hooks", |
| 60 | + load: (id) => { |
| 61 | + if (id === "node:async_hooks") { |
| 62 | + return "export default {}"; |
| 63 | + } |
| 64 | + }, |
| 65 | + }; |
| 66 | +} |
| 67 | + |
| 68 | +export default defineConfig({ |
| 69 | + plugins: [ |
| 70 | + removeAsyncHooksPlugin(), |
| 71 | + // rest of your plugins |
| 72 | + ], |
| 73 | +}); |
| 74 | +``` |
0 commit comments