Skip to content

Commit

Permalink
Fix inheriting sampling decision from parent. (#1100)
Browse files Browse the repository at this point in the history
Fixes gh-1099
  • Loading branch information
maciejwalkowiak authored Dec 11, 2020
1 parent c9e720f commit de00462
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# vNext

* Fix inheriting sampling decision from parent (#1100)
* Fixes and Tests: Session serialization and deserialization

# 4.0.0-alpha.2
Expand Down
23 changes: 12 additions & 11 deletions sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,20 @@ public void flush(long timeoutMillis) {
@Override
public @Nullable SentryTransaction startTransaction(
final @NotNull TransactionContext transactionContexts) {
return this.startTransaction(transactionContexts, null);
}

@Override
public @Nullable SentryTransaction startTransaction(
final @NotNull TransactionContext transactionContexts,
final @Nullable CustomSamplingContext customSamplingContext) {
Objects.requireNonNull(transactionContexts, "transactionContexts is required");

final SamplingContext samplingContext =
new SamplingContext(transactionContexts, customSamplingContext);
boolean samplingDecision = tracingSampler.sample(samplingContext);
transactionContexts.setSampled(samplingDecision);

SentryTransaction transaction = null;
if (!isEnabled()) {
options
Expand All @@ -706,17 +718,6 @@ public void flush(long timeoutMillis) {
return transaction;
}

@Override
public @Nullable SentryTransaction startTransaction(
final @NotNull TransactionContext transactionContexts,
final @Nullable CustomSamplingContext customSamplingContext) {
final SamplingContext samplingContext =
new SamplingContext(transactionContexts, customSamplingContext);
boolean samplingDecision = tracingSampler.sample(samplingContext);
transactionContexts.setSampled(samplingDecision);
return this.startTransaction(transactionContexts);
}

@Override
public @Nullable SentryTraceHeader traceHeaders() {
SentryTraceHeader traceHeader = null;
Expand Down
11 changes: 11 additions & 0 deletions sentry/src/test/java/io/sentry/HubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,17 @@ class HubTest {
}
}

@Test
fun `when startTransaction with parent sampled and no traces sampler provided, transaction inherits sampling decision`() {
val hub = generateHub()
val transactionContext = TransactionContext("name")
transactionContext.parentSampled = true
val transaction = hub.startTransaction(transactionContext)
assertNotNull(transaction)
assertNotNull(transaction.isSampled)
assertTrue(transaction.isSampled!!)
}

@Test
fun `Hub should close the sentry executor processor on close call`() {
val executor = mock<ISentryExecutorService>()
Expand Down

0 comments on commit de00462

Please sign in to comment.