Skip to content

Commit

Permalink
Support exclusion of non-application URIs if custom Sampler is used
Browse files Browse the repository at this point in the history
  • Loading branch information
mun711 committed Jun 25, 2022
1 parent 748908f commit b398043
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

import javax.enterprise.inject.Any;
Expand Down Expand Up @@ -140,25 +139,14 @@ public void setupSampler(
List<String> dropStaticResources) {

LateBoundSampler lateBoundSampler = CDI.current().select(LateBoundSampler.class, Any.Literal.INSTANCE).get();
Optional<Sampler> samplerBean = CDI.current()
.select(Sampler.class, Any.Literal.INSTANCE)
.stream()
.filter(o -> !(o instanceof LateBoundSampler))
.findFirst();

// Define Sampler using bean if present
if (samplerBean.isPresent()) {
lateBoundSampler.setSamplerDelegate(samplerBean.get());
} else {
List<String> dropNames = new ArrayList<>();
if (config.suppressNonApplicationUris) {
dropNames.addAll(dropNonApplicationUris);
}
if (!config.includeStaticResources) {
dropNames.addAll(dropStaticResources);
}
// Define Sampler using config
lateBoundSampler.setSamplerDelegate(TracerUtil.mapSampler(config.sampler, dropNames));
List<String> dropNames = new ArrayList<>();
if (config.suppressNonApplicationUris) {
dropNames.addAll(dropNonApplicationUris);
}
if (!config.includeStaticResources) {
dropNames.addAll(dropStaticResources);
}
Sampler samplerBean = TracerUtil.mapSampler(config.sampler, dropNames);
lateBoundSampler.setSamplerDelegate(samplerBean);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.List;
import java.util.Optional;

import javax.enterprise.inject.Any;
import javax.enterprise.inject.spi.CDI;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.sdk.resources.Resource;
Expand Down Expand Up @@ -34,8 +37,13 @@ private static Sampler getBaseSampler(String samplerName, Optional<Double> ratio
}
}

public static Sampler mapSampler(TracerRuntimeConfig.SamplerConfig samplerConfig, List<String> dropNames) {
Sampler sampler = getBaseSampler(samplerConfig.samplerName, samplerConfig.ratio);
public static Sampler mapSampler(TracerRuntimeConfig.SamplerConfig samplerConfig,
List<String> dropNames) {
Sampler sampler = CDI.current()
.select(Sampler.class, Any.Literal.INSTANCE)
.stream()
.filter(o -> !(o instanceof LateBoundSampler))
.findFirst().orElseGet(() -> getBaseSampler(samplerConfig.samplerName, samplerConfig.ratio));

if (!dropNames.isEmpty()) {
sampler = new DropNamesSampler(sampler, dropNames);
Expand Down

0 comments on commit b398043

Please sign in to comment.