You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(javascript): Add documentation for injecting Html <meta> tags (#10926)
Add documentation for new JS APIs `getTraceMetaTags` and `getTraceData`
---------
Co-authored-by: Liza Mock <[email protected]>
Co-authored-by: Francesco Novy <[email protected]>
Copy file name to clipboardExpand all lines: platform-includes/distributed-tracing/custom-instrumentation/javascript.mdx
+47-2Lines changed: 47 additions & 2 deletions
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
169
169
170
170
</PlatformCategorySection>
171
171
172
-
### Inject Tracing Information to Outgoing Requests
172
+
### Inject Tracing Information into Outgoing Requests
173
173
174
174
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.
175
175
@@ -205,6 +205,51 @@ In this example, tracing information is propagated to the project running at `ht
205
205
206
206
The two services are now connected with your custom distributed tracing implementation.
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 by injecting your server's tracing information as `<meta>` tags into the HTML that's initially served to the browser. 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.
213
+
214
+
The easiest and recommended way to do this is to use the `Sentry.getTraceMetaTags()`:
215
+
216
+
```javascript {5} {filename:index.js}
217
+
function renderHtml() {
218
+
return `
219
+
<html>
220
+
<head>
221
+
${Sentry.getTraceMetaTags()}
222
+
</head>
223
+
<body>
224
+
<!-- Your HTML content -->
225
+
</body>
226
+
</html>
227
+
`;
228
+
}
229
+
```
230
+
231
+
Alternatively, if you need more control over how meta tags are generated, you can use `Sentry.getTraceData()` to get only the meta tag values and generate the meta tags yourself:
0 commit comments