Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit f005182

Browse files
lforstLms24jjbayerromtsn
authored
Add transaction back to DSC specification (#635)
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io> Co-authored-by: Joris Bayer <joris.bayer@sentry.io> Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
1 parent e48d7d4 commit f005182

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/docs/sdk/performance/dynamic-sampling-context.mdx

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,30 @@ After the DSC of a particular trace has been frozen, API calls like `set_user` s
105105

106106
Dynamic Sampling Context is sent to Sentry via the `trace` envelope header and is propagated to downstream SDKs via a baggage header.
107107

108-
All of the values in the payloads below are required (non-optional) in a sense, that when they are known to an SDK at the time a transaction envelope is sent to Sentry, or at the time a baggage header is propagated, they must also be included in said envelope or baggage.
108+
All of the values in the payload schemas below are required (non-optional) in a sense, that when they are known to an SDK at the time a transaction envelope is sent to Sentry, or at the time a baggage header is propagated, they must also be included in said envelope or baggage.
109+
110+
<Alert level="warning">
111+
112+
### Note on "low-quality" transaction names:
113+
114+
UX wise for the Dynamic Sampling product, we depend on transaction names (i.e. the `transaction` parameter of the DSC) to have "good quality".
115+
**Good quality transaction names** are descriptive, have proper grouping on Sentry, have low cardinality, and do not contain PII or other identifiers.
116+
117+
**For that reason: If and only if a transaction name has good quality, it should be included in the DSC. Otherwise, it cannot be included!**
118+
119+
Examples for **low quality** ❌ transaction names:
120+
121+
- `"/organization/601242c3-8f49-4158-aef4-c9e42cb1422c/user/601242c3-8f49-4158-aef4-c9e42cb1422c"`
122+
- `"UIComponentWithHash_7sd8x823f48_x7b26"`
123+
124+
Examples for **good quality** ✅ transaction names:
125+
126+
- `"/organization/:organizationId/user/:userId"`
127+
- `"UserListUIComponent"`
128+
129+
SDKs can leverage <Link to="/sdk/event-payloads/transaction/#transaction-annotations">transaction annotations</Link> (in particular the `source` of the transaction name) to determine which transaction names have a good quality.
130+
131+
</Alert>
109132

110133
### Strictly required values
111134

@@ -122,8 +145,9 @@ The value of this envelope header is a JSON object with the following fields:
122145
- `release` (string) - The release name as specified in client options`.
123146
- `environment` (string) - The environment name as specified in client options.
124147
- `user_segment` (string) - User segment as set by the user with <Link to="/sdk/unified-api/#scope">`scope.set_user`</Link>.
148+
- `transaction` (string, **only include if name has [good quality](#note-on-low-quality-transaction-names)**) - The transaction name set on the scope.
125149

126-
It's important to note that at the moment, only `release`, `environment`, and `user_segment` are used by the product for dynamic sampling functionality.
150+
It's important to note that at the moment, only `release`, `environment`, `user_segment` and `transaction` are used by the product for dynamic sampling functionality.
127151
The rest of the context attributes, `trace_id`, `public_key`, and `sample_rate`, are used by Relay for internal decisions (like transaction sample rate smoothing).
128152

129153
### Baggage-Header
@@ -136,6 +160,7 @@ SDKs may use the following keys to set entries on `baggage` HTTP headers:
136160
- `sentry-release`
137161
- `sentry-environment`
138162
- `sentry-user_segment`
163+
- `sentry-transaction` (**only include if name has [good quality](#note-on-low-quality-transaction-names)**)
139164

140165
SDKs must set all of the keys in the form of "`sentry-[name]`".
141166
The prefix "`sentry-`" acts to identify key-value pairs set by Sentry SDKs.
@@ -198,17 +223,10 @@ These are not blockers to the adoption of the spec, but instead are here as cont
198223

199224
### The Temporal Problem
200225

201-
<Alert level="warning">
202-
203-
This section contains references to `transaction` and `user_id`, which are not part of the dynamic sampling context right now because of PII concerns.
204-
They might however make a comeback in the future and the problem outlined here still applies to `user_segment`.
205-
206-
</Alert>
207-
208-
Unlike `environment` or `release`, which should always be known to an SDK at initialization time, `user_id`, `user_segment`, and `transaction` (name) are only known after SDK initialization time.
226+
Unlike `environment` or `release`, which should always be known to an SDK at initialization time, `user_segment`, and `transaction` (name) are only known after SDK initialization time.
209227
This means that if a trace is propagated from a running transaction _BEFORE_ the user/transaction attributes are set, you'll get a portion of transactions in a trace that have different Dynamic Sampling Context than other portions, leading to _dynamic sampling across a trace_ not working as expected for users.
210228

211-
Let's say we want to dynamically sample a browser application based on the `user_id`.
229+
Let's say we want to dynamically sample a browser application based on the `user_segment`.
212230
In a typical single page application (SPA), the user information has to be requested from some backend service before it can be set with `Sentry.setUser` on the frontend.
213231

214232
Here's an example of that flow:
@@ -219,16 +237,14 @@ Here's an example of that flow:
219237
- user service continues trace by automatically creating sampling transaction
220238
- user service pings database service (propogates sentry-trace/baggage to database service)
221239
- database service continues trace by automatically creating sampling transaction
222-
- Page gets data from user service, calls `Sentry.setUser` and sets `user_id`
240+
- Page gets data from user service, calls `Sentry.setUser` and sets `user_segment`
223241
- Page makes HTTP requests to service A, service B, and service C (propogates sentry-trace/baggage to services A, B and C)
224242
- DSC is propogated with baggage to service A, service B, and service C, so 3 child transactions
225243
- Page finishes loading, finishing `pageload` transaction, which is sent to Sentry
226244

227-
In this case, the baggage that is propogated to the user service and the downstream database service _does not_ have the `user_id` value in it, because it was not yet set on the browser SDK.
228-
Therefore, when Relay tries to dynamically sample the user services and database services transactions based on `user_id`, it will not be able to.
229-
In addition, since the DSC is frozen after it's been sent, the DSC sent to service A, service B, and service C will not have `user_id` on it either. This means it also will not be dynamically sampled properly if there is a trace-wide DS rule on `user_id`.
230-
231-
This problem exists for both `user_id` and `user_segment`, and it is because since we don't have the user information on some platforms/frameworks right as we initialize the SDK.
245+
In this case, the baggage that is propogated to the user service and the downstream database service _does not_ have the `user_segment` value in it, because it was not yet set on the browser SDK.
246+
Therefore, when Relay tries to dynamically sample the user services and database services transactions based on `user_segment`, it will not be able to.
247+
In addition, since the DSC is frozen after it's been sent, the DSC sent to service A, service B, and service C will not have `user_segment` on it either. This means it also will not be dynamically sampled properly if there is a trace-wide DS rule on `user_segment`.
232248

233249
For `transaction` name, the problem is similar, but it is because of paramaterization.
234250
As much as we can, the SDKs will try to paramaterize transaction names (for ex, turn `/teams/123/user/456` into `/teams/:id/user/:id`) so that similar transactions are grouped together in the UI.

0 commit comments

Comments
 (0)