diff --git a/README.md b/README.md index 8aa74d58b..64319bcea 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,6 @@ System property values take priority over corresponding environment variables. ### Splunk distribution configuration | System property | Environment variable | Default value | Notes | | -------------------------------------------------- | ------------------------------------------------- | --------------| --------------------------------------------------------------------------------------------------------------------------------------------- | -| splunk.otel.config.span.processor.instrlib.enabled | SPLUNK_OTEL_CONFIG_SPAN_PROCESSOR_INSTRLIB_ENABLED| `false` | Enables span processing adding library instrumentation properties. Deprecated feature for customers not on the newest OpenTelemetry Collector | | splunk.jdbc.low.cardinality.span.name.enabled | SPLUNK_JDBC_LOW_CARDINALITY_SPAN_NAME_ENABLED | `true` | Enables low cardinality span names for spans generated by the JDBC auto-instrumentation. By default JDBC spans use full SQL queries as their names; when this property is on just the SQL statement type should be used (e.g. `SELECT`, `INSERT`). | ## Manually instrument a Java application diff --git a/custom/src/main/java/com/splunk/opentelemetry/InstrumentationLibrarySpanProcessor.java b/custom/src/main/java/com/splunk/opentelemetry/InstrumentationLibrarySpanProcessor.java deleted file mode 100644 index 1c6619803..000000000 --- a/custom/src/main/java/com/splunk/opentelemetry/InstrumentationLibrarySpanProcessor.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright Splunk Inc. - * - * Licensed 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 com.splunk.opentelemetry; - -import io.opentelemetry.context.Context; -import io.opentelemetry.sdk.common.CompletableResultCode; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; -import io.opentelemetry.sdk.trace.ReadWriteSpan; -import io.opentelemetry.sdk.trace.ReadableSpan; -import io.opentelemetry.sdk.trace.SpanProcessor; - -/** - * Until all Splunk customers migrate to OTLP, we add our own custom span attributes to signal - * instrumentation library name and version. - * - *

