Skip to content

Commit 0ae4b8f

Browse files
committed
edit connecting front to back section and add sentry-trace header to it
1 parent da8a13a commit 0ae4b8f

File tree

1 file changed

+16
-14
lines changed
  • src/platforms/javascript/common/performance

1 file changed

+16
-14
lines changed

src/platforms/javascript/common/performance/index.mdx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,36 @@ Without sampling, our atomatic instrumenation will send a transaction any time a
7878
7979
</markdown></Alert>
8080
81-
### Connecting Backend and Frontend Transactions
81+
## Connecting Backend and Frontend Transactions
8282
83-
When instrumenting both frontend and backend with Sentry, you can connect the
84-
`pageload` transaction on the frontend with the request transaction that rendered the page on the backend.
83+
To connect backend and frontend transactions into a single choherent trace, Sentry uses a `trace_id` value which is propagated between frontend and backend. Depending on the circumstance, this id is transmitted either in a request/response header or in an HTML `<meta>` tag. Linking transactions in this way makes it possible for you to navigate between them in the Sentry UI, so you can better understand how the different parts of your system are affecting each other.
8584
86-
Once connected, the backend and frontend transactions will share the same `trace_id`, allowing you to navigate from one transaction to the other in Sentry.
85+
### Pageload
8786
88-
In your backend code, include a `<meta>` tag in the `<head>` of the rendered HTML document as in this example:
87+
When enabling tracing in both frontend and backend and taking advantage of the automatic frontend instrumentation, you can connect the automatically-generated `pageload` transaction on the frontend with the request transaction that serves the page on the backend. Because JavaScript code running in a browser cannot read the response headers of the current page, the `trace_id` must be transmitted in the response itself, specifically in a `<meta>` tag in the `<head>` of the HTML sent from your backend.
8988
9089
```html
9190
<html>
92-
<head>
93-
<meta name="sentry-trace" content="{{ span.toTraceparent() }}">
94-
<!-- ... -->
91+
<head>
92+
<meta name="sentry-trace" content="{{ span.toTraceparent() }}" />
93+
<!-- ... -->
94+
</head>
95+
</html>
9596
```
9697
97-
The `name` attribute must be the string `"sentry-trace"` and the `content` attribute must be generated by your backend's Sentry SDK using `span.toTraceparent()` (or equivalent, depending on the backend platform).
98+
The `name` attribute must be the string `"sentry-trace"` and the `content` attribute must be generated by your backend's Sentry SDK using `span.toTraceparent()` (or equivalent, depending on the backend platform). This guarantees that a new and unique value will be generated for each request.
9899
99-
The `span` reference is either the transaction that rendered the page or any of its child spans. It defines the parent of the `pageload` transaction.
100+
The `span` reference is either the transaction that serves the HTML, or any of its child spans. It defines the parent of the `pageload` transaction.
100101
101-
For the correct association of transactions in a trace, make sure your backend will render a new and unique value for the `content` attribute for every request. Reusing the same value will cause unrelated traces to incorrectly share the same `trace_id`.
102+
Once the data is included in the `<meta>` tag, our `BrowserTracing` integration will pick it up automatically and link it to the transaction generated on pageload. (Note that it will not get linked to automatically-generated `navigation` transactions, that is, those which don't require a full page reload. Each of those will be the result of a different request transaction on the backend, and therefore should have a unique `trace_id`.)
102103
103-
<Alert level="info" title="Note"><markdown>
104+
### Navigation and Other XHR Requests
104105
105-
JavaScript code running on a browser cannot read the response headers of the current page. Therefore, the `<meta>` tag is used to propagate tracing metadata from the backend instead of the `sentry-trace` HTTP header described earlier.
106+
Once a page is loaded, any requests it makes and any responses your backend generates as a result are linked through a request/response header.
106107
107-
</markdown></Alert>
108+
As is the case with the `<meta>` tag discussed above, the header's name is `sentry-trace` and its value is obtained by calling `span.toTraceparent()` (or the equivalent), where `span` is either the relevant transaction or any of its children.
108109
110+
All of Sentry's tracing-related integrations (`BrowserTracing`, `Http`, and `Express`) either generate or pick up and propagate this header automatically as appropriate, for all transactions and spans which they generate. You can also attach and read the header yourself, in any case in which you've manually created either a transaction or a span and it makes sense to do so.
109111
110112
## Retrieving an Active Transaction
111113

0 commit comments

Comments
 (0)