-
-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sample rate to baggage as well as trace in envelope header and flatten user #2135
Conversation
@AbhiPrasad @lforst @Lms24 can any of you please leave a review, once you feel the docs are ready to make sure this aligns? |
Codecov Report
@@ Coverage Diff @@
## main #2135 +/- ##
============================================
- Coverage 80.95% 80.94% -0.02%
- Complexity 3257 3290 +33
============================================
Files 231 233 +2
Lines 11964 12044 +80
Branches 1589 1594 +5
============================================
+ Hits 9686 9749 +63
- Misses 1698 1712 +14
- Partials 580 583 +3
Continue to review full report at Codecov.
|
@@ -180,6 +180,10 @@ public void setTransaction(final @Nullable String transaction) { | |||
set("sentry-transaction", transaction); | |||
} | |||
|
|||
public void setSampleRate(final @Nullable String sampleRate) { | |||
set("sentry-samplerate", sampleRate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to make baggage and envelope header key names identical (except for the sentry-
prefix in baggage keys) so that we're able to just dump the DSC data into both transport mechanisms without any mapping. (Linking to the preview here for more details)
Therefore, we should change the snake case keys to underscores (like in the example below)
set("sentry-samplerate", sampleRate); | |
set("sentry-sample_rate", sampleRate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that also mean
sentry-publickey
becomessentry-public_key
sentry-traceid
becomessentry_trace_id
sentry-userid
becomessentry-user_id
sentry-usersegment
becomessentry-user_segment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sentry-traceid
becomessentry_trace_id
It becomes sentry-trace_id
, but that probably just was a typo ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK thanks, will update.
Yeah just a typo on the _
there.
CHANGELOG.md
Outdated
## Unreleased | ||
|
||
### Features | ||
|
||
- Add sample rate to baggage as well as trace in envelope header and flatten user ([#2135](https://github.com/getsentry/sentry-java/pull/2135)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge main into the branch to fix the changelog.
private static @Nullable String getSegment(final @NotNull User user) { | ||
final Map<String, String> others = user.getOthers(); | ||
if (others != null) { | ||
return others.get("segment"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should segment
be a new field in the User
protocol maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS seems to have it https://github.com/getsentry/sentry-javascript/blob/master/packages/types/src/user.ts while cocoa does not. Didn't check any other SDKs. Not sure what exactly this is used for / if it should be added. Can create a separate issue to track if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please, but let's be sure that the approach with others
works if not now.
Also, in this issue, we should upgrade the protocol https://develop.sentry.dev/sdk/event-payloads/user/ (adding the new field).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there's a confusion here. Retrieving segment
from others
is not new behaviour. It's been there before. See
if (sampleRateAsDouble < 0.0 || sampleRateAsDouble > 1.0) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we extract this logic from SentryOptions#setSampleRate
and SentryOptions#setTracesSampleRate
and reuse it as an util function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setSampleRate
has sampleRate > 1.0 || sampleRate <= 0.0
while setTracesSampleRate
has tracesSampleRate > 1.0 || tracesSampleRate < 0.0
. Can add a util but won't reuse in both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, tracesSampleRate
can be 0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added SampleRateUtil
in #2141
DecimalFormat df = | ||
new DecimalFormat("#.################", DecimalFormatSymbols.getInstance(Locale.US)); | ||
return df.format(sampleRateAsDouble); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid US
locale and use Locale.ROOT
instead, some custom OS versions might not have the US locale.
Why don't we just transform the Double to String and send it as it is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't want exponent formatting. 0.00000021.toString()
would become 2.1E-7
which we don't want.
Can replace the locale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the spec defining the number of max digits? because ################
can lead to a different value, not sure if this would round or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would round on the last digit. Yes we're aligning with JS on the max digits here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the locale usage in #2141
|
||
return baggage; | ||
} | ||
|
||
public static final class TraceContextUser implements JsonUnknown, JsonSerializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that be a breaking change if people is upgrading SDKs from X to Y? how does the ser/deser behave if you're reading a JSON with the older structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, updated the code to parse from legacy JSON in #2141
* Commit tests * Add sample rate from traces sampler to DSC * Do not replace null with true/false * Restore sample rate in OutboxSender * Remove fallback for sampling decision from TraceContext * Remove sample rate fallback from TracesSamplingDecision * Test more envelope header trace fields for OutboxSender * CR changes
…y/sentry-java into feat/add-sample-rate-to-baggage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
#2147) * Skip sending userId in DSC if send default pii is off * Add changelog * Add test case
📜 Description
Add sample rate to
baggage
header as well astrace
in envelope header.Flatten
user
intouser_id
anduser_segment
fortrace
in envelope header.💡 Motivation and Context
To allow for dynamic sampling and align with docs / other SDKs: getsentry/develop#613
💚 How did you test it?
📝 Checklist
🔮 Next steps