As a side note, official OTLP->Zipkin and OTLP->Jaeger translations already specify similar - * conversion, see - * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/zipkin.md#instrumentationlibrary - * and - * https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk_exporters/jaeger.md#instrumentationlibrary - * such translations are not released yet to the Collector. When they reach main branch, this - * processor can be deprecated. - */ -public class InstrumentationLibrarySpanProcessor implements SpanProcessor { - @Override - public void onStart(Context parentContext, ReadWriteSpan span) { - InstrumentationLibraryInfo libraryInfo = span.getInstrumentationLibraryInfo(); - - span.setAttribute("splunk.instrumentation_library.name", libraryInfo.getName()); - if (libraryInfo.getVersion() != null) { - span.setAttribute("splunk.instrumentation_library.version", libraryInfo.getVersion()); - } - } - - @Override - public boolean isStartRequired() { - return true; - } - - @Override - public void onEnd(ReadableSpan span) {} - - @Override - public boolean isEndRequired() { - return false; - } - - @Override - public CompletableResultCode shutdown() { - return CompletableResultCode.ofSuccess(); - } - - @Override - public CompletableResultCode forceFlush() { - return CompletableResultCode.ofSuccess(); - } -} diff --git a/custom/src/main/java/com/splunk/opentelemetry/InstrumentationLibraryTracerCustomizer.java b/custom/src/main/java/com/splunk/opentelemetry/SplunkTracerCustomizer.java similarity index 69% rename from custom/src/main/java/com/splunk/opentelemetry/InstrumentationLibraryTracerCustomizer.java rename to custom/src/main/java/com/splunk/opentelemetry/SplunkTracerCustomizer.java index 2c02fa6e3..3a053d856 100644 --- a/custom/src/main/java/com/splunk/opentelemetry/InstrumentationLibraryTracerCustomizer.java +++ b/custom/src/main/java/com/splunk/opentelemetry/SplunkTracerCustomizer.java @@ -19,10 +19,7 @@ import io.opentelemetry.javaagent.spi.TracerCustomizer; import io.opentelemetry.sdk.trace.TracerSdkManagement; -public class InstrumentationLibraryTracerCustomizer implements TracerCustomizer { - - static final String PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED = - "splunk.otel.config.span.processor.instrlib.enabled"; +public class SplunkTracerCustomizer implements TracerCustomizer { static final String ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY = "splunk.jdbc.low.cardinality.span.name.enabled"; @@ -31,14 +28,6 @@ private static String propertyToEnv(String property) { return property.replace(".", "_").toUpperCase(); } - private static boolean spanProcessorInstrumentationLibraryEnabled() { - String value = System.getProperty(PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED); - if (value == null) { - value = System.getenv(propertyToEnv(PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED)); - } - return Boolean.parseBoolean(value); - } - private static boolean jdbcSpanLowCardinalityNameEnabled() { String value = System.getProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY); if (value == null) { @@ -50,9 +39,6 @@ private static boolean jdbcSpanLowCardinalityNameEnabled() { @Override public void configure(TracerSdkManagement tracerManagement) { - if (spanProcessorInstrumentationLibraryEnabled()) { - tracerManagement.addSpanProcessor(new InstrumentationLibrarySpanProcessor()); - } if (jdbcSpanLowCardinalityNameEnabled()) { tracerManagement.addSpanProcessor(new JdbcSpanRenamingProcessor()); } diff --git a/custom/src/main/resources/META-INF/services/io.opentelemetry.javaagent.spi.TracerCustomizer b/custom/src/main/resources/META-INF/services/io.opentelemetry.javaagent.spi.TracerCustomizer index 087d71b5d..889c95d20 100644 --- a/custom/src/main/resources/META-INF/services/io.opentelemetry.javaagent.spi.TracerCustomizer +++ b/custom/src/main/resources/META-INF/services/io.opentelemetry.javaagent.spi.TracerCustomizer @@ -1 +1 @@ -com.splunk.opentelemetry.InstrumentationLibraryTracerCustomizer \ No newline at end of file +com.splunk.opentelemetry.SplunkTracerCustomizer \ No newline at end of file diff --git a/custom/src/test/java/com/splunk/opentelemetry/InstrumentationLibrarySpanProcessorTest.java b/custom/src/test/java/com/splunk/opentelemetry/InstrumentationLibrarySpanProcessorTest.java deleted file mode 100644 index f3ffa0eed..000000000 --- a/custom/src/test/java/com/splunk/opentelemetry/InstrumentationLibrarySpanProcessorTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright Splunk Inc. - * - * Licensed 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 com.splunk.opentelemetry; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.StatusCode; -import io.opentelemetry.context.Context; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; -import io.opentelemetry.sdk.trace.ReadWriteSpan; -import io.opentelemetry.sdk.trace.data.SpanData; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -class InstrumentationLibrarySpanProcessorTest { - - @Test - void shouldAddInstrumentationLibrary() { - ReadWriteSpanWithLibrary span = new ReadWriteSpanWithLibrary(); - InstrumentationLibrarySpanProcessor processor = new InstrumentationLibrarySpanProcessor(); - processor.onStart(Context.root(), span); - - Assertions.assertEquals( - "com.splunk.test", - span.attributes.get(AttributeKey.stringKey("splunk.instrumentation_library.name"))); - Assertions.assertEquals( - "1.2.3", - span.attributes.get(AttributeKey.stringKey("splunk.instrumentation_library.version"))); - } - - private static class ReadWriteSpanWithLibrary implements ReadWriteSpan { - - private Attributes attributes = Attributes.empty(); - - @Override - public SpanContext getSpanContext() { - return null; - } - - @Override - public String getName() { - return null; - } - - @Override - public SpanData toSpanData() { - return null; - } - - @Override - public InstrumentationLibraryInfo getInstrumentationLibraryInfo() { - return InstrumentationLibraryInfo.create("com.splunk.test", "1.2.3"); - } - - @Override - public boolean hasEnded() { - return false; - } - - @Override - public long getLatencyNanos() { - return 0; - } - - @Override - public Span setAttribute(String s, String s1) { - attributes = attributes.toBuilder().put(s, s1).build(); - return this; - } - - @Override - public Span setAttribute(String s, long l) { - return this; - } - - @Override - public Span setAttribute(String s, double v) { - return this; - } - - @Override - public Span setAttribute(String s, boolean b) { - return this; - } - - @Override - public Span setAttribute(AttributeKey key, T value) { - return this; - } - - @Override - public Span addEvent(String s) { - return this; - } - - @Override - public Span addEvent(String s, long l) { - return this; - } - - @Override - public Span addEvent(String s, Attributes attributes) { - return this; - } - - @Override - public Span addEvent(String s, Attributes attributes, long l) { - return this; - } - - @Override - public Span setStatus(StatusCode canonicalCode) { - return this; - } - - @Override - public Span setStatus(StatusCode canonicalCode, String description) { - return this; - } - - @Override - public Span recordException(Throwable throwable) { - return this; - } - - @Override - public Span recordException(Throwable throwable, Attributes attributes) { - return this; - } - - @Override - public Span updateName(String s) { - return this; - } - - @Override - public void end() {} - - @Override - public void end(long timestamp) {} - - @Override - public boolean isRecording() { - return false; - } - } -} diff --git a/custom/src/test/java/com/splunk/opentelemetry/InstrumentationLibraryTracerCustomizerTest.java b/custom/src/test/java/com/splunk/opentelemetry/SplunkTracerCustomizerTest.java similarity index 65% rename from custom/src/test/java/com/splunk/opentelemetry/InstrumentationLibraryTracerCustomizerTest.java rename to custom/src/test/java/com/splunk/opentelemetry/SplunkTracerCustomizerTest.java index 095a70b1c..fd8b66615 100644 --- a/custom/src/test/java/com/splunk/opentelemetry/InstrumentationLibraryTracerCustomizerTest.java +++ b/custom/src/test/java/com/splunk/opentelemetry/SplunkTracerCustomizerTest.java @@ -16,11 +16,9 @@ package com.splunk.opentelemetry; -import static com.splunk.opentelemetry.InstrumentationLibraryTracerCustomizer.ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY; -import static com.splunk.opentelemetry.InstrumentationLibraryTracerCustomizer.PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED; +import static com.splunk.opentelemetry.SplunkTracerCustomizer.ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.never; import io.opentelemetry.sdk.trace.TracerSdkProvider; import org.junit.jupiter.api.Test; @@ -29,24 +27,20 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class InstrumentationLibraryTracerCustomizerTest { +public class SplunkTracerCustomizerTest { @Mock private TracerSdkProvider tracerSdkProvider; @Test public void shouldAddSpanProcessorsIfPropertiesAreSetToTrue() { // given - InstrumentationLibraryTracerCustomizer underTest = new InstrumentationLibraryTracerCustomizer(); - System.setProperty(PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED, "true"); + SplunkTracerCustomizer underTest = new SplunkTracerCustomizer(); System.setProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY, "true"); // when underTest.configure(tracerSdkProvider); // then - then(tracerSdkProvider) - .should() - .addSpanProcessor(isA(InstrumentationLibrarySpanProcessor.class)); then(tracerSdkProvider).should().addSpanProcessor(isA(JdbcSpanRenamingProcessor.class)); then(tracerSdkProvider).shouldHaveNoMoreInteractions(); } @@ -55,8 +49,7 @@ public void shouldAddSpanProcessorsIfPropertiesAreSetToTrue() { public void shouldNotAddSpanProcessorsIfPropertiesAreSetToAnythingElse() { // given - InstrumentationLibraryTracerCustomizer underTest = new InstrumentationLibraryTracerCustomizer(); - System.setProperty(PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED, "enabled"); + SplunkTracerCustomizer underTest = new SplunkTracerCustomizer(); System.setProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY, "whatever"); // when @@ -70,17 +63,13 @@ public void shouldNotAddSpanProcessorsIfPropertiesAreSetToAnythingElse() { public void shouldConfigureTracerSdkForDefaultValues() { // given - InstrumentationLibraryTracerCustomizer underTest = new InstrumentationLibraryTracerCustomizer(); - System.clearProperty(PROPERTY_SPAN_PROCESSOR_INSTR_LIB_ENABLED); + SplunkTracerCustomizer underTest = new SplunkTracerCustomizer(); System.clearProperty(ENABLE_JDBC_SPAN_LOW_CARDINALITY_NAME_PROPERTY); // when underTest.configure(tracerSdkProvider); // then - then(tracerSdkProvider) - .should(never()) - .addSpanProcessor(isA(InstrumentationLibrarySpanProcessor.class)); then(tracerSdkProvider).should().addSpanProcessor(isA(JdbcSpanRenamingProcessor.class)); then(tracerSdkProvider).shouldHaveNoMoreInteractions(); } diff --git a/smoke-tests/src/test/java/com/splunk/opentelemetry/SpringBootSmokeTest.java b/smoke-tests/src/test/java/com/splunk/opentelemetry/SpringBootSmokeTest.java index 278dbefa0..fb09c3768 100644 --- a/smoke-tests/src/test/java/com/splunk/opentelemetry/SpringBootSmokeTest.java +++ b/smoke-tests/src/test/java/com/splunk/opentelemetry/SpringBootSmokeTest.java @@ -19,7 +19,6 @@ import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest; import java.io.IOException; import java.util.Collection; -import java.util.Map; import java.util.jar.Attributes; import java.util.jar.JarFile; import okhttp3.Request; @@ -34,11 +33,6 @@ protected String getTargetImage(int jdk) { return "open-telemetry-docker-dev.bintray.io/java/smoke-springboot-jdk" + jdk + ":latest"; } - @Override - protected Map getExtraEnv() { - return Map.of("SPLUNK_OTEL_CONFIG_SPAN_PROCESSOR_INSTRLIB_ENABLED", "true"); - } - @ParameterizedTest(name = "{index} => SpringBoot SmokeTest On JDK{0}.") @ValueSource(ints = {8, 11, 15}) public void springBootSmokeTestOnJDK(int jdk) throws IOException, InterruptedException { @@ -68,14 +62,6 @@ public void springBootSmokeTestOnJDK(int jdk) throws IOException, InterruptedExc .map(a -> a.getValue().getStringValue()) .filter(s -> s.equals(currentAgentVersion)) .count()); - Assertions.assertEquals( - 3, - getSpanStream(traces) - .flatMap(s -> s.getAttributesList().stream()) - .filter(a -> a.getKey().equals("splunk.instrumentation_library.version")) - .map(a -> a.getValue().getStringValue()) - .filter(s -> s.equals(currentAgentVersion)) - .count()); stopTarget(); }