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
{{ message }}
This repository was archived by the owner on Aug 14, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: src/docs/sdk/performance/dynamic-sampling-context.mdx
+33-17Lines changed: 33 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -105,7 +105,30 @@ After the DSC of a particular trace has been frozen, API calls like `set_user` s
105
105
106
106
Dynamic Sampling Context is sent to Sentry via the `trace` envelope header and is propagated to downstream SDKs via a baggage header.
107
107
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
+
<Alertlevel="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!**
Examples for **good quality** ✅ transaction names:
125
+
126
+
-`"/organization/:organizationId/user/:userId"`
127
+
-`"UserListUIComponent"`
128
+
129
+
SDKs can leverage <Linkto="/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>
109
132
110
133
### Strictly required values
111
134
@@ -122,8 +145,9 @@ The value of this envelope header is a JSON object with the following fields:
122
145
-`release` (string) - The release name as specified in client options`.
123
146
-`environment` (string) - The environment name as specified in client options.
124
147
-`user_segment` (string) - User segment as set by the user with <Linkto="/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.
125
149
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.
127
151
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).
128
152
129
153
### Baggage-Header
@@ -136,6 +160,7 @@ SDKs may use the following keys to set entries on `baggage` HTTP headers:
136
160
-`sentry-release`
137
161
-`sentry-environment`
138
162
-`sentry-user_segment`
163
+
-`sentry-transaction` (**only include if name has [good quality](#note-on-low-quality-transaction-names)**)
139
164
140
165
SDKs must set all of the keys in the form of "`sentry-[name]`".
141
166
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
198
223
199
224
### The Temporal Problem
200
225
201
-
<Alertlevel="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.
209
227
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.
210
228
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`.
212
230
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.
213
231
214
232
Here's an example of that flow:
@@ -219,16 +237,14 @@ Here's an example of that flow:
219
237
- user service continues trace by automatically creating sampling transaction
220
238
- user service pings database service (propogates sentry-trace/baggage to database service)
221
239
- 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`
223
241
- Page makes HTTP requests to service A, service B, and service C (propogates sentry-trace/baggage to services A, B and C)
224
242
- DSC is propogated with baggage to service A, service B, and service C, so 3 child transactions
225
243
- Page finishes loading, finishing `pageload` transaction, which is sent to Sentry
226
244
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`.
232
248
233
249
For `transaction` name, the problem is similar, but it is because of paramaterization.
234
250
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