Skip to content

Commit 0149cd3

Browse files
committed
Address comments
1 parent 541c6a7 commit 0149cd3

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public SamplingResult shouldSample(
134134
SamplingResult result =
135135
applier.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);
136136

137+
// If the trace state has a sampling rule reference, propagate it
138+
// Otherwise, propagate the matched sampling rule using AwsSamplingResult
137139
String ruleToPropagate =
138140
upstreamMatchedRule == null ? applier.getRuleName() : upstreamMatchedRule;
139141
if (this.adaptiveSamplingConfig != null
@@ -199,6 +201,15 @@ void adaptSampling(ReadableSpan span, SpanData spanData, Consumer<ReadableSpan>
199201
operation = generateIngressOperation(spanData);
200202
}
201203
for (AwsXrayAdaptiveSamplingConfig.AnomalyConditions condition : anomalyConditions) {
204+
// Skip condition if it would only re-apply action already being taken
205+
if ((shouldBoostSampling
206+
&& AwsXrayAdaptiveSamplingConfig.UsageType.SAMPLING_BOOST.equals(
207+
condition.getUsage()))
208+
|| (shouldCaptureAnomalySpan
209+
&& AwsXrayAdaptiveSamplingConfig.UsageType.ERROR_SPAN_CAPTURE.equals(
210+
condition.getUsage()))) {
211+
continue;
212+
}
202213
// Check if the operation matches any in the list or if operations list is null (match all)
203214
List<String> operations = condition.getOperations();
204215
if (!(operations == null || operations.isEmpty() || operations.contains(operation))) {
@@ -253,15 +264,15 @@ void adaptSampling(ReadableSpan span, SpanData spanData, Consumer<ReadableSpan>
253264
boolean isLocalRootSpan =
254265
parentContext == null || !parentContext.isValid() || parentContext.isRemote();
255266

256-
if (shouldBoostSampling || shouldCaptureAnomalySpan || isLocalRootSpan) {
257-
// Anomaly Capture
258-
if (shouldCaptureAnomalySpan
259-
&& anomalyCaptureRateLimiter != null
260-
&& anomalyCaptureRateLimiter.trySpend(1)) {
261-
spanBatcher.accept(span);
262-
}
267+
// Anomaly Capture
268+
if (shouldCaptureAnomalySpan
269+
&& anomalyCaptureRateLimiter != null
270+
&& anomalyCaptureRateLimiter.trySpend(1)) {
271+
spanBatcher.accept(span);
272+
}
263273

264-
// Sampling Boost
274+
// Sampling Boost
275+
if (shouldBoostSampling || isLocalRootSpan) {
265276
String ruleNameForBoostStats =
266277
span.getSpanContext()
267278
.getTraceState()

0 commit comments

Comments
 (0)