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/enriching-events/transaction-name/index.mdx
+26-38Lines changed: 26 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,36 +24,29 @@ You need to add `browserTracingIntegration` when initializing the SDK to automat
24
24
25
25
</PlatformCategorySection>
26
26
27
-
Generally, **you don't need to set or override the transaction name manually.**
28
-
In most cases, the automatically determined name is a good grouping mechanism.
29
-
However, if this does not work for your use case, you can set both transaction names independently.
27
+
Because automatically-determined names are a good grouping mechanism, unless you have a special use-case, **you won't need to set or override transaction names manually.**
30
28
31
-
## What is a "Good" Transaction Name?
29
+
## What's a "Good" Transaction Name?
32
30
33
-
The transaction name can reference the current web app or server route, mobile screen or activity, or the current task being executed.
31
+
Your transaction name can reference the current web app or server route, mobile screen or activity, or the current task being executed.
34
32
For example:
35
33
36
34
-`GET /api/{version}/users/`
37
35
-`UserListView`
38
36
-`myapp.tasks.renew_all_subscriptions`
39
37
40
-
Ideally, the transaction name does not contain variable values such as user
41
-
IDs but has rather low cardinality while still uniquely identifying a piece of
42
-
code you care about.
43
-
For example, instead of `'GET /api/users/123/details'`, set `'GET /api/users/:id/details'`.
44
-
This ensures that errors or traces for all requests made to this route are grouped together.
38
+
A good transaction name shouldn't have too many variables (such as user IDs), but should still be unique enough to help you easily identify the piece of code you care about.
39
+
For example, instead of naming a transaction`'GET /api/users/123/details'`, name it `'GET /api/users/:id/details'`.
40
+
This will group all errors and traces for requests to the same route.
45
41
46
-
### When to set the Transaction Name
42
+
### When to Set the Transaction Name
47
43
48
-
We generally recommend to let the SDK set the transaction name automatically.
49
-
However, in some cases, the SDK might not be able to set a name or the set name doesn't work for your use case.
44
+
It's usually best to let the SDK set the transaction name automatically. However, if it can't or the name doesn't suit your needs, you can set it manually.
50
45
51
-
If you need to set the transaction name manually, we recommend setting it _as early as possible_ in your application code, specifically when the operation you want to describe with the transaction name starts.
52
-
This ensures that errors thrown early in the life cycle of your application are correctly annotated.
53
-
Furthermore, it ensures consistency across a trace if you use [distributed tracing](/concepts/key-terms/tracing/distributed-tracing/).
46
+
We recommend setting it _as early as possible_ in your application code, ideally when the operation you want to track starts. This ensures that errors thrown early in the application lifecycle are annotated correctly and keeps traces consistent if you're using [distributed tracing](/concepts/key-terms/tracing/distributed-tracing/).
54
47
55
-
For example, in a server application, you might set the transaction name in a middleware that runs before the request is processed.
56
-
In a web application, you might set the transaction name when you enter a new route (e.g. in an SPA Router).
48
+
For example, in a server app, you can set the transaction name in middleware before handling a request.
49
+
In a web app, you can set it when navigating to a new route, like in an SPA router.
57
50
58
51
## Setting the Error Transaction Name
59
52
@@ -67,8 +60,7 @@ Set the transaction name on the current scope when the operation you want to gro
Note that the transaction name on the scope is only applied to error events. It does not influence the name of a potentially active root span.
71
-
Likewise, if a span is active while an error is thrown, its name will not be applied to the error event's transaction name.
63
+
The transaction name on the scope only applies to error events, not the active root span. Similarly, if an error happens during an active span, the span's name won’t be applied to the error's transaction name.
72
64
73
65
### Setting the Name on the Event
74
66
@@ -85,22 +77,22 @@ Sentry.init({
85
77
86
78
## Setting the Root Span Name
87
79
88
-
To override the name of the root span name (i.e. the trace name or transaction name in the Sentry UI), you have multiple options:
80
+
There are multiple options for overriding the root span name (for example, the trace or transaction name in the Sentry UI):
89
81
90
82
<PlatformCategorySectionsupported={['browser']}>
91
83
92
84
### At Root Span Start
93
85
94
86
Sentry's `browserTracingIntegration` automatically sets the transaction name based on the current route or URL for all `pageload` and `navigation` transactions.
95
-
If you want to override the transaction name, you can do so in the <PlatformLinkto="/tracing/instrumentation/automatic-instrumentation/#beforestartspan">`beforeStartSpan` callback</PlatformLink> of the integration.
87
+
To override the transaction name, use the <PlatformLinkto="/tracing/instrumentation/automatic-instrumentation/#beforestartspan">`beforeStartSpan` callback</PlatformLink> of the integration.
96
88
97
89
</PlatformCategorySection>
98
90
99
-
### While the root span is active
91
+
### While the Root Span Is Active
100
92
101
-
_Available since: v8.44.0_
93
+
_Available starting with: v8.44.0_
102
94
103
-
Sometimes, for example if you have a router that only emits the route change after it occurred, you might not be able to set the final root span name at span start but a little bit later. In this case, you can update the root span name while the span is active:
95
+
Sometimes, (for example if you have a router that only emits the route change after it occurred) you might not be able to set the final root span name at span start. In this case, you can update the root span name while the span is active:
Learn more about <PlatformLinkto="/tracing/instrumentation/custom-instrumentation/#updating-the-span-name">updating the span name</PlatformLink>.
113
105
114
-
### After the root span finished
106
+
### After the Root Span Has Finished
115
107
116
-
If you cannot determine the root span name before the span finishes, you can retroactively change it in `beforeSendTransaction`:
108
+
If you can't determine the root span name before the span finishes, you'll be able to change it retroactively in `beforeSendTransaction`:
117
109
118
110
```javascript
119
111
Sentry.init({
@@ -124,20 +116,16 @@ Sentry.init({
124
116
});
125
117
```
126
118
127
-
We recommend to only do this, if you cannot use any of the other options to set the root span name earlier.
119
+
<Note>
120
+
Only do this if you can't set the root span name earlier using other options.
121
+
</Note>
128
122
129
123
## Further Information
130
124
131
-
You might be wondering why these two types of transaction names exist and why they are set independently.
132
-
The reason is mostly historic evolvement of the Sentry product and the SDKs.
133
-
The error transaction name existed long before Sentry provided tracing capabilities and where it was only applied to error events to better group issues.
134
125
135
-
In the first iteration of Sentry's tracing or performance monitoring product, we decided to call the root span of a span tree within an application a "Transaction", which also had a name.
136
-
In the second, now ongoing, tracing iteration, Sentry's new UI features no longer mention "Transactions" for root spans but rather just "spans" and "traces".
137
-
However, the two concepts (error transaction name and root span name) are still ambiguous and used so throughout various older parts of the Sentry UI.
126
+
You might wonder why there are two separate transaction names and why they're set independently. This is mainly due to Sentry's history and evolution. The error transaction name existed before Sentry offered tracing, and it was used solely to group error events. When tracing was introduced, the root span in a span tree was also called a "transaction," with its own name.
138
127
139
-
With this product evolvement in mind, the SDKs also had to adapt their APIs around tracing, specifically moving away from transaction-based APIs in version 8.
140
-
Consequently, the SDK exposes the `setTransactionName` API on the `Scope` which—although the name might suggest differently from historic context—has nothing to do with spans.
141
-
Likewise, the span name is not automatically applied to error events either, meaning both concepts are completely [decoupled](https://github.com/getsentry/sentry-javascript/issues/10846) from each other.
128
+
In later iterations, Sentry shifted focus in the UI from "transactions" to "spans" and "traces," but the older concepts remain in parts of the UI. The SDKs adapted their APIs, moving away from transaction-based designs. For example, the `setTransactionName` API on the `Scope` refers to error transaction names, not spans. Similarly, a span name doesn’t automatically apply to error events, keeping the two concepts [separate](https://github.com/getsentry/sentry-javascript/issues/10846).
142
129
143
-
We believe that the ambiguity of these APIs will decrease over time as the Sentry product further moves away from associating the "Transaction" term with tracing and spans.
130
+
131
+
As Sentry continues to evolve, the ambiguity between these terms is expected to decrease as the product moves away from associating "transactions" with tracing and spans.
Copy file name to clipboardExpand all lines: platform-includes/performance/beforeNavigate-example/javascript.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
One common use case is parameterizing transaction names. For both `pageload` and `navigation` transactions, the `browserTracingIntegration` uses the browser's `window.location` value to generate a transaction name. Using `beforeStartSpan` lets you modify the transaction name to make it more generic, so that, for example, transactions named `GET /users/12312012` and `GET /users/11212012` can both be renamed to `GET /users/:userid`. That way they'll be grouped together.
1
+
One common use case is parameterizing transaction names. For both `pageload` and `navigation` transactions, the `browserTracingIntegration` uses the browser's `window.location` value to generate a transaction name. Using `beforeStartSpan` lets you modify the transaction name to make it more generic, so that for example, transactions named `GET /users/12312012` and `GET /users/11212012` can both be renamed to `GET /users/:userid`. That way they'll be grouped together.
0 commit comments