From 9f9fdc5ba361dc98903f3f723217d8792e540e1f Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 23 Sep 2024 15:03:22 -0700 Subject: [PATCH] Fix --- .../agent/internal/keytransaction/KeyTransactionSampler.java | 3 +++ .../applicationinsights/agent/internal/sampling/Samplers.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionSampler.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionSampler.java index f504af0432..d9e67db321 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionSampler.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/keytransaction/KeyTransactionSampler.java @@ -84,6 +84,9 @@ public SamplingResult shouldSample( SamplingResult result = fallback.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks); + if (existingKeyTransactions.isEmpty() && startKeyTransactions.isEmpty()) { + return result; + } return new TransactionSamplingResult( existingKeyTransactions, startKeyTransactions, endKeyTransactions, result); } diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/Samplers.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/Samplers.java index 4db1eeabf1..a55385e961 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/Samplers.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/Samplers.java @@ -55,7 +55,7 @@ public static Sampler getSampler( // as // it will ensure consistent traces, however it does not accurately compute item counts, since // item counts are not propagated in trace state (yet) - return Sampler.parentBasedBuilder(sampler).build(); + sampler = Sampler.parentBasedBuilder(sampler).build(); } if (KeyTransactionConfigSupplier.KEY_TRANSACTIONS_ENABLED) {