From c8eeac430e3ae7d64426fc2051fc1548367de9f6 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 28 Nov 2023 14:09:44 -0800 Subject: [PATCH 1/4] new sampler impl --- .../com/splunk/rum/internal/SessionUtils.java | 26 ++++++ .../UInt32QuadXorTraceIdRatioSampler.java | 86 +++++++++++++++++++ .../splunk/rum/internal/SessionUtilsTest.java | 15 ++++ .../UInt32QuadXorTraceIdRatioSamplerTest.java | 37 ++++++++ 4 files changed, 164 insertions(+) create mode 100644 splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java create mode 100644 splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java create mode 100644 splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java create mode 100644 splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java b/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java new file mode 100644 index 00000000..25afd5b8 --- /dev/null +++ b/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java @@ -0,0 +1,26 @@ +package com.splunk.rum.internal; + +import android.util.Log; + +public class SessionUtils { + + /** + * Performs an unsigned 32-bit conversion of the hex session id to a long. + */ + static long convertToUInt32(String sessionId) { + long acc = 0L; + for (int i = 0; i < sessionId.length(); i += 8) { + long chunk = 0; + try { + String chunkString = sessionId.substring(i, i+8); + chunk = Long.parseUnsignedLong(chunkString, 16); + } catch (NumberFormatException e) { + Log.w("SplunkRum", "Error parsing session id into long: " + sessionId); + } + acc = acc ^ chunk; + } + return acc; + } + + +} diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java new file mode 100644 index 00000000..34813c2b --- /dev/null +++ b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java @@ -0,0 +1,86 @@ +package com.splunk.rum.internal; + +import java.util.List; +import java.util.Locale; +import java.util.function.Supplier; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.trace.data.LinkData; +import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.sdk.trace.samplers.SamplingResult; + +/** + * This class is internal and is hence not for public use. + * Its APIs are unstable and can change at any time. + * + * This class is very similar to the SessionIdRatioBasedSampler from + * upstream, but exists in order to perform a trace id into a long calculation + * in a way that is more consistent with iOS and js. + * + * This class should be considered a stop-gap measure until this problem + * is correctly spec'd in otel. + * + */ +public class UInt32QuadXorTraceIdRatioSampler implements Sampler { + static final SamplingResult POSITIVE_SAMPLING_RESULT = SamplingResult.recordAndSample(); + + static final SamplingResult NEGATIVE_SAMPLING_RESULT = SamplingResult.drop(); + private final long idUpperBound; + private final String description; + private final Supplier sessionIdSupplier; + private final Object lock = new Object(); + private String lastSeenSessionId = ""; + private SamplingResult lastSamplingResult = NEGATIVE_SAMPLING_RESULT; + + static Sampler create(double ratio, Supplier sessionIdSupplier) { + // Taken directly mostly from the TraceIdRatioBasedSampler in upstream, with a modification + // to the upper bound to make it within UInt32. + if (ratio < 0.0 || ratio > 1.0) { + throw new IllegalArgumentException("ratio must be in range [0.0, 1.0]"); + } + long idUpperBound; + // Special case the limits, to avoid any possible issues with lack of precision across + // double/long boundaries. For probability == 0.0, we use Long.MIN_VALUE as this guarantees + // that we will never sample a trace, even in the case where the id == Long.MIN_VALUE, since + // Math.Abs(Long.MIN_VALUE) == Long.MIN_VALUE. + if (ratio == 0.0) { + idUpperBound = Long.MIN_VALUE; + } else if (ratio == 1.0) { + idUpperBound = Long.MAX_VALUE; + } else { + idUpperBound = (long) (ratio * 0xFFFFFFFFL); + } + String description = String.format(Locale.getDefault(),"UInt32QuadXorTraceIdRatioSampler{radio:%f}", ratio); + return new UInt32QuadXorTraceIdRatioSampler(idUpperBound, sessionIdSupplier, description); + } + + private UInt32QuadXorTraceIdRatioSampler(long idUpperBound, Supplier sessionIdSupplier, String description) { + this.idUpperBound = idUpperBound; + this.sessionIdSupplier = sessionIdSupplier; + this.description = description; + } + + @Override + public SamplingResult shouldSample(Context parentContext, String traceId, String name, + SpanKind spanKind, Attributes attributes, + List parentLinks) { + String sessionId = sessionIdSupplier.get(); + synchronized(lock){ + if(lastSeenSessionId.equals(sessionId)){ + return lastSamplingResult; + } + lastSeenSessionId = sessionId; + lastSamplingResult = SessionUtils.convertToUInt32(sessionId) < idUpperBound + ? POSITIVE_SAMPLING_RESULT + : NEGATIVE_SAMPLING_RESULT; + return lastSamplingResult; + } + } + + @Override + public String getDescription() { + return description; + } +} diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java new file mode 100644 index 00000000..02aa3d2b --- /dev/null +++ b/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java @@ -0,0 +1,15 @@ +package com.splunk.rum.internal; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class SessionUtilsTest { + + @Test + void testConvert(){ + long result = SessionUtils.convertToUInt32("c06947ed1f53b1a69be3c6899bc11a3e"); + assertEquals(3742903036L, result); + } + +} \ No newline at end of file diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java new file mode 100644 index 00000000..32e3675c --- /dev/null +++ b/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java @@ -0,0 +1,37 @@ +package com.splunk.rum.internal; + +import static com.splunk.rum.internal.UInt32QuadXorTraceIdRatioSampler.NEGATIVE_SAMPLING_RESULT; +import static com.splunk.rum.internal.UInt32QuadXorTraceIdRatioSampler.POSITIVE_SAMPLING_RESULT; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.sdk.trace.samplers.SamplingResult; + +class UInt32QuadXorTraceIdRatioSamplerTest { + + private final Context parentContext = Context.root().with(Span.getInvalid()); + @Test + void sampleInclude(){ + Sampler sampler = UInt32QuadXorTraceIdRatioSampler.create(0.5, () -> "4777abcd3f7777abcdefc6899bc11a3e"); + SamplingResult result = sampler.shouldSample(parentContext, null, null, null, Attributes.empty(), + Collections.emptyList()); + assertEquals(POSITIVE_SAMPLING_RESULT.getDecision(), result.getDecision()); + } + + @Test + void sampleDrop(){ + Sampler sampler = UInt32QuadXorTraceIdRatioSampler.create(0.5, () -> "9777abcd3f7777abcdefc6899bc11a3e"); + SamplingResult result = sampler.shouldSample(parentContext, null, null, null, Attributes.empty(), + Collections.emptyList()); + assertEquals(NEGATIVE_SAMPLING_RESULT.getDecision(), result.getDecision()); + } + + +} \ No newline at end of file From c914679f31cb8c9fcd60fc1858adad42c6e82733 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 28 Nov 2023 15:09:04 -0800 Subject: [PATCH 2/4] add the UInt32QuadXorTraceIdRatioSampler to better align with the experience on web and ios. --- .../java/com/splunk/rum/RumInitializer.java | 19 +++-- .../com/splunk/rum/internal/SessionUtils.java | 24 +++++-- .../UInt32QuadXorTraceIdRatioSampler.java | 71 +++++++++++++------ .../splunk/rum/internal/SessionUtilsTest.java | 21 +++++- .../UInt32QuadXorTraceIdRatioSamplerTest.java | 71 +++++++++++++++---- 5 files changed, 156 insertions(+), 50 deletions(-) diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java b/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java index b078e4c5..3da85465 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/RumInitializer.java @@ -31,11 +31,11 @@ import android.os.Looper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.splunk.rum.internal.UInt32QuadXorTraceIdRatioSampler; import io.opentelemetry.android.GlobalAttributesSpanAppender; import io.opentelemetry.android.OpenTelemetryRum; import io.opentelemetry.android.OpenTelemetryRumBuilder; import io.opentelemetry.android.RuntimeDetailsExtractor; -import io.opentelemetry.android.SessionIdRatioBasedSampler; import io.opentelemetry.android.instrumentation.activity.VisibleScreenTracker; import io.opentelemetry.android.instrumentation.anr.AnrDetector; import io.opentelemetry.android.instrumentation.crash.CrashReporter; @@ -57,8 +57,10 @@ import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; import io.opentelemetry.sdk.trace.export.SpanExporter; +import io.opentelemetry.sdk.trace.samplers.Sampler; import java.time.Duration; import java.util.Collection; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import java.util.function.Supplier; import java.util.logging.Level; @@ -149,13 +151,20 @@ SplunkRum initialize( .build())); // Set up the sampler, if enabled + // TODO: Make this better... + // This holder is required because we cannot reasonably get the session id until after + // OpenTelemetryRum has been created. So this is spackled into place below. + AtomicReference> sessionSupplierHolder = new AtomicReference<>(() -> null); if (builder.sessionBasedSamplerEnabled) { otelRumBuilder.addTracerProviderCustomizer( (tracerProviderBuilder, app) -> { - SessionIdRatioBasedSampler sampler = - new SessionIdRatioBasedSampler( + Sampler sampler = + UInt32QuadXorTraceIdRatioSampler.create( builder.sessionBasedSamplerRatio, - otelRumBuilder.getSessionId()); + () -> { + Supplier supplier = sessionSupplierHolder.get(); + return supplier == null ? null : supplier.get(); + }); return tracerProviderBuilder.setSampler(sampler); }); } @@ -210,6 +219,8 @@ SplunkRum initialize( OpenTelemetryRum openTelemetryRum = otelRumBuilder.build(); + sessionSupplierHolder.set(openTelemetryRum::getRumSessionId); + initializationEvents.recordInitializationSpans( builder.getConfigFlags(), openTelemetryRum.getOpenTelemetry().getTracer(RUM_TRACER_NAME)); diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java b/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java index 25afd5b8..9afeea5b 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/internal/SessionUtils.java @@ -1,18 +1,32 @@ +/* + * Copyright Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.splunk.rum.internal; import android.util.Log; public class SessionUtils { - /** - * Performs an unsigned 32-bit conversion of the hex session id to a long. - */ + /** Performs an unsigned 32-bit conversion of the hex session id to a long. */ static long convertToUInt32(String sessionId) { long acc = 0L; for (int i = 0; i < sessionId.length(); i += 8) { long chunk = 0; try { - String chunkString = sessionId.substring(i, i+8); + String chunkString = sessionId.substring(i, i + 8); chunk = Long.parseUnsignedLong(chunkString, 16); } catch (NumberFormatException e) { Log.w("SplunkRum", "Error parsing session id into long: " + sessionId); @@ -21,6 +35,4 @@ static long convertToUInt32(String sessionId) { } return acc; } - - } diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java index 34813c2b..4d3747ae 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java @@ -1,8 +1,20 @@ -package com.splunk.rum.internal; +/* + * Copyright Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import java.util.List; -import java.util.Locale; -import java.util.function.Supplier; +package com.splunk.rum.internal; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; @@ -10,18 +22,19 @@ import io.opentelemetry.sdk.trace.data.LinkData; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.SamplingResult; +import java.util.List; +import java.util.Locale; +import java.util.function.Supplier; /** - * This class is internal and is hence not for public use. - * Its APIs are unstable and can change at any time. - * - * This class is very similar to the SessionIdRatioBasedSampler from - * upstream, but exists in order to perform a trace id into a long calculation - * in a way that is more consistent with iOS and js. + * This class is very similar to the SessionIdRatioBasedSampler from upstream, but exists in order + * to perform a trace id into a long calculation in a way that is more consistent with iOS and js. * - * This class should be considered a stop-gap measure until this problem - * is correctly spec'd in otel. + *

This class should be considered a stop-gap measure until this problem is correctly spec'd in + * otel. * + *

This class is internal and is hence not for public use. Its APIs are unstable and can change + * at any time. */ public class UInt32QuadXorTraceIdRatioSampler implements Sampler { static final SamplingResult POSITIVE_SAMPLING_RESULT = SamplingResult.recordAndSample(); @@ -34,7 +47,7 @@ public class UInt32QuadXorTraceIdRatioSampler implements Sampler { private String lastSeenSessionId = ""; private SamplingResult lastSamplingResult = NEGATIVE_SAMPLING_RESULT; - static Sampler create(double ratio, Supplier sessionIdSupplier) { + public static Sampler create(double ratio, Supplier sessionIdSupplier) { // Taken directly mostly from the TraceIdRatioBasedSampler in upstream, with a modification // to the upper bound to make it within UInt32. if (ratio < 0.0 || ratio > 1.0) { @@ -52,29 +65,41 @@ static Sampler create(double ratio, Supplier sessionIdSupplier) { } else { idUpperBound = (long) (ratio * 0xFFFFFFFFL); } - String description = String.format(Locale.getDefault(),"UInt32QuadXorTraceIdRatioSampler{radio:%f}", ratio); + String description = + String.format( + Locale.getDefault(), "UInt32QuadXorTraceIdRatioSampler{radio:%f}", ratio); return new UInt32QuadXorTraceIdRatioSampler(idUpperBound, sessionIdSupplier, description); } - private UInt32QuadXorTraceIdRatioSampler(long idUpperBound, Supplier sessionIdSupplier, String description) { + private UInt32QuadXorTraceIdRatioSampler( + long idUpperBound, Supplier sessionIdSupplier, String description) { this.idUpperBound = idUpperBound; this.sessionIdSupplier = sessionIdSupplier; this.description = description; } @Override - public SamplingResult shouldSample(Context parentContext, String traceId, String name, - SpanKind spanKind, Attributes attributes, - List parentLinks) { + public SamplingResult shouldSample( + Context parentContext, + String traceId, + String name, + SpanKind spanKind, + Attributes attributes, + List parentLinks) { String sessionId = sessionIdSupplier.get(); - synchronized(lock){ - if(lastSeenSessionId.equals(sessionId)){ + if (sessionId == null) { + return POSITIVE_SAMPLING_RESULT; // Have to return true because we may not have a + // session yet + } + synchronized (lock) { + if (lastSeenSessionId.equals(sessionId)) { return lastSamplingResult; } lastSeenSessionId = sessionId; - lastSamplingResult = SessionUtils.convertToUInt32(sessionId) < idUpperBound - ? POSITIVE_SAMPLING_RESULT - : NEGATIVE_SAMPLING_RESULT; + lastSamplingResult = + SessionUtils.convertToUInt32(sessionId) < idUpperBound + ? POSITIVE_SAMPLING_RESULT + : NEGATIVE_SAMPLING_RESULT; return lastSamplingResult; } } diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java index 02aa3d2b..58b66799 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/internal/SessionUtilsTest.java @@ -1,3 +1,19 @@ +/* + * Copyright Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.splunk.rum.internal; import static org.junit.jupiter.api.Assertions.*; @@ -7,9 +23,8 @@ class SessionUtilsTest { @Test - void testConvert(){ + void testConvert() { long result = SessionUtils.convertToUInt32("c06947ed1f53b1a69be3c6899bc11a3e"); assertEquals(3742903036L, result); } - -} \ No newline at end of file +} diff --git a/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java b/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java index 32e3675c..6b86f489 100644 --- a/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java +++ b/splunk-otel-android/src/test/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSamplerTest.java @@ -1,37 +1,80 @@ +/* + * Copyright Splunk Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.splunk.rum.internal; import static com.splunk.rum.internal.UInt32QuadXorTraceIdRatioSampler.NEGATIVE_SAMPLING_RESULT; import static com.splunk.rum.internal.UInt32QuadXorTraceIdRatioSampler.POSITIVE_SAMPLING_RESULT; import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; - -import java.util.Collections; - import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.sdk.trace.samplers.Sampler; import io.opentelemetry.sdk.trace.samplers.SamplingResult; +import java.util.Collections; +import org.junit.jupiter.api.Test; class UInt32QuadXorTraceIdRatioSamplerTest { private final Context parentContext = Context.root().with(Span.getInvalid()); + @Test - void sampleInclude(){ - Sampler sampler = UInt32QuadXorTraceIdRatioSampler.create(0.5, () -> "4777abcd3f7777abcdefc6899bc11a3e"); - SamplingResult result = sampler.shouldSample(parentContext, null, null, null, Attributes.empty(), - Collections.emptyList()); + void sampleInclude() { + Sampler sampler = + UInt32QuadXorTraceIdRatioSampler.create( + 0.5, () -> "4777abcd3f7777abcdefc6899bc11a3e"); + SamplingResult result = + sampler.shouldSample( + parentContext, + null, + null, + null, + Attributes.empty(), + Collections.emptyList()); assertEquals(POSITIVE_SAMPLING_RESULT.getDecision(), result.getDecision()); } @Test - void sampleDrop(){ - Sampler sampler = UInt32QuadXorTraceIdRatioSampler.create(0.5, () -> "9777abcd3f7777abcdefc6899bc11a3e"); - SamplingResult result = sampler.shouldSample(parentContext, null, null, null, Attributes.empty(), - Collections.emptyList()); + void sampleDrop() { + Sampler sampler = + UInt32QuadXorTraceIdRatioSampler.create( + 0.5, () -> "9777abcd3f7777abcdefc6899bc11a3e"); + SamplingResult result = + sampler.shouldSample( + parentContext, + null, + null, + null, + Attributes.empty(), + Collections.emptyList()); assertEquals(NEGATIVE_SAMPLING_RESULT.getDecision(), result.getDecision()); } - -} \ No newline at end of file + @Test + void nullSessionMeansAlwaysPositive() { + Sampler sampler = UInt32QuadXorTraceIdRatioSampler.create(0.00000001, () -> null); + SamplingResult result = + sampler.shouldSample( + parentContext, + null, + null, + null, + Attributes.empty(), + Collections.emptyList()); + assertEquals(POSITIVE_SAMPLING_RESULT.getDecision(), result.getDecision()); + } +} From 8578dce58fc6e5e9124a41425bd17c5e3b2ce51f Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 28 Nov 2023 15:13:37 -0800 Subject: [PATCH 3/4] add comment --- .../splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java index 4d3747ae..7a2937ce 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java @@ -63,6 +63,7 @@ public static Sampler create(double ratio, Supplier sessionIdSupplier) { } else if (ratio == 1.0) { idUpperBound = Long.MAX_VALUE; } else { + // ratio * UInt32 max value idUpperBound = (long) (ratio * 0xFFFFFFFFL); } String description = From 49ff74766a88ac46fb3de2d23a987d9aef7132bd Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Thu, 30 Nov 2023 14:32:24 -0800 Subject: [PATCH 4/4] typo --- .../splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java index 7a2937ce..e995aa9b 100644 --- a/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java +++ b/splunk-otel-android/src/main/java/com/splunk/rum/internal/UInt32QuadXorTraceIdRatioSampler.java @@ -68,7 +68,7 @@ public static Sampler create(double ratio, Supplier sessionIdSupplier) { } String description = String.format( - Locale.getDefault(), "UInt32QuadXorTraceIdRatioSampler{radio:%f}", ratio); + Locale.getDefault(), "UInt32QuadXorTraceIdRatioSampler{ratio:%f}", ratio); return new UInt32QuadXorTraceIdRatioSampler(idUpperBound, sessionIdSupplier, description); }