Skip to content

Commit

Permalink
Use alwaysOn() sampler (#42)
Browse files Browse the repository at this point in the history
* Use alwaysOn() sampler

* spotless

* fix failing smoke test
  • Loading branch information
Mateusz Rzeszutek authored Nov 23, 2020
1 parent 16fb338 commit cfe687f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.opentelemetry.javaagent.spi.TracerCustomizer;
import io.opentelemetry.sdk.trace.TracerSdkManagement;
import io.opentelemetry.sdk.trace.samplers.Sampler;

public class SplunkTracerCustomizer implements TracerCustomizer {

Expand All @@ -42,5 +43,8 @@ public void configure(TracerSdkManagement tracerManagement) {
if (jdbcSpanLowCardinalityNameEnabled()) {
tracerManagement.addSpanProcessor(new JdbcSpanRenamingProcessor());
}

tracerManagement.updateActiveTraceConfig(
tracerManagement.getActiveTraceConfig().toBuilder().setSampler(Sampler.alwaysOn()).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,46 @@
package com.splunk.opentelemetry;

import static com.splunk.opentelemetry.SplunkTracerCustomizer.ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;

import io.opentelemetry.sdk.trace.TracerSdkProvider;
import io.opentelemetry.sdk.trace.config.TraceConfig;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class SplunkTracerCustomizerTest {
@Mock private TracerSdkProvider tracerSdkProvider;

@Captor private ArgumentCaptor<TraceConfig> traceConfigCaptor;

@Test
public void shouldAddSpanProcessorsIfPropertiesAreSetToTrue() {

// given
SplunkTracerCustomizer underTest = new SplunkTracerCustomizer();
System.setProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY, "true");

TraceConfig traceConfig = TraceConfig.getDefault();
given(tracerSdkProvider.getActiveTraceConfig()).willReturn(traceConfig);

// when
underTest.configure(tracerSdkProvider);

// then
then(tracerSdkProvider).should().addSpanProcessor(isA(JdbcSpanRenamingProcessor.class));
then(tracerSdkProvider).should().updateActiveTraceConfig(traceConfigCaptor.capture());
then(tracerSdkProvider).shouldHaveNoMoreInteractions();

assertEquals(Sampler.alwaysOn(), traceConfigCaptor.getValue().getSampler());
}

@Test
Expand All @@ -52,25 +66,36 @@ public void shouldNotAddSpanProcessorsIfPropertiesAreSetToAnythingElse() {
SplunkTracerCustomizer underTest = new SplunkTracerCustomizer();
System.setProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY, "whatever");

TraceConfig traceConfig = TraceConfig.getDefault();
given(tracerSdkProvider.getActiveTraceConfig()).willReturn(traceConfig);

// when
underTest.configure(tracerSdkProvider);

// then
then(tracerSdkProvider).shouldHaveNoInteractions();
then(tracerSdkProvider).should().updateActiveTraceConfig(traceConfigCaptor.capture());
then(tracerSdkProvider).shouldHaveNoMoreInteractions();

assertEquals(Sampler.alwaysOn(), traceConfigCaptor.getValue().getSampler());
}

@Test
public void shouldConfigureTracerSdkForDefaultValues() {

// given
SplunkTracerCustomizer underTest = new SplunkTracerCustomizer();
System.clearProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY);

TraceConfig traceConfig = TraceConfig.getDefault();
given(tracerSdkProvider.getActiveTraceConfig()).willReturn(traceConfig);

// when
underTest.configure(tracerSdkProvider);

// then
then(tracerSdkProvider).should().addSpanProcessor(isA(JdbcSpanRenamingProcessor.class));
then(tracerSdkProvider).should().updateActiveTraceConfig(traceConfigCaptor.capture());
then(tracerSdkProvider).shouldHaveNoMoreInteractions();

assertEquals(Sampler.alwaysOn(), traceConfigCaptor.getValue().getSampler());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
class SpringBootSmokeTest extends SmokeTest {

private String getTargetImage(int jdk) {
return "open-telemetry-docker-dev.bintray.io/java/smoke-springboot-jdk" + jdk + ":latest";
return "open-telemetry-docker-dev.bintray.io/java/smoke-springboot-jdk"
+ jdk
+ ":20201105.347264626";
}

@ParameterizedTest(name = "{index} => SpringBoot SmokeTest On JDK{0}.")
Expand Down

0 comments on commit cfe687f

Please sign in to comment.