Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alwaysOn() sampler #42

Merged
merged 3 commits into from
Nov 23, 2020
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
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";
Comment on lines +31 to +33
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure that this change is OK, but it seems that the latest image is simply too new, something related to @WithSpan must have changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it got moved to a different package, and a different artifact in the past couple of weeks.

}

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