@@ -134,6 +134,8 @@ public SamplingResult shouldSample(
134
134
SamplingResult result =
135
135
applier .shouldSample (parentContext , traceId , name , spanKind , attributes , parentLinks );
136
136
137
+ // If the trace state has a sampling rule reference, propagate it
138
+ // Otherwise, propagate the matched sampling rule using AwsSamplingResult
137
139
String ruleToPropagate =
138
140
upstreamMatchedRule == null ? applier .getRuleName () : upstreamMatchedRule ;
139
141
if (this .adaptiveSamplingConfig != null
@@ -199,6 +201,15 @@ void adaptSampling(ReadableSpan span, SpanData spanData, Consumer<ReadableSpan>
199
201
operation = generateIngressOperation (spanData );
200
202
}
201
203
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
+ }
202
213
// Check if the operation matches any in the list or if operations list is null (match all)
203
214
List <String > operations = condition .getOperations ();
204
215
if (!(operations == null || operations .isEmpty () || operations .contains (operation ))) {
@@ -253,15 +264,15 @@ void adaptSampling(ReadableSpan span, SpanData spanData, Consumer<ReadableSpan>
253
264
boolean isLocalRootSpan =
254
265
parentContext == null || !parentContext .isValid () || parentContext .isRemote ();
255
266
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
+ }
263
273
264
- // Sampling Boost
274
+ // Sampling Boost
275
+ if (shouldBoostSampling || isLocalRootSpan ) {
265
276
String ruleNameForBoostStats =
266
277
span .getSpanContext ()
267
278
.getTraceState ()
0 commit comments