Skip to content

Commit 4057f3d

Browse files
onurtemizkangetsantry[bot]shanamatthews
authored
feat(remix): Add meta instructions. (#8452)
* feat(remix): Add `meta` instructions. * [getsentry/action-github-commit] Auto commit * Apply suggestions from code review Co-authored-by: Shana Matthews <[email protected]> * Fix internal link. * fix link --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Shana Matthews <[email protected]>
1 parent 7f4f99d commit 4057f3d

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/platform-includes/distributed-tracing/how-to-use/javascript.remix.mdx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
If you're using the current version of our Remix SDK, distributed tracing will work out of the box for the client and server. To get around possible [Browser CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) issues, you should define `tracePropagationTargets` for client-side.
1+
Remix SDK attaches `sentry-trace` and `baggage` values from your `root` loader. You need to use the [`meta`](https://remix.run/docs/en/v1/api/conventions#meta) function to attach the data from your `loader` as `<meta>` tags. The following code snippet shows how to do this:
2+
3+
```typescript {tabTitle: Remix v1} {filename: root.tsx}
4+
export const meta: MetaFunction = ({ data }) => {
5+
return {
6+
// ...
7+
"sentry-trace": data.sentryTrace,
8+
baggage: data.sentryBaggage,
9+
};
10+
};
11+
```
12+
13+
```typescript {tabTitle: Remix v2} {filename: root.tsx}
14+
// Sentry provides a type for Remix v2 MetaFunction parameters
15+
// so you can access `data.sentryTrace` and `data.sentryBaggage` alongside other data from loader.
16+
import type { SentryMetaArgs } from "@sentry/remix";
17+
18+
export const meta = ({ data }: SentryMetaArgs<MetaFunction<typeof loader>>) => {
19+
return [
20+
{
21+
name: "sentry-trace",
22+
content: data.sentryTrace,
23+
},
24+
{
25+
name: "baggage",
26+
content: data.sentryBaggage,
27+
},
28+
];
29+
};
30+
```
31+
32+
The `name` attributes must be the strings `"sentry-trace"` and `"baggage"` and the `content` attributes must be generated by your backend Sentry SDK. For `sentry-trace`, use `span.toSentryTrace()` (or equivalent, depending on the backend platform). This guarantees that a new and unique value will be generated for each request. For `baggage`, use `serializeBaggage(span.getBaggage())`.
33+
34+
To get around possible [Browser CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) issues, you should define `tracePropagationTargets` on the client side. See <PlatformLink to="/usage/distributed-tracing/dealing-with-cors-issues/">Dealing with CORS Issues</PlatformLink> for more information.
235

336
```tsx
437
// entry.client.tsx

0 commit comments

Comments
 (0)