From b2870491fa37b362aaa7603c9985079fae2fd256 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 17 Oct 2023 15:54:13 -0700 Subject: [PATCH 1/6] allow for simpler creation of start-only and end-only SpanProcessors. --- .../opentelemetry-sdk-trace.txt | 5 +- .../TestTracerProviderConfigurer.java | 26 ++------- .../sdk/trace/SpanProcessor.java | 55 +++++++++++++++++++ .../sdk/trace/SpanProcessorTest.java | 50 +++++++++++++++++ 4 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt index df26146497b..bd24ba0a226 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt @@ -1,2 +1,5 @@ Comparing source compatibility of against -No changes. \ No newline at end of file +*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.trace.SpanProcessor (not serializable) + === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 + +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.SpanProcessor endOnly(java.util.function.Consumer) + +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.SpanProcessor startOnly(java.util.function.BiConsumer) diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java index 3546b8f8160..713a1219951 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java @@ -5,10 +5,7 @@ package io.opentelemetry.sdk.autoconfigure.provider; -import io.opentelemetry.context.Context; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.trace.ReadWriteSpan; -import io.opentelemetry.sdk.trace.ReadableSpan; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import io.opentelemetry.sdk.trace.SpanProcessor; @@ -18,24 +15,9 @@ public class TestTracerProviderConfigurer @Override public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) { tracerProvider.addSpanProcessor( - new SpanProcessor() { - @Override - public void onStart(Context parentContext, ReadWriteSpan span) { - span.setAttribute("configured", config.getBoolean("otel.test.configured")); - } - - @Override - public boolean isStartRequired() { - return true; - } - - @Override - public void onEnd(ReadableSpan span) {} - - @Override - public boolean isEndRequired() { - return false; - } - }); + SpanProcessor.startOnly( + (ctx, span) -> { + span.setAttribute("configured", config.getBoolean("otel.test.configured")); + })); } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java index ba9fb037c84..ac6e54cb8e2 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java @@ -13,6 +13,8 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.Consumer; import javax.annotation.concurrent.ThreadSafe; /** @@ -112,4 +114,57 @@ default CompletableResultCode forceFlush() { default void close() { shutdown().join(10, TimeUnit.SECONDS); } + + /** + * Creates a new SpanProcessor instance that invokes the provided BiConsumer when the span is + * started. + */ + static SpanProcessor startOnly(BiConsumer onStart) { + return new SpanProcessor() { + @Override + public void onStart(Context parentContext, ReadWriteSpan span) { + onStart.accept(parentContext, span); + } + + @Override + public boolean isStartRequired() { + return true; + } + + @Override + public void onEnd(ReadableSpan span) { + /// nop + } + + @Override + public boolean isEndRequired() { + return false; + } + }; + } + + /** Creates a new SpanProcessor that invokes the provided Consumer when a span is ended. */ + static SpanProcessor endOnly(Consumer onEnd) { + return new SpanProcessor() { + @Override + public void onStart(Context parentContext, ReadWriteSpan span) { + // nop + } + + @Override + public boolean isStartRequired() { + return false; + } + + @Override + public void onEnd(ReadableSpan span) { + onEnd.accept(span); + } + + @Override + public boolean isEndRequired() { + return true; + } + }; + } } diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java new file mode 100644 index 00000000000..e2fd4e81cd3 --- /dev/null +++ b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java @@ -0,0 +1,50 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static org.mockito.Mockito.mock; + +import io.opentelemetry.context.Context; +import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Test; + +class SpanProcessorTest { + + @Test + void startOnly() { + AtomicReference seenContext = new AtomicReference<>(); + AtomicReference seenSpan = new AtomicReference<>(); + Context context = mock(Context.class); + ReadWriteSpan inputSpan = mock(ReadWriteSpan.class); + + SpanProcessor processor = + SpanProcessor.startOnly( + (ctx, span) -> { + seenContext.set(ctx); + seenSpan.set(span); + }); + + assertThat(processor.isStartRequired()).isTrue(); + assertThat(processor.isEndRequired()).isFalse(); + processor.onStart(context, inputSpan); + assertThat(seenContext.get()).isSameAs(context); + assertThat(seenSpan.get()).isSameAs(inputSpan); + } + + @Test + void endOnly() { + AtomicReference seenSpan = new AtomicReference<>(); + ReadWriteSpan inputSpan = mock(ReadWriteSpan.class); + + SpanProcessor processor = SpanProcessor.endOnly(seenSpan::set); + + assertThat(processor.isStartRequired()).isFalse(); + assertThat(processor.isEndRequired()).isTrue(); + processor.onEnd(inputSpan); + assertThat(seenSpan.get()).isSameAs(inputSpan); + } +} From 5bddf1c6b5ea69330250ffe43ea335ebcc631ffa Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 17 Oct 2023 16:23:21 -0700 Subject: [PATCH 2/6] Create helper classes instead of touching interface. --- .../opentelemetry-sdk-trace.txt | 25 +++++++-- .../TestTracerProviderConfigurer.java | 9 ++- .../sdk/trace/OnEndSpanProcessor.java | 42 ++++++++++++++ .../sdk/trace/OnStartSpanProcessor.java | 43 +++++++++++++++ .../sdk/trace/SpanProcessor.java | 55 ------------------- 5 files changed, 110 insertions(+), 64 deletions(-) create mode 100644 sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java create mode 100644 sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt index bd24ba0a226..a15d81651bc 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt @@ -1,5 +1,22 @@ Comparing source compatibility of against -*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.trace.SpanProcessor (not serializable) - === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 - +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.SpanProcessor endOnly(java.util.function.Consumer) - +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.SpanProcessor startOnly(java.util.function.BiConsumer) ++++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.trace.OnEndSpanProcessor (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW INTERFACE: java.io.Closeable + +++ NEW INTERFACE: java.lang.AutoCloseable + +++ NEW INTERFACE: io.opentelemetry.sdk.trace.SpanProcessor + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) boolean isEndRequired() + +++ NEW METHOD: PUBLIC(+) boolean isStartRequired() + +++ NEW METHOD: PUBLIC(+) void onEnd(io.opentelemetry.sdk.trace.ReadableSpan) + +++ NEW METHOD: PUBLIC(+) void onStart(io.opentelemetry.context.Context, io.opentelemetry.sdk.trace.ReadWriteSpan) ++++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.trace.OnStartSpanProcessor (not serializable) + +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. + +++ NEW INTERFACE: java.io.Closeable + +++ NEW INTERFACE: java.lang.AutoCloseable + +++ NEW INTERFACE: io.opentelemetry.sdk.trace.SpanProcessor + +++ NEW SUPERCLASS: java.lang.Object + +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.SpanProcessor create(java.util.function.BiConsumer) + +++ NEW METHOD: PUBLIC(+) boolean isEndRequired() + +++ NEW METHOD: PUBLIC(+) boolean isStartRequired() + +++ NEW METHOD: PUBLIC(+) void onEnd(io.opentelemetry.sdk.trace.ReadableSpan) + +++ NEW METHOD: PUBLIC(+) void onStart(io.opentelemetry.context.Context, io.opentelemetry.sdk.trace.ReadWriteSpan) diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java index 713a1219951..197425f27fd 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java @@ -6,8 +6,8 @@ package io.opentelemetry.sdk.autoconfigure.provider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.trace.OnStartSpanProcessor; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; -import io.opentelemetry.sdk.trace.SpanProcessor; @SuppressWarnings("deprecation") // Support testing of SdkTracerProviderConfigurer public class TestTracerProviderConfigurer @@ -15,9 +15,8 @@ public class TestTracerProviderConfigurer @Override public void configure(SdkTracerProviderBuilder tracerProvider, ConfigProperties config) { tracerProvider.addSpanProcessor( - SpanProcessor.startOnly( - (ctx, span) -> { - span.setAttribute("configured", config.getBoolean("otel.test.configured")); - })); + OnStartSpanProcessor.create( + (ctx, span) -> + span.setAttribute("configured", config.getBoolean("otel.test.configured")))); } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java new file mode 100644 index 00000000000..073524ad30a --- /dev/null +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import io.opentelemetry.context.Context; +import java.util.function.Consumer; + +/** A SpanProcessor implementation that is only capable of processing spans when they end. */ +public final class OnEndSpanProcessor implements SpanProcessor { + private final Consumer onEnd; + + private OnEndSpanProcessor(Consumer onEnd) { + this.onEnd = onEnd; + } + + static SpanProcessor create(Consumer onEnd) { + return new OnEndSpanProcessor(onEnd); + } + + @Override + public void onEnd(ReadableSpan span) { + onEnd.accept(span); + } + + @Override + public boolean isEndRequired() { + return false; + } + + @Override + public void onStart(Context parentContext, ReadWriteSpan span) { + // nop + } + + @Override + public boolean isStartRequired() { + return false; + } +} diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java new file mode 100644 index 00000000000..ed895116463 --- /dev/null +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java @@ -0,0 +1,43 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import io.opentelemetry.context.Context; +import java.util.function.BiConsumer; + +/** A SpanProcessor that only handles onStart(). */ +public final class OnStartSpanProcessor implements SpanProcessor { + + private final BiConsumer onStart; + + private OnStartSpanProcessor(BiConsumer onStart) { + this.onStart = onStart; + } + + public static SpanProcessor create(BiConsumer onStart) { + return new OnStartSpanProcessor(onStart); + } + + @Override + public void onStart(Context parentContext, ReadWriteSpan span) { + this.onStart.accept(parentContext, span); + } + + @Override + public boolean isStartRequired() { + return true; + } + + @Override + public void onEnd(ReadableSpan span) { + // nop + } + + @Override + public boolean isEndRequired() { + return false; + } +} diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java index ac6e54cb8e2..ba9fb037c84 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/SpanProcessor.java @@ -13,8 +13,6 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; -import java.util.function.Consumer; import javax.annotation.concurrent.ThreadSafe; /** @@ -114,57 +112,4 @@ default CompletableResultCode forceFlush() { default void close() { shutdown().join(10, TimeUnit.SECONDS); } - - /** - * Creates a new SpanProcessor instance that invokes the provided BiConsumer when the span is - * started. - */ - static SpanProcessor startOnly(BiConsumer onStart) { - return new SpanProcessor() { - @Override - public void onStart(Context parentContext, ReadWriteSpan span) { - onStart.accept(parentContext, span); - } - - @Override - public boolean isStartRequired() { - return true; - } - - @Override - public void onEnd(ReadableSpan span) { - /// nop - } - - @Override - public boolean isEndRequired() { - return false; - } - }; - } - - /** Creates a new SpanProcessor that invokes the provided Consumer when a span is ended. */ - static SpanProcessor endOnly(Consumer onEnd) { - return new SpanProcessor() { - @Override - public void onStart(Context parentContext, ReadWriteSpan span) { - // nop - } - - @Override - public boolean isStartRequired() { - return false; - } - - @Override - public void onEnd(ReadableSpan span) { - onEnd.accept(span); - } - - @Override - public boolean isEndRequired() { - return true; - } - }; - } } From 27c93bbe9099a092441b193a52d336c18839ef1d Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 17 Oct 2023 16:49:29 -0700 Subject: [PATCH 3/6] fix tests --- .../sdk/trace/OnEndSpanProcessor.java | 2 +- .../sdk/trace/OnEndSpanProcessorTest.java | 28 +++++++++++++++++++ ...est.java => OnStartSpanProcessorTest.java} | 19 ++----------- 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java rename sdk/trace/src/test/java/io/opentelemetry/sdk/trace/{SpanProcessorTest.java => OnStartSpanProcessorTest.java} (63%) diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java index 073524ad30a..7a1c0ca2091 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java @@ -27,7 +27,7 @@ public void onEnd(ReadableSpan span) { @Override public boolean isEndRequired() { - return false; + return true; } @Override diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java new file mode 100644 index 00000000000..af67e43e56a --- /dev/null +++ b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.sdk.trace; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Test; + +class OnEndSpanProcessorTest { + + @Test + void endOnly() { + AtomicReference seenSpan = new AtomicReference<>(); + ReadWriteSpan inputSpan = mock(ReadWriteSpan.class); + + SpanProcessor processor = OnEndSpanProcessor.create(seenSpan::set); + + assertThat(processor.isStartRequired()).isFalse(); + assertThat(processor.isEndRequired()).isTrue(); + processor.onEnd(inputSpan); + assertThat(seenSpan.get()).isSameAs(inputSpan); + } +} diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnStartSpanProcessorTest.java similarity index 63% rename from sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java rename to sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnStartSpanProcessorTest.java index e2fd4e81cd3..3a9bf2e7f1b 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/SpanProcessorTest.java +++ b/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnStartSpanProcessorTest.java @@ -5,14 +5,14 @@ package io.opentelemetry.sdk.trace; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import io.opentelemetry.context.Context; import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.Test; -class SpanProcessorTest { +class OnStartSpanProcessorTest { @Test void startOnly() { @@ -22,7 +22,7 @@ void startOnly() { ReadWriteSpan inputSpan = mock(ReadWriteSpan.class); SpanProcessor processor = - SpanProcessor.startOnly( + OnStartSpanProcessor.create( (ctx, span) -> { seenContext.set(ctx); seenSpan.set(span); @@ -34,17 +34,4 @@ void startOnly() { assertThat(seenContext.get()).isSameAs(context); assertThat(seenSpan.get()).isSameAs(inputSpan); } - - @Test - void endOnly() { - AtomicReference seenSpan = new AtomicReference<>(); - ReadWriteSpan inputSpan = mock(ReadWriteSpan.class); - - SpanProcessor processor = SpanProcessor.endOnly(seenSpan::set); - - assertThat(processor.isStartRequired()).isFalse(); - assertThat(processor.isEndRequired()).isTrue(); - processor.onEnd(inputSpan); - assertThat(seenSpan.get()).isSameAs(inputSpan); - } } From 32c12d3a1326f4543ef71ded7da6ab2a0a1356df Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 24 Oct 2023 15:38:49 -0700 Subject: [PATCH 4/6] custom functional interfaces --- .../sdk/trace/OnEndSpanProcessor.java | 14 +++++++++----- .../sdk/trace/OnStartSpanProcessor.java | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java index 7a1c0ca2091..efcb8398431 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java @@ -6,23 +6,22 @@ package io.opentelemetry.sdk.trace; import io.opentelemetry.context.Context; -import java.util.function.Consumer; /** A SpanProcessor implementation that is only capable of processing spans when they end. */ public final class OnEndSpanProcessor implements SpanProcessor { - private final Consumer onEnd; + private final OnEnd onEnd; - private OnEndSpanProcessor(Consumer onEnd) { + private OnEndSpanProcessor(OnEnd onEnd) { this.onEnd = onEnd; } - static SpanProcessor create(Consumer onEnd) { + static SpanProcessor create(OnEnd onEnd) { return new OnEndSpanProcessor(onEnd); } @Override public void onEnd(ReadableSpan span) { - onEnd.accept(span); + onEnd.apply(span); } @Override @@ -39,4 +38,9 @@ public void onStart(Context parentContext, ReadWriteSpan span) { public boolean isStartRequired() { return false; } + + @FunctionalInterface + public interface OnEnd { + void apply(ReadableSpan span); + } } diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java index ed895116463..1a779ab1363 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java +++ b/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java @@ -6,24 +6,23 @@ package io.opentelemetry.sdk.trace; import io.opentelemetry.context.Context; -import java.util.function.BiConsumer; /** A SpanProcessor that only handles onStart(). */ public final class OnStartSpanProcessor implements SpanProcessor { - private final BiConsumer onStart; + private final OnStart onStart; - private OnStartSpanProcessor(BiConsumer onStart) { + private OnStartSpanProcessor(OnStart onStart) { this.onStart = onStart; } - public static SpanProcessor create(BiConsumer onStart) { + public static SpanProcessor create(OnStart onStart) { return new OnStartSpanProcessor(onStart); } @Override public void onStart(Context parentContext, ReadWriteSpan span) { - this.onStart.accept(parentContext, span); + onStart.apply(parentContext, span); } @Override @@ -40,4 +39,9 @@ public void onEnd(ReadableSpan span) { public boolean isEndRequired() { return false; } + + @FunctionalInterface + public interface OnStart { + void apply(Context context, ReadWriteSpan span); + } } From e5062ff05492ed9af04ca8f32ad2d6d1204e5172 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 24 Oct 2023 15:44:22 -0700 Subject: [PATCH 5/6] move to incubator --- .../opentelemetry-sdk-trace.txt | 22 +------------------ .../TestTracerProviderConfigurer.java | 2 +- .../incubator}/trace/OnEndSpanProcessor.java | 5 ++++- .../trace/OnStartSpanProcessor.java | 5 ++++- .../trace/OnEndSpanProcessorTest.java | 6 ++++- .../trace/OnStartSpanProcessorTest.java | 4 +++- 6 files changed, 18 insertions(+), 26 deletions(-) rename {sdk/trace/src/main/java/io/opentelemetry/sdk => sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator}/trace/OnEndSpanProcessor.java (81%) rename {sdk/trace/src/main/java/io/opentelemetry/sdk => sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator}/trace/OnStartSpanProcessor.java (81%) rename {sdk/trace/src/test/java/io/opentelemetry/sdk => sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator}/trace/OnEndSpanProcessorTest.java (78%) rename {sdk/trace/src/test/java/io/opentelemetry/sdk => sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator}/trace/OnStartSpanProcessorTest.java (87%) diff --git a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt index a15d81651bc..df26146497b 100644 --- a/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt +++ b/docs/apidiffs/current_vs_latest/opentelemetry-sdk-trace.txt @@ -1,22 +1,2 @@ Comparing source compatibility of against -+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.trace.OnEndSpanProcessor (not serializable) - +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. - +++ NEW INTERFACE: java.io.Closeable - +++ NEW INTERFACE: java.lang.AutoCloseable - +++ NEW INTERFACE: io.opentelemetry.sdk.trace.SpanProcessor - +++ NEW SUPERCLASS: java.lang.Object - +++ NEW METHOD: PUBLIC(+) boolean isEndRequired() - +++ NEW METHOD: PUBLIC(+) boolean isStartRequired() - +++ NEW METHOD: PUBLIC(+) void onEnd(io.opentelemetry.sdk.trace.ReadableSpan) - +++ NEW METHOD: PUBLIC(+) void onStart(io.opentelemetry.context.Context, io.opentelemetry.sdk.trace.ReadWriteSpan) -+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.sdk.trace.OnStartSpanProcessor (not serializable) - +++ CLASS FILE FORMAT VERSION: 52.0 <- n.a. - +++ NEW INTERFACE: java.io.Closeable - +++ NEW INTERFACE: java.lang.AutoCloseable - +++ NEW INTERFACE: io.opentelemetry.sdk.trace.SpanProcessor - +++ NEW SUPERCLASS: java.lang.Object - +++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.trace.SpanProcessor create(java.util.function.BiConsumer) - +++ NEW METHOD: PUBLIC(+) boolean isEndRequired() - +++ NEW METHOD: PUBLIC(+) boolean isStartRequired() - +++ NEW METHOD: PUBLIC(+) void onEnd(io.opentelemetry.sdk.trace.ReadableSpan) - +++ NEW METHOD: PUBLIC(+) void onStart(io.opentelemetry.context.Context, io.opentelemetry.sdk.trace.ReadWriteSpan) +No changes. \ No newline at end of file diff --git a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java index 197425f27fd..31d5e8a2dd7 100644 --- a/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java +++ b/sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/provider/TestTracerProviderConfigurer.java @@ -6,7 +6,7 @@ package io.opentelemetry.sdk.autoconfigure.provider; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; -import io.opentelemetry.sdk.trace.OnStartSpanProcessor; +import io.opentelemetry.sdk.extension.incubator.trace.OnStartSpanProcessor; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; @SuppressWarnings("deprecation") // Support testing of SdkTracerProviderConfigurer diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessor.java similarity index 81% rename from sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java rename to sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessor.java index efcb8398431..4a207277201 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnEndSpanProcessor.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessor.java @@ -3,9 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.trace; +package io.opentelemetry.sdk.extension.incubator.trace; import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.trace.ReadWriteSpan; +import io.opentelemetry.sdk.trace.ReadableSpan; +import io.opentelemetry.sdk.trace.SpanProcessor; /** A SpanProcessor implementation that is only capable of processing spans when they end. */ public final class OnEndSpanProcessor implements SpanProcessor { diff --git a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessor.java similarity index 81% rename from sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java rename to sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessor.java index 1a779ab1363..1ef96c2e883 100644 --- a/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/OnStartSpanProcessor.java +++ b/sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessor.java @@ -3,9 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.trace; +package io.opentelemetry.sdk.extension.incubator.trace; import io.opentelemetry.context.Context; +import io.opentelemetry.sdk.trace.ReadWriteSpan; +import io.opentelemetry.sdk.trace.ReadableSpan; +import io.opentelemetry.sdk.trace.SpanProcessor; /** A SpanProcessor that only handles onStart(). */ public final class OnStartSpanProcessor implements SpanProcessor { diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java similarity index 78% rename from sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java rename to sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java index af67e43e56a..c1de5bc4964 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnEndSpanProcessorTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java @@ -3,12 +3,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.trace; +package io.opentelemetry.sdk.extension.incubator.trace; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import java.util.concurrent.atomic.AtomicReference; + +import io.opentelemetry.sdk.trace.ReadWriteSpan; +import io.opentelemetry.sdk.trace.ReadableSpan; +import io.opentelemetry.sdk.trace.SpanProcessor; import org.junit.jupiter.api.Test; class OnEndSpanProcessorTest { diff --git a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnStartSpanProcessorTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java similarity index 87% rename from sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnStartSpanProcessorTest.java rename to sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java index 3a9bf2e7f1b..b7ebb60af42 100644 --- a/sdk/trace/src/test/java/io/opentelemetry/sdk/trace/OnStartSpanProcessorTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java @@ -3,13 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.sdk.trace; +package io.opentelemetry.sdk.extension.incubator.trace; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import io.opentelemetry.context.Context; import java.util.concurrent.atomic.AtomicReference; +import io.opentelemetry.sdk.trace.ReadWriteSpan; +import io.opentelemetry.sdk.trace.SpanProcessor; import org.junit.jupiter.api.Test; class OnStartSpanProcessorTest { From 6b97a5fd7592a1863fa8012ee947798d1637d095 Mon Sep 17 00:00:00 2001 From: Jason Plumb Date: Tue, 24 Oct 2023 15:53:00 -0700 Subject: [PATCH 6/6] spotless --- .../sdk/extension/incubator/trace/OnEndSpanProcessorTest.java | 3 +-- .../extension/incubator/trace/OnStartSpanProcessorTest.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java index c1de5bc4964..426b68e8131 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnEndSpanProcessorTest.java @@ -8,11 +8,10 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; -import java.util.concurrent.atomic.AtomicReference; - import io.opentelemetry.sdk.trace.ReadWriteSpan; import io.opentelemetry.sdk.trace.ReadableSpan; import io.opentelemetry.sdk.trace.SpanProcessor; +import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.Test; class OnEndSpanProcessorTest { diff --git a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java index b7ebb60af42..245486ec9e2 100644 --- a/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java +++ b/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/trace/OnStartSpanProcessorTest.java @@ -9,9 +9,9 @@ import static org.mockito.Mockito.mock; import io.opentelemetry.context.Context; -import java.util.concurrent.atomic.AtomicReference; import io.opentelemetry.sdk.trace.ReadWriteSpan; import io.opentelemetry.sdk.trace.SpanProcessor; +import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.Test; class OnStartSpanProcessorTest {