From 5d07e672c1a8c6a22848a4838998dcd7c2e94267 Mon Sep 17 00:00:00 2001 From: Mahad Janjua Date: Wed, 10 Sep 2025 16:00:19 -0700 Subject: [PATCH 1/2] [AdaptiveSampling] Improve sampling rule propagation + other improvements --- .github/actions/patch-dependencies/action.yml | 22 + .../patches/opentelemetry-java-contrib.patch | 429 ++++++++++++------ .../opentelemetry-java-instrumentation.patch | 28 ++ .github/scripts/patch.sh | 13 + dependencyManagement/build.gradle.kts | 2 +- lambda-layer/build-layer.sh | 3 + .../aws-otel-java-instrumentation.patch | 2 +- .../opentelemetry-java-instrumentation.patch | 4 +- scripts/local_patch.sh | 24 + 9 files changed, 381 insertions(+), 146 deletions(-) create mode 100644 .github/patches/opentelemetry-java-instrumentation.patch diff --git a/.github/actions/patch-dependencies/action.yml b/.github/actions/patch-dependencies/action.yml index 9281534275..55399a6a02 100644 --- a/.github/actions/patch-dependencies/action.yml +++ b/.github/actions/patch-dependencies/action.yml @@ -49,6 +49,9 @@ runs: if [[ -f .github/patches/opentelemetry-java.patch ]]; then echo 'patch_otel_java=true' >> $GITHUB_ENV fi + if [[ -f .github/patches/opentelemetry-java-instrumentation.patch ]]; then + echo 'patch_otel_java_instrumentation=true' >> $GITHUB_ENV + fi if [[ -f .github/patches/opentelemetry-java-contrib.patch ]]; then echo 'patch_otel_java_contrib=true' >> $GITHUB_ENV fi @@ -97,3 +100,22 @@ runs: run: rm -rf opentelemetry-java-contrib if: ${{ env.patch_otel_java_contrib == 'true' }} shell: bash + + - name: Build opentelemetry-java-instrumentation with tests + uses: gradle/gradle-build-action@v2 + if: ${{ env.patch_otel_java_instrumentation == 'true' && inputs.run_tests != 'false' }} + with: + arguments: check -x spotlessCheck publishToMavenLocal + build-root-directory: opentelemetry-java-instrumentation + + - name: Build opentelemetry java instrumentation + uses: gradle/gradle-build-action@v2 + if: ${{ env.patch_otel_java_instrumentation == 'true' && inputs.run_tests == 'false' }} + with: + arguments: publishToMavenLocal + build-root-directory: opentelemetry-java-instrumentation + + - name: cleanup opentelmetry-java-instrumentation + run: rm -rf opentelemetry-java-instrumentation + if: ${{ env.patch_otel_java_instrumentation == 'true' }} + shell: bash \ No newline at end of file diff --git a/.github/patches/opentelemetry-java-contrib.patch b/.github/patches/opentelemetry-java-contrib.patch index dc86f4767b..1a51463191 100644 --- a/.github/patches/opentelemetry-java-contrib.patch +++ b/.github/patches/opentelemetry-java-contrib.patch @@ -1,3 +1,52 @@ +diff --git a/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java b/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java +index 2d8de301..54e26e12 100644 +--- a/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java ++++ b/aws-xray-propagator/src/main/java/io/opentelemetry/contrib/awsxray/propagator/AwsXrayPropagator.java +@@ -68,6 +68,9 @@ public final class AwsXrayPropagator implements TextMapPropagator { + private static final char IS_SAMPLED = '1'; + private static final char NOT_SAMPLED = '0'; + ++ // Copied from AwsSamplingResult in aws-xray extension ++ private static final String AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY = "xrsr"; ++ + private static final List FIELDS = Collections.singletonList(TRACE_HEADER_KEY); + + private static final AwsXrayPropagator INSTANCE = new AwsXrayPropagator(); +@@ -127,6 +130,16 @@ public final class AwsXrayPropagator implements TextMapPropagator { + .append(samplingFlag); + + Baggage baggage = Baggage.fromContext(context); ++ // Get sampling rule from trace state and inject into baggage ++ // This is a back up in case the next service does not have trace state propagation ++ String ruleFromTraceState = ++ spanContext.getTraceState().get(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY); ++ if (ruleFromTraceState != null) { ++ baggage = ++ baggage.toBuilder() ++ .put(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY, ruleFromTraceState) ++ .build(); ++ } + // Truncate baggage to 256 chars per X-Ray spec. + baggage.forEach( + new BiConsumer() { +@@ -236,13 +249,15 @@ public final class AwsXrayPropagator implements TextMapPropagator { + if (spanId == null || traceId == null) { + logger.finest("Both traceId and spanId are required to extract a valid span context. "); + } +- ++ SpanContext upstreamSpanContext = Span.fromContext(context).getSpanContext(); + SpanContext spanContext = + SpanContext.createFromRemoteParent( + StringUtils.padLeft(traceId, TraceId.getLength()), + spanId, + isSampled ? TraceFlags.getSampled() : TraceFlags.getDefault(), +- TraceState.getDefault()); ++ upstreamSpanContext.isValid() ++ ? upstreamSpanContext.getTraceState() ++ : TraceState.getDefault()); + if (spanContext.isValid()) { + context = context.with(Span.wrap(spanContext)); + } diff --git a/aws-xray/build.gradle.kts b/aws-xray/build.gradle.kts index ccec9d52..fddbad18 100644 --- a/aws-xray/build.gradle.kts @@ -20,10 +69,10 @@ index ccec9d52..fddbad18 100644 testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure") diff --git a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSamplingResult.java b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSamplingResult.java new file mode 100644 -index 00000000..41f22f90 +index 00000000..4aed8959 --- /dev/null +++ b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/AwsSamplingResult.java -@@ -0,0 +1,54 @@ +@@ -0,0 +1,56 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 @@ -35,6 +84,7 @@ index 00000000..41f22f90 +import io.opentelemetry.api.trace.TraceState; +import io.opentelemetry.sdk.trace.samplers.SamplingDecision; +import io.opentelemetry.sdk.trace.samplers.SamplingResult; ++import javax.annotation.Nullable; + +final class AwsSamplingResult implements SamplingResult { + @@ -44,17 +94,17 @@ index 00000000..41f22f90 + + private final SamplingDecision decision; + private final Attributes attributes; -+ private final String samplingRuleName; ++ @Nullable private final String samplingRuleName; + + private AwsSamplingResult( -+ SamplingDecision decision, Attributes attributes, String samplingRuleName) { ++ SamplingDecision decision, Attributes attributes, @Nullable String samplingRuleName) { + this.decision = decision; + this.attributes = attributes; + this.samplingRuleName = samplingRuleName; + } + + static AwsSamplingResult create( -+ SamplingDecision decision, Attributes attributes, String samplingRuleName) { ++ SamplingDecision decision, Attributes attributes, @Nullable String samplingRuleName) { + return new AwsSamplingResult(decision, attributes, samplingRuleName); + } + @@ -70,7 +120,8 @@ index 00000000..41f22f90 + + @Override + public TraceState getUpdatedTraceState(TraceState parentTraceState) { -+ if (parentTraceState.get(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY) == null) { ++ if (parentTraceState.get(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY) == null ++ && this.samplingRuleName != null) { + return parentTraceState.toBuilder() + .put(AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY, samplingRuleName) + .build(); @@ -911,10 +962,10 @@ index 1ef8abf5..328e63dd 100644 } } 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 -index 75977dc0..406941ba 100644 +index 75977dc0..a605bfdc 100644 --- a/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java +++ b/aws-xray/src/main/java/io/opentelemetry/contrib/awsxray/XrayRulesSampler.java -@@ -5,42 +5,79 @@ +@@ -5,42 +5,81 @@ package io.opentelemetry.contrib.awsxray; @@ -922,9 +973,11 @@ index 75977dc0..406941ba 100644 + +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; ++import io.opentelemetry.api.baggage.Baggage; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Span; ++import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.context.Context; @@ -995,7 +1048,7 @@ index 75977dc0..406941ba 100644 this( clientId, resource, -@@ -49,8 +86,22 @@ final class XrayRulesSampler implements Sampler { +@@ -49,8 +88,22 @@ final class XrayRulesSampler implements Sampler { rules.stream() // Lower priority value takes precedence so normal ascending sort. .sorted(Comparator.comparingInt(GetSamplingRulesResponse.SamplingRule::getPriority)) @@ -1020,7 +1073,7 @@ index 75977dc0..406941ba 100644 } private XrayRulesSampler( -@@ -58,12 +109,36 @@ final class XrayRulesSampler implements Sampler { +@@ -58,12 +111,36 @@ final class XrayRulesSampler implements Sampler { Resource resource, Clock clock, Sampler fallbackSampler, @@ -1058,15 +1111,22 @@ index 75977dc0..406941ba 100644 } @Override -@@ -74,10 +149,36 @@ final class XrayRulesSampler implements Sampler { +@@ -74,10 +151,44 @@ final class XrayRulesSampler implements Sampler { SpanKind spanKind, Attributes attributes, List parentLinks) { ++ SpanContext parentSpanContext = Span.fromContext(parentContext).getSpanContext(); + String upstreamMatchedRule = -+ Span.fromContext(parentContext) -+ .getSpanContext() ++ parentSpanContext + .getTraceState() + .get(AwsSamplingResult.AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY); ++ if (upstreamMatchedRule == null) { ++ Baggage b = Baggage.fromContext(parentContext); ++ upstreamMatchedRule = ++ b != null ++ ? b.getEntryValue(AwsSamplingResult.AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY) ++ : null; ++ } for (SamplingRuleApplier applier : ruleAppliers) { if (applier.matches(attributes, resource)) { - return applier.shouldSample( @@ -1077,27 +1137,28 @@ index 75977dc0..406941ba 100644 + // If the trace state has a sampling rule reference, propagate it + // Otherwise, encode and propagate the matched sampling rule using AwsSamplingResult + String ruleToPropagate; ++ boolean isFromUpstream = parentSpanContext.isValid(); + if (upstreamMatchedRule != null) { + ruleToPropagate = hashToRuleMap.getOrDefault(upstreamMatchedRule, applier.getRuleName()); ++ } else if (isFromUpstream) { ++ ruleToPropagate = null; + } else { + ruleToPropagate = applier.getRuleName(); + } + String hashedRule = ruleToHashMap.getOrDefault(ruleToPropagate, ruleToPropagate); -+ if (this.adaptiveSamplingConfig != null -+ && this.adaptiveSamplingConfig.getAnomalyCaptureLimit() != null) { -+ // If the span is capturable based on local SDK config, add sampling rule attribute -+ return AwsSamplingResult.create( -+ result.getDecision(), -+ result.getAttributes().toBuilder() -+ .put(AWS_XRAY_SAMPLING_RULE.getKey(), ruleToPropagate) -+ .build(), -+ hashedRule); -+ } -+ return AwsSamplingResult.create(result.getDecision(), result.getAttributes(), hashedRule); ++ ++ return AwsSamplingResult.create( ++ result.getDecision(), ++ result.getAttributes().toBuilder() ++ .put( ++ AWS_XRAY_SAMPLING_RULE.getKey(), ++ ruleToPropagate != null ? ruleToPropagate : "UNKNOWN") ++ .build(), ++ hashedRule); } } -@@ -96,7 +197,185 @@ final class XrayRulesSampler implements Sampler { +@@ -96,7 +207,97 @@ final class XrayRulesSampler implements Sampler { return "XrayRulesSampler{" + Arrays.toString(ruleAppliers) + "}"; } @@ -1113,6 +1174,8 @@ index 75977dc0..406941ba 100644 + int anomalyTracesPerSecond = config.getAnomalyCaptureLimit().getAnomalyTracesPerSecond(); + this.anomalyCaptureRateLimiter = + new RateLimiter(anomalyTracesPerSecond, anomalyTracesPerSecond, clock); ++ } else { ++ this.anomalyCaptureRateLimiter = new RateLimiter(1, 1, clock); + } + } + } @@ -1121,81 +1184,10 @@ index 75977dc0..406941ba 100644 + if (!adaptiveSamplingRuleExists && this.adaptiveSamplingConfig == null) { + return; + } -+ Long statusCode = spanData.getAttributes().get(HTTP_RESPONSE_STATUS_CODE); -+ -+ boolean shouldBoostSampling = false; -+ boolean shouldCaptureAnomalySpan = false; + -+ List anomalyConditions = -+ adaptiveSamplingConfig != null ? adaptiveSamplingConfig.getAnomalyConditions() : null; -+ // Empty list -> no conditions will apply and we will not do anything -+ if (anomalyConditions != null && !anomalyConditions.isEmpty()) { -+ String operation = spanData.getAttributes().get(AwsAttributeKeys.AWS_LOCAL_OPERATION); -+ if (operation == null) { -+ operation = generateIngressOperation(spanData); -+ } -+ for (AwsXrayAdaptiveSamplingConfig.AnomalyConditions condition : anomalyConditions) { -+ // Skip condition if it would only re-apply action already being taken -+ if ((shouldBoostSampling -+ && AwsXrayAdaptiveSamplingConfig.UsageType.SAMPLING_BOOST.equals( -+ condition.getUsage())) -+ || (shouldCaptureAnomalySpan -+ && AwsXrayAdaptiveSamplingConfig.UsageType.ANOMALY_TRACE_CAPTURE.equals( -+ condition.getUsage()))) { -+ continue; -+ } -+ // Check if the operation matches any in the list or if operations list is null (match all) -+ List operations = condition.getOperations(); -+ if (!(operations == null || operations.isEmpty() || operations.contains(operation))) { -+ continue; -+ } -+ // Check if any anomalyConditions detect an anomaly either through error code or latency -+ boolean isAnomaly = false; -+ -+ String errorCodeRegex = condition.getErrorCodeRegex(); -+ if (statusCode != null && errorCodeRegex != null) { -+ isAnomaly = statusCode.toString().matches(errorCodeRegex); -+ } -+ -+ Long highLatencyMs = condition.getHighLatencyMs(); -+ if (highLatencyMs != null) { -+ isAnomaly = -+ (errorCodeRegex == null || isAnomaly) -+ && (span.getLatencyNanos() / 1_000_000.0) >= highLatencyMs; -+ } -+ -+ if (isAnomaly) { -+ AwsXrayAdaptiveSamplingConfig.UsageType usage = condition.getUsage(); -+ if (usage != null) { -+ switch (usage) { -+ case BOTH: -+ shouldBoostSampling = true; -+ shouldCaptureAnomalySpan = true; -+ break; -+ case SAMPLING_BOOST: -+ shouldBoostSampling = true; -+ break; -+ case ANOMALY_TRACE_CAPTURE: -+ shouldCaptureAnomalySpan = true; -+ break; -+ default: // do nothing -+ } -+ } else { -+ shouldBoostSampling = true; -+ shouldCaptureAnomalySpan = true; -+ } -+ } -+ if (shouldBoostSampling && shouldCaptureAnomalySpan) { -+ break; -+ } -+ } -+ } else if ((statusCode != null && statusCode > 499) -+ || (statusCode == null -+ && spanData.getStatus() != null -+ && StatusCode.ERROR.equals(spanData.getStatus().getStatusCode()))) { -+ shouldBoostSampling = true; -+ shouldCaptureAnomalySpan = true; -+ } ++ AnomalyDetectionResult result = isAnomaly(span, spanData); ++ boolean shouldBoostSampling = result.shouldBoostSampling(); ++ boolean shouldCaptureAnomalySpan = result.shouldCaptureAnomalySpan(); + + String traceId = spanData.getTraceId(); + AwsXrayAdaptiveSamplingConfig.UsageType existingUsage = traceUsageCache.getIfPresent(traceId); @@ -1219,7 +1211,7 @@ index 75977dc0..406941ba 100644 + span.getSpanContext() + .getTraceState() + .get(AwsSamplingResult.AWS_XRAY_SAMPLING_RULE_TRACE_STATE_KEY); -+ String ruleNameForBoostStats = ++ String upstreamRuleName = + traceStateValue != null + ? hashToRuleMap.getOrDefault(traceStateValue, traceStateValue) + : traceStateValue; @@ -1227,7 +1219,7 @@ index 75977dc0..406941ba 100644 + SamplingRuleApplier matchedRule = null; + for (SamplingRuleApplier applier : ruleAppliers) { + // Rule propagated from when sampling decision was made, otherwise the matched rule -+ if (applier.getRuleName().equals(ruleNameForBoostStats)) { ++ if (applier.getRuleName().equals(upstreamRuleName)) { + ruleToReportTo = applier; + break; + } @@ -1240,7 +1232,8 @@ index 75977dc0..406941ba 100644 + logger.log( + Level.FINE, + "No sampling rule matched the request. This is a bug in either the OpenTelemetry SDK or X-Ray."); -+ } else { ++ } else if (!span.getParentSpanContext().isValid()) { ++ // Span is not from an upstream service, so we should boost the matched rule + ruleToReportTo = matchedRule; + } + } @@ -1257,34 +1250,14 @@ index 75977dc0..406941ba 100644 + } + } + -+ // Any interaction with a cache entry will reset the expiration timer of that entry -+ if (isSpanCaptured && isCountedAsAnomalyForBoost) { -+ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.BOTH); -+ } else if (isSpanCaptured) { -+ if (AwsXrayAdaptiveSamplingConfig.UsageType.isUsedForBoost(existingUsage)) { -+ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.BOTH); -+ } else { -+ this.traceUsageCache.put( -+ traceId, AwsXrayAdaptiveSamplingConfig.UsageType.ANOMALY_TRACE_CAPTURE); -+ } -+ } else if (isCountedAsAnomalyForBoost) { -+ if (AwsXrayAdaptiveSamplingConfig.UsageType.isUsedForAnomalyTraceCapture(existingUsage)) { -+ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.BOTH); -+ } else { -+ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.SAMPLING_BOOST); -+ } -+ } else if (existingUsage != null) { -+ this.traceUsageCache.put(traceId, existingUsage); -+ } else { -+ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.NEITHER); -+ } ++ updateTraceUsageCache(traceId, isSpanCaptured, isCountedAsAnomalyForBoost); + } + + List snapshot(Date now) { return Arrays.stream(ruleAppliers) .map(rule -> rule.snapshot(now)) .filter(Objects::nonNull) -@@ -115,15 +394,16 @@ final class XrayRulesSampler implements Sampler { +@@ -115,15 +316,16 @@ final class XrayRulesSampler implements Sampler { Map ruleTargets, Set requestedTargetRuleNames, Date now) { @@ -1303,7 +1276,7 @@ index 75977dc0..406941ba 100644 } if (requestedTargetRuleNames.contains(rule.getRuleName())) { // In practice X-Ray should return a target for any rule we requested but -@@ -135,6 +415,92 @@ final class XrayRulesSampler implements Sampler { +@@ -135,6 +337,216 @@ final class XrayRulesSampler implements Sampler { return rule; }) .toArray(SamplingRuleApplier[]::new); @@ -1320,6 +1293,85 @@ index 75977dc0..406941ba 100644 + traceUsageCache); + } + ++ private AnomalyDetectionResult isAnomaly(ReadableSpan span, SpanData spanData) { ++ boolean shouldBoostSampling = false; ++ boolean shouldCaptureAnomalySpan = false; ++ Long statusCode = spanData.getAttributes().get(HTTP_RESPONSE_STATUS_CODE); ++ ++ List anomalyConditions = ++ adaptiveSamplingConfig != null ? adaptiveSamplingConfig.getAnomalyConditions() : null; ++ // Empty list -> no conditions will apply and we will not do anything ++ if (anomalyConditions != null) { ++ String operation = spanData.getAttributes().get(AwsAttributeKeys.AWS_LOCAL_OPERATION); ++ if (operation == null) { ++ operation = generateIngressOperation(spanData); ++ } ++ for (AwsXrayAdaptiveSamplingConfig.AnomalyConditions condition : anomalyConditions) { ++ // Skip condition if it would only re-apply action already being taken ++ if ((shouldBoostSampling ++ && AwsXrayAdaptiveSamplingConfig.UsageType.SAMPLING_BOOST.equals( ++ condition.getUsage())) ++ || (shouldCaptureAnomalySpan ++ && AwsXrayAdaptiveSamplingConfig.UsageType.ANOMALY_TRACE_CAPTURE.equals( ++ condition.getUsage()))) { ++ continue; ++ } ++ // Check if the operation matches any in the list or if operations list is null (match all) ++ List operations = condition.getOperations(); ++ if (!(operations == null || operations.isEmpty() || operations.contains(operation))) { ++ continue; ++ } ++ // Check if any anomalyConditions detect an anomaly either through error code or latency ++ boolean isAnomaly = false; ++ ++ String errorCodeRegex = condition.getErrorCodeRegex(); ++ if (statusCode != null && errorCodeRegex != null) { ++ isAnomaly = statusCode.toString().matches(errorCodeRegex); ++ } ++ ++ Long highLatencyMs = condition.getHighLatencyMs(); ++ if (highLatencyMs != null) { ++ isAnomaly = ++ (errorCodeRegex == null || isAnomaly) ++ && (span.getLatencyNanos() / 1_000_000.0) >= highLatencyMs; ++ } ++ ++ if (isAnomaly) { ++ AwsXrayAdaptiveSamplingConfig.UsageType usage = condition.getUsage(); ++ if (usage != null) { ++ switch (usage) { ++ case BOTH: ++ shouldBoostSampling = true; ++ shouldCaptureAnomalySpan = true; ++ break; ++ case SAMPLING_BOOST: ++ shouldBoostSampling = true; ++ break; ++ case ANOMALY_TRACE_CAPTURE: ++ shouldCaptureAnomalySpan = true; ++ break; ++ default: // do nothing ++ } ++ } else { ++ shouldBoostSampling = true; ++ shouldCaptureAnomalySpan = true; ++ } ++ } ++ if (shouldBoostSampling && shouldCaptureAnomalySpan) { ++ break; ++ } ++ } ++ } else if ((statusCode != null && statusCode > 499) ++ || (statusCode == null ++ && spanData.getStatus() != null ++ && StatusCode.ERROR.equals(spanData.getStatus().getStatusCode()))) { ++ shouldBoostSampling = true; ++ shouldCaptureAnomalySpan = true; ++ } ++ ++ return new AnomalyDetectionResult(shouldBoostSampling, shouldCaptureAnomalySpan); ++ } ++ + static boolean isKeyPresent(SpanData span, AttributeKey key) { + return span.getAttributes().get(key) != null; + } @@ -1361,6 +1413,33 @@ index 75977dc0..406941ba 100644 + return "/"; + } + ++ private void updateTraceUsageCache( ++ String traceId, boolean isSpanCaptured, boolean isCountedAsAnomalyForBoost) { ++ AwsXrayAdaptiveSamplingConfig.UsageType existingUsage = traceUsageCache.getIfPresent(traceId); ++ ++ // Any interaction with a cache entry will reset the expiration timer of that entry ++ if (isSpanCaptured && isCountedAsAnomalyForBoost) { ++ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.BOTH); ++ } else if (isSpanCaptured) { ++ if (AwsXrayAdaptiveSamplingConfig.UsageType.isUsedForBoost(existingUsage)) { ++ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.BOTH); ++ } else { ++ this.traceUsageCache.put( ++ traceId, AwsXrayAdaptiveSamplingConfig.UsageType.ANOMALY_TRACE_CAPTURE); ++ } ++ } else if (isCountedAsAnomalyForBoost) { ++ if (AwsXrayAdaptiveSamplingConfig.UsageType.isUsedForAnomalyTraceCapture(existingUsage)) { ++ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.BOTH); ++ } else { ++ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.SAMPLING_BOOST); ++ } ++ } else if (existingUsage != null) { ++ this.traceUsageCache.put(traceId, existingUsage); ++ } else { ++ this.traceUsageCache.put(traceId, AwsXrayAdaptiveSamplingConfig.UsageType.NEITHER); ++ } ++ } ++ + private static Map createRuleHashMaps( + List rules) { + Map ruleToHashMap = new HashMap<>(); @@ -1395,6 +1474,24 @@ index 75977dc0..406941ba 100644 + Cache getTraceUsageCache() { + traceUsageCache.cleanUp(); + return traceUsageCache; ++ } ++ ++ private static class AnomalyDetectionResult { ++ private final boolean shouldBoostSampling; ++ private final boolean shouldCaptureAnomalySpan; ++ ++ public AnomalyDetectionResult(boolean shouldBoostSampling, boolean shouldCaptureAnomalySpan) { ++ this.shouldBoostSampling = shouldBoostSampling; ++ this.shouldCaptureAnomalySpan = shouldCaptureAnomalySpan; ++ } ++ ++ boolean shouldBoostSampling() { ++ return shouldBoostSampling; ++ } ++ ++ boolean shouldCaptureAnomalySpan() { ++ return shouldCaptureAnomalySpan; ++ } } } diff --git a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerTest.java b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/AwsXrayRemoteSamplerTest.java @@ -2034,7 +2131,7 @@ index 6bb6e82a..6d71711b 100644 return applier.shouldSample( Context.current(), diff --git a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/XrayRulesSamplerTest.java b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/XrayRulesSamplerTest.java -index 1ca8df34..72ec524b 100644 +index 1ca8df34..14ebdbda 100644 --- a/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/XrayRulesSamplerTest.java +++ b/aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/XrayRulesSamplerTest.java @@ -5,17 +5,28 @@ @@ -2127,7 +2224,7 @@ index 1ca8df34..72ec524b 100644 TestClock clock = TestClock.create(); XrayRulesSampler sampler = -@@ -103,22 +124,58 @@ class XrayRulesSamplerTest { +@@ -103,22 +124,72 @@ class XrayRulesSamplerTest { Resource.getDefault(), clock, Sampler.alwaysOn(), @@ -2141,7 +2238,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.RECORD_AND_SAMPLE, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "cat-rule") ++ .build(), + XrayRulesSampler.hashRuleName("cat-rule"))); assertThat(doSample(sampler, "cat-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE)); @@ -2149,7 +2248,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.RECORD_AND_SAMPLE, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "cat-rule") ++ .build(), + XrayRulesSampler.hashRuleName("cat-rule"))); assertThat(doSample(sampler, "dog-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE)); @@ -2157,7 +2258,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.RECORD_AND_SAMPLE, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "dog-rule") ++ .build(), + XrayRulesSampler.hashRuleName("dog-rule"))); assertThat(doSample(sampler, "dog-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.DROP)); @@ -2165,7 +2268,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.DROP, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "dog-rule") ++ .build(), + XrayRulesSampler.hashRuleName("dog-rule"))); assertThat(doSample(sampler, "bat-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE)); @@ -2173,7 +2278,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.RECORD_AND_SAMPLE, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "bat-rule") ++ .build(), + XrayRulesSampler.hashRuleName("bat-rule"))); assertThat(doSample(sampler, "bat-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.RECORD_AND_SAMPLE)); @@ -2181,7 +2288,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.RECORD_AND_SAMPLE, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "bat-rule") ++ .build(), + XrayRulesSampler.hashRuleName("bat-rule"))); assertThat(doSample(sampler, "unknown")) - .isEqualTo(SamplingResult.create(SamplingDecision.DROP)); @@ -2189,12 +2298,14 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.DROP, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "default-rule") ++ .build(), + XrayRulesSampler.hashRuleName("default-rule"))); Instant now = Instant.ofEpochSecond(0, clock.now()); assertThat(sampler.snapshot(Date.from(now))).hasSize(4); -@@ -128,10 +185,10 @@ class XrayRulesSamplerTest { +@@ -128,10 +199,10 @@ class XrayRulesSamplerTest { assertThat(sampler.snapshot(Date.from(now))).hasSize(4); SamplingTargetDocument catTarget = @@ -2207,7 +2318,7 @@ index 1ca8df34..72ec524b 100644 clock.advance(Duration.ofSeconds(10)); now = Instant.ofEpochSecond(0, clock.now()); -@@ -145,16 +202,41 @@ class XrayRulesSamplerTest { +@@ -145,16 +216,51 @@ class XrayRulesSamplerTest { .collect(Collectors.toSet()), Date.from(now)); assertThat(doSample(sampler, "dog-service")) @@ -2216,7 +2327,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.RECORD_AND_SAMPLE, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "dog-rule") ++ .build(), + XrayRulesSampler.hashRuleName("dog-rule"))); assertThat(doSample(sampler, "dog-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.DROP)); @@ -2224,7 +2337,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.DROP, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "dog-rule") ++ .build(), + XrayRulesSampler.hashRuleName("dog-rule"))); assertThat(doSample(sampler, "unknown")) - .isEqualTo(SamplingResult.create(SamplingDecision.DROP)); @@ -2232,7 +2347,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.DROP, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "default-rule") ++ .build(), + XrayRulesSampler.hashRuleName("default-rule"))); // Targets overridden to always drop. assertThat(doSample(sampler, "cat-service")) @@ -2241,7 +2358,9 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.DROP, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "cat-rule") ++ .build(), + XrayRulesSampler.hashRuleName("cat-rule"))); assertThat(doSample(sampler, "bat-service")) - .isEqualTo(SamplingResult.create(SamplingDecision.DROP)); @@ -2249,12 +2368,14 @@ index 1ca8df34..72ec524b 100644 + .isEqualTo( + AwsSamplingResult.create( + SamplingDecision.DROP, -+ Attributes.empty(), ++ Attributes.builder() ++ .put(XrayRulesSampler.AWS_XRAY_SAMPLING_RULE, "bat-rule") ++ .build(), + XrayRulesSampler.hashRuleName("bat-rule"))); // Minimum is batTarget, 5s from now assertThat(sampler.nextTargetFetchTimeNanos()) -@@ -169,6 +251,867 @@ class XrayRulesSamplerTest { +@@ -169,6 +275,891 @@ class XrayRulesSamplerTest { assertThat(sampler.snapshot(Date.from(now))).hasSize(4); } @@ -2596,6 +2717,10 @@ index 1ca8df34..72ec524b 100644 + .thenReturn( + SpanContext.create( + "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); ++ when(readableSpanMock.getParentSpanContext()) ++ .thenReturn( ++ SpanContext.create( ++ "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); + SpanData spanDataMock = mock(SpanData.class); + Attributes attributesMock = mock(Attributes.class); + when(spanDataMock.getAttributes()).thenReturn(attributesMock); @@ -2740,6 +2865,10 @@ index 1ca8df34..72ec524b 100644 + .thenReturn( + SpanContext.create( + "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); ++ when(readableSpanMock.getParentSpanContext()) ++ .thenReturn( ++ SpanContext.create( ++ "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); + when(readableSpanMock.getAttribute(any())).thenReturn("test-operation"); + when(readableSpanMock.getLatencyNanos()).thenReturn(1L); + @@ -2808,6 +2937,10 @@ index 1ca8df34..72ec524b 100644 + .thenReturn( + SpanContext.create( + "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); ++ when(readableSpanMock.getParentSpanContext()) ++ .thenReturn( ++ SpanContext.create( ++ "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); + when(readableSpanMock.getAttribute(any())).thenReturn("test-operation"); + when(readableSpanMock.getLatencyNanos()).thenReturn(300_000_000L); // 300 ms + @@ -2877,6 +3010,10 @@ index 1ca8df34..72ec524b 100644 + .thenReturn( + SpanContext.create( + "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); ++ when(readableSpanMock.getParentSpanContext()) ++ .thenReturn( ++ SpanContext.create( ++ "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); + when(readableSpanMock.getAttribute(any())).thenReturn("test-operation"); + when(readableSpanMock.getLatencyNanos()).thenReturn(300_000_000L); // 300 ms + @@ -2962,6 +3099,10 @@ index 1ca8df34..72ec524b 100644 + .thenReturn( + SpanContext.create( + "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); ++ when(readableSpanMock.getParentSpanContext()) ++ .thenReturn( ++ SpanContext.create( ++ "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); + + SpanData spanDataMock = mock(SpanData.class); + Attributes attributesMock = mock(Attributes.class); @@ -3045,6 +3186,10 @@ index 1ca8df34..72ec524b 100644 + .thenReturn( + SpanContext.create( + "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); ++ when(readableSpanMock.getParentSpanContext()) ++ .thenReturn( ++ SpanContext.create( ++ "TRACE_ID", "SPAN_ID", TraceFlags.getDefault(), TraceState.getDefault())); + when(readableSpanMock.getLatencyNanos()).thenReturn(1L); + + SpanData spanDataMock = mock(SpanData.class); diff --git a/.github/patches/opentelemetry-java-instrumentation.patch b/.github/patches/opentelemetry-java-instrumentation.patch new file mode 100644 index 0000000000..05f7b3077d --- /dev/null +++ b/.github/patches/opentelemetry-java-instrumentation.patch @@ -0,0 +1,28 @@ +diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts +index d020848503..88f0a60ac6 100644 +--- a/dependencyManagement/build.gradle.kts ++++ b/dependencyManagement/build.gradle.kts +@@ -100,7 +100,7 @@ val DEPENDENCIES = listOf( + "commons-validator:commons-validator:1.9.0", + "io.netty:netty:3.10.6.Final", + "io.opentelemetry.contrib:opentelemetry-aws-resources:${otelContribVersion}", +- "io.opentelemetry.contrib:opentelemetry-aws-xray-propagator:${otelContribVersion}", ++ "io.opentelemetry.contrib:opentelemetry-aws-xray-propagator:1.39.0-alpha-adot1", + "io.opentelemetry.contrib:opentelemetry-gcp-resources:${otelContribVersion}", + "io.opentelemetry.contrib:opentelemetry-baggage-processor:${otelContribVersion}", + "io.opentelemetry.proto:opentelemetry-proto:1.4.0-alpha", +diff --git a/version.gradle.kts b/version.gradle.kts +index a1cae43b4b..c1520e9947 100644 +--- a/version.gradle.kts ++++ b/version.gradle.kts +@@ -1,5 +1,5 @@ +-val stableVersion = "2.11.0" +-val alphaVersion = "2.11.0-alpha" ++val stableVersion = "2.11.0-adot1" ++val alphaVersion = "2.11.0-adot1-alpha" + + allprojects { + if (findProperty("otel.stable") != "true") { +-- +2.45.1 + diff --git a/.github/scripts/patch.sh b/.github/scripts/patch.sh index b6a6bba94e..9d2c902a61 100755 --- a/.github/scripts/patch.sh +++ b/.github/scripts/patch.sh @@ -44,3 +44,16 @@ if [[ -f "$OTEL_JAVA_CONTRIB_PATCH" ]]; then else echo "Skipping patching opentelemetry-java-contrib" fi + + +OTEL_JAVA_INSTRUMENTATION_PATCH=".github/patches/opentelemetry-java-instrumentation.patch" +if [[ -f "$OTEL_JAVA_INSTRUMENTATION_PATCH" ]]; then + git clone https://github.com/open-telemetry/opentelemetry-java-instrumentation.git + cd opentelemetry-java-instrumentation + git checkout ${OTEL_JAVA_INSTRUMENTATION_VERSION} -b tag-${OTEL_JAVA_INSTRUMENTATION_VERSION} + patch -p1 < "../${OTEL_JAVA_INSTRUMENTATION_PATCH}" + git commit -a -m "ADOT Patch release" + cd - +else + echo "Skipping patching opentelemetry-java-instrumentation" +fi diff --git a/dependencyManagement/build.gradle.kts b/dependencyManagement/build.gradle.kts index 596e09e939..19a1b3b29c 100644 --- a/dependencyManagement/build.gradle.kts +++ b/dependencyManagement/build.gradle.kts @@ -27,7 +27,7 @@ data class DependencySet(val group: String, val version: String, val modules: Li val testSnapshots = rootProject.findProperty("testUpstreamSnapshots") == "true" // This is the version of the upstream instrumentation BOM -val otelVersion = "2.11.0" +val otelVersion = "2.11.0-adot1" val otelSnapshotVersion = "2.12.0" val otelAlphaVersion = if (!testSnapshots) "$otelVersion-alpha" else "$otelSnapshotVersion-alpha-SNAPSHOT" val otelJavaAgentVersion = if (!testSnapshots) otelVersion else "$otelSnapshotVersion-SNAPSHOT" diff --git a/lambda-layer/build-layer.sh b/lambda-layer/build-layer.sh index 8c944191de..36350cd5b1 100755 --- a/lambda-layer/build-layer.sh +++ b/lambda-layer/build-layer.sh @@ -22,6 +22,9 @@ git clone https://github.com/open-telemetry/opentelemetry-java-instrumentation.g pushd opentelemetry-java-instrumentation git checkout v${version} -b tag-v${version} +# There is another patch in the .github/patches directory for other changes. We should apply them too for consistency. +patch -p1 < "$SOURCEDIR"/../.github/patches/opentelemetry-java-instrumentation.patch + # This patch is for Lambda related context propagation patch -p1 < "$SOURCEDIR"/patches/opentelemetry-java-instrumentation.patch diff --git a/lambda-layer/patches/aws-otel-java-instrumentation.patch b/lambda-layer/patches/aws-otel-java-instrumentation.patch index 6b1f5eb9d5..f2e08b6c29 100644 --- a/lambda-layer/patches/aws-otel-java-instrumentation.patch +++ b/lambda-layer/patches/aws-otel-java-instrumentation.patch @@ -6,7 +6,7 @@ index 9493189..6090207 100644 val testSnapshots = rootProject.findProperty("testUpstreamSnapshots") == "true" // This is the version of the upstream instrumentation BOM --val otelVersion = "2.11.0" +-val otelVersion = "2.11.0-adot1" +val otelVersion = "2.11.0-adot-lambda1" val otelSnapshotVersion = "2.12.0" val otelAlphaVersion = if (!testSnapshots) "$otelVersion-alpha" else "$otelSnapshotVersion-alpha-SNAPSHOT" diff --git a/lambda-layer/patches/opentelemetry-java-instrumentation.patch b/lambda-layer/patches/opentelemetry-java-instrumentation.patch index a4004e3330..cca35f0ed0 100644 --- a/lambda-layer/patches/opentelemetry-java-instrumentation.patch +++ b/lambda-layer/patches/opentelemetry-java-instrumentation.patch @@ -310,8 +310,8 @@ index 7900c9a4d9..80383d7c22 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -1,5 +1,5 @@ --val stableVersion = "2.11.0" --val alphaVersion = "2.11.0-alpha" +-val stableVersion = "2.11.0-adot1" +-val alphaVersion = "2.11.0-adot1-alpha" +val stableVersion = "2.11.0-adot-lambda1" +val alphaVersion = "2.11.0-adot-lambda1-alpha" diff --git a/scripts/local_patch.sh b/scripts/local_patch.sh index 079d4516b9..d1c01c5d8b 100755 --- a/scripts/local_patch.sh +++ b/scripts/local_patch.sh @@ -56,4 +56,28 @@ if [[ -f "$OTEL_JAVA_CONTRIB_PATCH" ]]; then rm -rf opentelemetry-java-contrib else echo "Skipping patching opentelemetry-java-contrib" +fi + + +# Patching opentelemetry-java-instrumentation +OTEL_JAVA_INSTRUMENTATION_PATCH=".github/patches/opentelemetry-java-instrumentation.patch" +if [[ -f "$OTEL_JAVA_INSTRUMENTATION_PATCH" ]]; then + echo "Patching opentelemetry-java-instrumentation" + git clone https://github.com/open-telemetry/opentelemetry-java-instrumentation.git + cd opentelemetry-java-instrumentation + + echo "Checking out tag ${OTEL_JAVA_INSTRUMENTATION_VERSION}" + git checkout ${OTEL_JAVA_INSTRUMENTATION_VERSION} -b tag-${OTEL_JAVA_INSTRUMENTATION_VERSION} + patch -p1 < "../${OTEL_JAVA_INSTRUMENTATION_PATCH}" + git commit -a -m "ADOT Patch release" + + echo "Building patched opentelemetry-java-instrumentation" + ./gradlew clean assemble + ./gradlew publishToMavenLocal + cd - + + echo "Cleaning up opentelemetry-java-instrumentation" + rm -rf opentelemetry-java-instrumentation +else + echo "Skipping patching opentelemetry-java-instrumentation" fi \ No newline at end of file From 772b619f9c9d477f73e2d18e015ad5e1b892f637 Mon Sep 17 00:00:00 2001 From: Mahad Janjua Date: Fri, 12 Sep 2025 18:43:11 -0700 Subject: [PATCH 2/2] Fix lambda layer build script --- lambda-layer/build-layer.sh | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lambda-layer/build-layer.sh b/lambda-layer/build-layer.sh index 36350cd5b1..3190182c3b 100755 --- a/lambda-layer/build-layer.sh +++ b/lambda-layer/build-layer.sh @@ -2,11 +2,27 @@ set -e SOURCEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +file="$SOURCEDIR/../.github/patches/versions" + +contrib_version=$(awk -F'=v' '/OTEL_JAVA_CONTRIB_VERSION/ {print $2}' "$file") +if [[ -n "$contrib_version" ]]; then + echo "Found OTEL Contrib Version: ${contrib_version}" + ## Clone and Patch the OpenTelemetry Java contrib Repository + echo "Info: Cloning and Patching OpenTelemetry Java contrib Repository" + git clone https://github.com/open-telemetry/opentelemetry-java-contrib.git + pushd opentelemetry-java-contrib + git checkout v${contrib_version} -b tag-v${contrib_version} + # There is another patch in the .github/patches directory for other changes. We should apply them too for consistency. + patch -p1 < "$SOURCEDIR"/../.github/patches/opentelemetry-java-contrib.patch + + ./gradlew publishToMavenLocal + popd + rm -rf opentelemetry-java-contrib +fi ## Get OTel version echo "Info: Getting OTEL Version" -file="$SOURCEDIR/../.github/patches/versions" version=$(awk -F'=v' '/OTEL_JAVA_INSTRUMENTATION_VERSION/ {print $2}' "$file") echo "Found OTEL Version: ${version}" # Exit if the version is empty or null @@ -34,23 +50,6 @@ patch -p1 < "$SOURCEDIR"/patches/StreamHandlerInstrumentation.patch popd rm -rf opentelemetry-java-instrumentation -contrib_version=$(awk -F'=v' '/OTEL_JAVA_CONTRIB_VERSION/ {print $2}' "$file") -if [[ -n "$contrib_version" ]]; then - echo "Found OTEL Contrib Version: ${contrib_version}" - ## Clone and Patch the OpenTelemetry Java contrib Repository - echo "Info: Cloning and Patching OpenTelemetry Java contrib Repository" - git clone https://github.com/open-telemetry/opentelemetry-java-contrib.git - pushd opentelemetry-java-contrib - git checkout v${contrib_version} -b tag-v${contrib_version} - - # There is another patch in the .github/patches directory for other changes. We should apply them too for consistency. - patch -p1 < "$SOURCEDIR"/../.github/patches/opentelemetry-java-contrib.patch - - ./gradlew publishToMavenLocal - popd - rm -rf opentelemetry-java-contrib -fi - ## Build the ADOT Java from current source echo "Info: Building ADOT Java from current source" pushd "$SOURCEDIR"/..