Skip to content

Commit 1eea193

Browse files
[Adaptive Sampling] Ensure sampling rule propagation across AWS accounts (#1188)
1 parent 899f40e commit 1eea193

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

.github/patches/opentelemetry-java-contrib.patch

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ index 1ef8abf5..328e63dd 100644
962962
}
963963
}
964964
diff --git a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java
965-
index 75977dc0..a605bfdc 100644
965+
index 75977dc0..fae13433 100644
966966
--- a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java
967967
+++ b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java
968968
@@ -5,42 +5,81 @@
@@ -1111,7 +1111,7 @@ index 75977dc0..a605bfdc 100644
11111111
}
11121112

11131113
@Override
1114-
@@ -74,10 +151,44 @@ final class XrayRulesSampler implements Sampler {
1114+
@@ -74,10 +151,43 @@ final class XrayRulesSampler implements Sampler {
11151115
SpanKind spanKind,
11161116
Attributes attributes,
11171117
List<LinkData> parentLinks) {
@@ -1137,15 +1137,14 @@ index 75977dc0..a605bfdc 100644
11371137
+ // If the trace state has a sampling rule reference, propagate it
11381138
+ // Otherwise, encode and propagate the matched sampling rule using AwsSamplingResult
11391139
+ String ruleToPropagate;
1140-
+ boolean isFromUpstream = parentSpanContext.isValid();
11411140
+ if (upstreamMatchedRule != null) {
1142-
+ ruleToPropagate = hashToRuleMap.getOrDefault(upstreamMatchedRule, applier.getRuleName());
1143-
+ } else if (isFromUpstream) {
1141+
+ ruleToPropagate = hashToRuleMap.getOrDefault(upstreamMatchedRule, null);
1142+
+ } else if (parentSpanContext.isValid()) {
11441143
+ ruleToPropagate = null;
11451144
+ } else {
11461145
+ ruleToPropagate = applier.getRuleName();
11471146
+ }
1148-
+ String hashedRule = ruleToHashMap.getOrDefault(ruleToPropagate, ruleToPropagate);
1147+
+ String hashedRule = ruleToHashMap.getOrDefault(ruleToPropagate, upstreamMatchedRule);
11491148
+
11501149
+ return AwsSamplingResult.create(
11511150
+ result.getDecision(),
@@ -1158,7 +1157,7 @@ index 75977dc0..a605bfdc 100644
11581157
}
11591158
}
11601159

1161-
@@ -96,7 +207,97 @@ final class XrayRulesSampler implements Sampler {
1160+
@@ -96,7 +206,97 @@ final class XrayRulesSampler implements Sampler {
11621161
return "XrayRulesSampler{" + Arrays.toString(ruleAppliers) + "}";
11631162
}
11641163

@@ -1257,7 +1256,7 @@ index 75977dc0..a605bfdc 100644
12571256
return Arrays.stream(ruleAppliers)
12581257
.map(rule -> rule.snapshot(now))
12591258
.filter(Objects::nonNull)
1260-
@@ -115,15 +316,16 @@ final class XrayRulesSampler implements Sampler {
1259+
@@ -115,15 +315,16 @@ final class XrayRulesSampler implements Sampler {
12611260
Map<String, SamplingTargetDocument> ruleTargets,
12621261
Set<String> requestedTargetRuleNames,
12631262
Date now) {
@@ -1276,7 +1275,7 @@ index 75977dc0..a605bfdc 100644
12761275
}
12771276
if (requestedTargetRuleNames.contains(rule.getRuleName())) {
12781277
// In practice X-Ray should return a target for any rule we requested but
1279-
@@ -135,6 +337,216 @@ final class XrayRulesSampler implements Sampler {
1278+
@@ -135,6 +336,216 @@ final class XrayRulesSampler implements Sampler {
12801279
return rule;
12811280
})
12821281
.toArray(SamplingRuleApplier[]::new);

0 commit comments

Comments
 (0)