Skip to content

Commit

Permalink
Fix inheriting sampling decision from parent.
Browse files Browse the repository at this point in the history
Fixes gh-1099
  • Loading branch information
maciejwalkowiak committed Dec 9, 2020
1 parent f9f2686 commit 920d40e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
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 920d40e

Please sign in to comment.