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
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/tracing/trace-propagation/index.mdx
+1-3Lines changed: 1 addition & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,7 @@ If the overall application landscape that you want to observe with Sentry consis
10
10
11
11
## What is Distributed Tracing?
12
12
13
-
In the context of tracing events across a distributed system, distributed tracing acts as a powerful debugging tool. Imagine your application as a vast network of interconnected parts. For example, your system might be spread across different servers or your application might split into different backend and frontend services, each potentially having their own technology stack.
14
-
15
-
When an error or performance issue occurs, it can be challenging to pinpoint the root cause due to the complexity of such a system. Distributed tracing helps you follow the path of an event as it travels through this intricate web, recording every step it takes. By examining these traces, you can reconstruct the sequence of events leading up to the event of interest, identify the specific components involved, and understand their interactions. This detailed visibility enables you to diagnose and resolve issues more effectively, ultimately improving the reliability and performance of your distributed system.
When tracing is enabled, the Sentry SDK will not only create spans for pageloads and transactions but also propagate trace information to other systems. This allows you to connect multiple systems and see how they interact with each other.
8
+
9
+
By default, outgoing HTTP requests will automatically be instrumented for you. For other cases where you may want to continue traces (for example when working with websockets), you can manually extract and inject tracing information.
10
+
11
+
## Enabling Automatic Distributed Tracing
12
+
13
+
To enable distributed tracing for your frontend, add `browserTracingIntegration` to your `Sentry.init()` options as described in the <PlatformLinkto="/tracing/instrumentation/automatic-instrumentation/">Automatic Instrumentation</PlatformLink> docs.
14
+
15
+
### Continuing a Trace Manually
16
+
17
+
By default, the `browserTracingIntegration` will automatically continue a trace found in a `<meta>` tag - see <PlatformLinkto="/tracing/trace-propagation/#automatic-trace-propagation">Automatic Trace Propagation</PlatformLink> for details.
18
+
If you want to continue a different trace, for example because you cannot propagate the trace through meta tags but through some different mechanism, you can do this:
## Configuring Distributed Tracing Without `browserTracingIntegration`
45
+
46
+
If you don't want to use the `browserTracingIntegration` integration, or you want to propagate traces in other places than HTTP requests (for example, with websockets), you can manually extract and inject tracing data in your application to connect multiple systems. For this, you must:
47
+
48
+
- Extract and store incoming tracing information from HTML `<meta>` tags when loading the page.
49
+
- Inject tracing information to any outgoing requests.
50
+
51
+
To learn more about distributed tracing, see our <PlatformLinkto="/tracing/trace-propagation/">Distributed Tracing</PlatformLink> docs.
52
+
53
+
### Extract Tracing Information From HTML `meta` Tags
54
+
55
+
If you have a server that renders your application's HTML (server-side rendering) and is also running a Sentry SDK, you can connect your backend to your backend via tracing.
56
+
57
+
To do this, have your server render HTML `<meta>` tags with the Sentry trace information. In your frontend, extract that tracing information when the page is loading and use it to create new transactions connected to that incoming backend trace.
58
+
59
+
Some Sentry backend SDKs provide a built-in way to inject these `<meta>` tags into rendered HTML. For example:
On this page you will learn how to manually propagate trace information into and out of your JavaScript application.
2
2
3
-
Distributed tracing will be set up automatically if:
4
-
5
-
- You've <PlatformLinkto="/tracing/">Set Up Tracing</PlatformLink>, or
6
-
- You're using one of the SDKs that include tracing propagation out of the box:
7
-
-`@sentry/astro`
8
-
-`@sentry/nextjs`
9
-
-`@sentry/nuxt`
10
-
-`@sentry/remix`
11
-
-`@sentry/solidstart`
12
-
-`@sentry/sveltekit`
13
-
14
-
If you are using a different package, and have not enabled tracing, you can manually set up your application for distributed tracing to work.
15
-
16
-
## Enabling Distributed Tracing
17
-
18
-
<PlatformCategorySectionsupported={['browser']}>
19
-
20
-
To enable distributed tracing for your frontend, add `browserTracingIntegration` to your `Sentry.init()` options as described in the <PlatformLinkto="/tracing/instrumentation/automatic-instrumentation/">Automatic Instrumentation</PlatformLink> docs.
21
-
22
-
If you want to use distributed tracing but not tracing, set the `tracesSampleRate` option to `0`.
By default, the `browserTracingIntegration` will automatically continue a trace found in a `<meta>` tags - see <PlatformLinkto="/tracing/trace-propagation/#automatic-trace-propagation">Automatic Trace Propagation</PlatformLink> for details.
38
-
If you want to continue a different trace, for example because you cannot propagate the trace through meta tags but through some different mechanism, you can do this as follows:
## Enabling Distributed Tracing without `browserTracingIntegration`
65
-
66
-
If you don't want to use the `browserTracingIntegration` integration, you can manually extract and inject tracing data in your application to connect multiple systems. For this, you must:
67
-
68
-
- Extract and store incoming tracing information from HTML `<meta>` tags when loading the page.
69
-
- Inject tracing information to any outgoing requests.
70
-
71
-
To learn more about distributed tracing, see our <PlatformLinkto="/tracing/trace-propagation/">Distributed Tracing</PlatformLink> docs.
72
-
73
-
### Extract Tracing Information From HTML `meta` Tags
74
-
75
-
If you have a server that renders your application's HTML (SSR) and is also running a Sentry SDK, you can connect your backend to your backend via tracing.
76
-
77
-
To do this, have your server render HTML `<meta>` tags with the Sentry trace information. In your frontend, extract that tracing information when the page is loading and use it to create new transactions connected to that incoming backend trace.
78
-
79
-
Some Sentry backend SDKs provide a built-in way to inject these `<meta>` tags into rendered HTML. For example:
If you want to use distributed tracing but not tracing, set the `tracesSampleRate` option to `0`.
116
-
117
-
```javascript
118
-
Sentry.init({
119
-
dsn:"___PUBLIC_DSN___",
120
-
121
-
// If this is 0, tracing is disabled
122
-
// but distributed tracing is not
123
-
tracesSampleRate:0,
124
-
});
125
-
```
126
-
127
-
## Manually Extracting and Injecting Distributed Tracing Information
128
-
129
-
You can also manually extract and inject tracing data into your application. For this, you must:
130
-
131
-
- Extract and store incoming tracing information from incoming request headers or similar.
132
-
- Inject tracing information to any outgoing requests.
133
-
134
-
To learn more about distributed tracing, see our <PlatformLink to="/tracing/trace-propagation/">Distributed Tracing</PlatformLink> docs.
135
-
136
-
### Extracting Incoming Tracing Information
137
-
138
-
You must extract and store incoming tracing information in memory for later use. Sentry provides the `continueTrace()` function to help you with this. Incoming tracing information can come from different places:
139
-
140
-
- In a web environment, it's sent with HTTP headers, for example, by another Sentry SDK used in your frontend project.
141
-
- In a job queue, it can be retrieved from meta or header variables.
142
-
- You also can pick up tracing information from environment variables.
143
-
144
-
Here's an example of how to extract and store incoming tracing information using `continueTrace()`:
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.
215
-
216
-
The easiest and recommended way to do this is to use the `Sentry.getTraceMetaTags()`:
217
-
218
-
```javascript {5} {filename:index.js}
219
-
function renderHtml() {
220
-
return `
221
-
<html>
222
-
<head>
223
-
${Sentry.getTraceMetaTags()}
224
-
</head>
225
-
<body>
226
-
<!-- Your HTML content -->
227
-
</body>
228
-
</html>
229
-
`;
230
-
}
231
-
```
232
-
233
-
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