fix(server): Reorder DSC validation for correct client sample rate #4625
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains several fixes to the Envelope processor surrounding DSC
validation. Together, these fixes ensure that the
_dsc
metadata fieldin the event payload contains the same values that were used during
sampling and normalization. It also fixes the
trace.client_sample_rate
field in case a foreign DSC was reset.
Background
Relay validates whether the DSC originates in a project of the same
organization. If this is not the case and we were to use this DSC for
dynamic sampling, we would be applying sampling rules and rates from a
different organization.
If the DSC is invalid, we try to compute a new one from the information
in the event payload: We take the trace ID, environment, release, and
project key from event data. This simplifies the sampling routines,
since they can afterwards use the DSC and do not have to access the
event payload.
Fixes
DSC from the event payload. Previously, we would leave the old DSC
in.
remaining DSC contents cannot be used, the sampling rate was actually
applied and must be retained for extrapolation. Previously, we
removed it along with the rest of the foreign DSC.
finalize_event
, where it gets written intothe event payload
_dsc
field. Since we validate the DSC both inPoPs and processing Relays, in practice the field always received the
correct value. However, we now ensure correct order.
client sampling rate into the event's trace context. Previously,
these two functions were switched and potentially wrong data was
written.
_dsc
metadata is materialized there, too.