Skip to content

Commit

Permalink
change polling interval property name to match spec (#6672)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Berg <jberg@newrelic.com>
  • Loading branch information
drewhammond and jack-berg authored Sep 4, 2024
1 parent 09de4bd commit 43be1e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JaegerRemoteSamplerProvider implements ConfigurableSamplerProvider {

private static final Logger LOGGER =
Logger.getLogger(JaegerRemoteSamplerProvider.class.getName());

// visible for testing
static final String ATTRIBUTE_PROPERTY = "otel.resource.attributes";
static final String SERVICE_NAME_PROPERTY = "otel.service.name";
static final String SAMPLER_ARG_PROPERTY = "otel.traces.sampler.arg";
static final String RESOURCE_ATTRIBUTE_SERVICE_NAME_PROPERTY = "service.name";
private static final String ENDPOINT_KEY = "endpoint";
private static final String POLLING_INTERVAL = "pollingInterval";
private static final String POLLING_INTERVAL = "pollingIntervalMs";
private static final String INITIAL_SAMPLING_RATE = "initialSamplingRate";

@Override
Expand All @@ -43,9 +48,23 @@ public Sampler createSampler(ConfigProperties config) {
builder.setEndpoint(endpoint);
}
String pollingInterval = params.get(POLLING_INTERVAL);
// Previously, we mistakenly read from pollingInterval. For backwards compatibility, check
// pollingInterval and log warning if set.
if (pollingInterval == null) {
pollingInterval = params.get("pollingInterval");
if (pollingInterval != null) {
LOGGER.log(
Level.WARNING,
SAMPLER_ARG_PROPERTY
+ " contains deprecated \"pollingInterval\" property. Please use \""
+ POLLING_INTERVAL
+ "\" instead.");
}
}
if (pollingInterval != null) {
builder.setPollingInterval(Integer.valueOf(pollingInterval), TimeUnit.MILLISECONDS);
}

String initialSamplingRate = params.get(INITIAL_SAMPLING_RATE);
if (initialSamplingRate != null) {
builder.setInitialSampler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void serviceProvider() {
.thenReturn("test_service");
HashMap<String, String> samplerArgs = new HashMap<>();
samplerArgs.put("endpoint", "http://localhost:9999");
samplerArgs.put("pollingInterval", "99");
samplerArgs.put("pollingIntervalMs", "99");
double samplingRate = 0.33;
samplerArgs.put("initialSamplingRate", String.valueOf(samplingRate));
when(mockConfig.getMap(JaegerRemoteSamplerProvider.SAMPLER_ARG_PROPERTY))
Expand Down

0 comments on commit 43be1e7

Please sign in to comment.