-
-
Notifications
You must be signed in to change notification settings - Fork 465
Propagate sampling random value #4153
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
Conversation
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c2c78de | 415.28 ms | 505.08 ms | 89.80 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| c2c78de | 1.58 MiB | 2.21 MiB | 640.27 KiB |
Previous results on branch: feat/sample_rand
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b5d63c8 | 384.39 ms | 443.98 ms | 59.59 ms |
| b674478 | 399.19 ms | 482.67 ms | 83.48 ms |
| b4d2996 | 319.66 ms | 369.94 ms | 50.28 ms |
| 473d6ab | 446.68 ms | 464.90 ms | 18.22 ms |
| 7c29bb1 | 647.18 ms | 767.43 ms | 120.25 ms |
| 4e41178 | 388.33 ms | 531.18 ms | 142.86 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b5d63c8 | 1.58 MiB | 2.21 MiB | 641.09 KiB |
| b674478 | 1.58 MiB | 2.21 MiB | 640.91 KiB |
| b4d2996 | 1.58 MiB | 2.21 MiB | 640.92 KiB |
| 473d6ab | 1.58 MiB | 2.21 MiB | 640.93 KiB |
| 7c29bb1 | 1.58 MiB | 2.21 MiB | 640.92 KiB |
| 4e41178 | 1.58 MiB | 2.21 MiB | 641.07 KiB |
| sentrySpan.toBaggageHeader(Collections.emptyList()); | ||
| if (baggageHeader != null) { | ||
| setter.set(carrier, baggageHeader.getName(), baggageHeader.getValue()); | ||
| // TODO can we use traceIfAllowed? do we have the URL here? need to access span attrs |
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.
Left this as a TODO for the future. We could start looking at span attributes to retrieve the URL of the downstream system.
| .getLogger() | ||
| .log(SentryLevel.DEBUG, "Continuing Sentry trace %s", sentryTraceHeader.getTraceId()); | ||
|
|
||
| final @NotNull PropagationContext propagationContext = |
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.
Since this causes baggage to be frozen immediately, we no longer want to do this in the propagator.
| if (baggageHeader != null) { | ||
| setter.set(carrier, baggageHeader.getName(), baggageHeader.getValue()); | ||
| // TODO can we use traceIfAllowed? do we have the URL here? need to access span attrs | ||
| final @Nullable TracingUtils.TracingHeaders tracingHeaders = |
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.
This ensures baggage is frozen when sending out headers. Not freezing was a bug.
| new PropagationContext( | ||
| new SentryId(traceId), sentrySpanId, sentryParentSpanId, baggage, sampled); | ||
|
|
||
| baggage = propagationContext.getBaggage(); |
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 don't want to send the wrong baggage into the OtelSpanWrapper ctor further down.
| private final @NotNull Contexts contexts = new Contexts(); | ||
| private @Nullable String transactionName; | ||
| private @Nullable TransactionNameSource transactionNameSource; | ||
| private final @Nullable Baggage 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.
No need to keep this as a property here. We can always ask the context for it.
| ? null | ||
| : StringUtils.join(",", thirdPartyKeyValueStrings); | ||
| return new Baggage(keyValues, thirdPartyHeader, mutable, logger); | ||
| /* |
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.
When creating Baggage from headers we now ignore the sample random value entry and instead of freezing right away we just mark the baggage for being frozen. This shouldFreeze flag is then checked when passing baggage into either PropagationContext or TransactionContext and frozen if true.
| this.transactionNameSource = context.getTransactionNameSource(); | ||
| this.transactionOptions = transactionOptions; | ||
|
|
||
| if (context.getBaggage() != 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.
We're relying on TransactionContext to bring in baggage here. Instead of holding on directly, we're using context to access it.
| this.name = Objects.requireNonNull(name, "name is required"); | ||
| this.transactionNameSource = transactionNameSource; | ||
| this.setSamplingDecision(samplingDecision); | ||
| this.baggage = TracingUtils.ensureBaggage(null, samplingDecision); |
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.
Takes care of creating a new Baggage if missing, backfilling sample random value and freezing baggage if marked for freezing.
We can't force customers to go through Sentry.continueTrace which would create a PropagationContext so we also have to handle this here. This is something we should improve when replacing the Performance API.
| private @Nullable Boolean sampled; | ||
|
|
||
| private @Nullable Baggage baggage; | ||
| private final @NotNull Baggage 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.
Changed this to non null, so we don't have to handle null everywhere we access this.
| propagationContext.getTraceId(), | ||
| propagationContext.getSpanId(), | ||
| propagationContext.getParentSpanId(), | ||
| cloneBaggage(propagationContext.getBaggage()), |
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 were cloning baggage here for each scope fork meaning a non frozen baggage would never freeze. This might no longer be a problem after having done a lot more changes now. However I don't see a reason to clone / separate any pre-existing baggage. If anything we should make sure a new one is created when isolation scope is forked.
bf75222 to
d3adc66
Compare
📜 Description
Propagate sampling random value to downstream systems (
sentry-sample_randin baggage) and Sentry (sample_randin envelope header).Use incoming
sentry-sample_rand.Backfill sampling random value in case it is missing.
💡 Motivation and Context
Closes #4115
Closes #4032
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps