-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(javascript): Add documentation for injecting Html <meta>
tags
#10926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8737c61
a3ebd81
dcf6b06
5f49365
483def4
c750e4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,7 @@ In this example, we create a new transaction that is attached to the trace speci | |
|
||
</PlatformCategorySection> | ||
|
||
### Inject Tracing Information to Outgoing Requests | ||
### Inject Tracing Information into Outgoing Requests | ||
|
||
For distributed tracing to work, the two headers that you extracted and stored in the active root span, `sentry-trace` and `baggage`, must be added to outgoing HTTP requests. | ||
|
||
|
@@ -205,6 +205,46 @@ In this example, tracing information is propagated to the project running at `ht | |
|
||
The two services are now connected with your custom distributed tracing implementation. | ||
|
||
<PlatformCategorySection supported={['server', 'serverless']}> | ||
|
||
### Injecting Tracing Information into HTML | ||
|
||
If you're server-side rendering HTML and you use a Sentry SDK in your browser application, you can connect the backend and frontend traces. | ||
You can do this by injecting your server's tracing information `<meta>` tags into the HTML that's initially served to the client. | ||
When the frontend SDK is initialized, it will automatically pick up the tracing information from the `<meta>` tags and continue the trace. | ||
Note that your browser SDK needs to register `browserTracingIntegration` for this to work. | ||
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
function renderHtml() { | ||
const metaTagValues = Sentry.getMetaTagValues( | ||
Sentry.getCurrentScope(), | ||
Sentry.getCurrentSpan(), | ||
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Sentry.getClient() | ||
); | ||
|
||
return ` | ||
<html> | ||
<head> | ||
<meta name="sentry-trace" content="${metaTagValues["sentry-trace"]}"> | ||
<meta name="baggage" content="${metaTagValues.baggage}"> | ||
</head> | ||
<body> | ||
<!-- Your HTML content --> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
``` | ||
|
||
<Note> | ||
|
||
This setup is only required if you have a custom SSR or HTML page generation setup. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid showing this note, and simply only show this whole section for relevant SDKs? So hide it for next, remix etc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah let's try this first. We can always expand the allowlist if users are asking for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, updated to |
||
If you're using a meta framework like Next.js, the respective Sentry SDK already takes care of setting the tracing information automatically. | ||
|
||
</Note> | ||
|
||
</PlatformCategorySection> | ||
|
||
### Starting a New Trace | ||
|
||
Available since SDK version `8.5.0`. | ||
|
Uh oh!
There was an error while loading. Please reload this page.