Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions custom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ dependencies {
compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
compileOnly(libs.bundles.semconv)

implementation(libs.contribConsistentSampling) {
// exclude transitive dependency as it's provided through agent packaging
exclude(group = "io.opentelemetry", module = "opentelemetry-sdk-trace")
exclude(group = "io.opentelemetry", module = "opentelemetry-sdk-extension-autoconfigure-spi")
}
implementation(libs.contribSpanStacktrace) {
// exclude transitive dependency as it's provided through agent packaging
exclude(group = "io.opentelemetry", module = "opentelemetry-sdk")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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 co.elastic.otel.compositesampling;

import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;

@AutoService(ConfigurableSamplerProvider.class)
public class CompositeParentBasedTraceIdRatioBasedSamplerProvider
implements ConfigurableSamplerProvider {

@Override
public Sampler createSampler(ConfigProperties config) {
DynamicCompositeParentBasedTraceIdRatioBasedSampler.setRatio(
config.getDouble(
"otel.traces.sampler.arg",
DynamicCompositeParentBasedTraceIdRatioBasedSampler.DEFAULT_TRACEIDRATIO_SAMPLE_RATIO));
return DynamicCompositeParentBasedTraceIdRatioBasedSampler.INSTANCE;
}

@Override
public String getName() {
return "experimental_composite_parentbased_traceidratio";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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 co.elastic.otel.compositesampling;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.contrib.sampler.consistent56.ConsistentSampler;
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;

public enum DynamicCompositeParentBasedTraceIdRatioBasedSampler implements Sampler {
INSTANCE;

static final double DEFAULT_TRACEIDRATIO_SAMPLE_RATIO = 1.0d;

private static Sampler delegate = newSampler(DEFAULT_TRACEIDRATIO_SAMPLE_RATIO);

public static void setRatio(double ratio) {
delegate = newSampler(ratio);
}

@Override
public SamplingResult shouldSample(
Context parentContext,
String traceId,
String name,
SpanKind spanKind,
Attributes attributes,
List<LinkData> parentLinks) {
return delegate.shouldSample(parentContext, traceId, name, spanKind, attributes, parentLinks);
}

@Override
public String getDescription() {
return INSTANCE.getDescription();
}

private static Sampler newSampler(double ratio) {
return ConsistentSampler.parentBased(ConsistentSampler.probabilityBased(ratio));
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ opentelemetryInstrumentationAlphaBom = { group = "io.opentelemetry.instrumentati

opentelemetryProto = { group = "io.opentelemetry.proto", name = "opentelemetry-proto", version.ref = "opentelemetryProto" }

contribConsistentSampling = { group = "io.opentelemetry.contrib", name = "opentelemetry-consistent-sampling", version.ref = "opentelemetryContribAlpha" }
contribResources = { group = "io.opentelemetry.contrib", name = "opentelemetry-resource-providers", version.ref = "opentelemetryContribAlpha" }
contribSpanStacktrace = { group = "io.opentelemetry.contrib", name = "opentelemetry-span-stacktrace", version.ref = "opentelemetryContribAlpha" }
contribInferredSpans = { group = "io.opentelemetry.contrib", name = "opentelemetry-inferred-spans", version.ref = "opentelemetryContribAlpha" }
Expand Down
Loading