From def1c85b6063f3633af9ad5c30ce3f3c1d58368e Mon Sep 17 00:00:00 2001 From: jack-berg <34418638+jack-berg@users.noreply.github.com> Date: Thu, 25 Aug 2022 08:46:45 -0500 Subject: [PATCH] Drop opentelemetry-sdk-extension-jfr-events, which moved to opentelemetry-java-contrib (#4703) --- README.md | 1 - all/build.gradle.kts | 10 +- .../io/opentelemetry/all/SdkDesignTest.java | 4 +- sdk-extensions/jfr-events/README.md | 23 ---- sdk-extensions/jfr-events/build.gradle.kts | 30 ----- sdk-extensions/jfr-events/gradle.properties | 1 - .../jfr/JfrContextStorageWrapper.java | 40 ------ .../sdk/extension/jfr/JfrSpanProcessor.java | 65 --------- .../sdk/extension/jfr/ScopeEvent.java | 40 ------ .../sdk/extension/jfr/SpanEvent.java | 52 ------- .../sdk/extension/jfr/package-info.java | 14 -- .../extension/jfr/JfrSpanProcessorTest.java | 127 ------------------ settings.gradle.kts | 1 - 13 files changed, 6 insertions(+), 402 deletions(-) delete mode 100644 sdk-extensions/jfr-events/README.md delete mode 100644 sdk-extensions/jfr-events/build.gradle.kts delete mode 100644 sdk-extensions/jfr-events/gradle.properties delete mode 100644 sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrContextStorageWrapper.java delete mode 100644 sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessor.java delete mode 100644 sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/ScopeEvent.java delete mode 100644 sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/SpanEvent.java delete mode 100644 sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/package-info.java delete mode 100644 sdk-extensions/jfr-events/src/test/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessorTest.java diff --git a/README.md b/README.md index 4b3562a12e6..e8e72e8023a 100644 --- a/README.md +++ b/README.md @@ -276,7 +276,6 @@ dependency as follows, replacing `{{artifact-id}}` with the value from the "Arti | [SDK Resources Extension](./sdk-extensions/resources) | Resource providers, including container, host, os, and process | `opentelemetry-sdk-extension-resources` | 1.17.0 | | [SDK AWS Extension](./sdk-extensions/aws) | AWS resource providers, including beanstalk, ec2, ecs, eks, and lambda | `opentelemetry-sdk-extension-aws` | 1.17.0 | | [SDK Jaeger Remote Sampler Extension](./sdk-extensions/jaeger-remote-sampler) | Sampler which obtains sampling configuration from remote Jaeger server | `opentelemetry-sdk-extension-jaeger-remote-sampler` | 1.17.0 | -| [SDK JFR Events Extension](./sdk-extensions/jfr-events) | SpanProcessor which records spans as JFR events | `opentelemetry-sdk-extension-jfr-events` | 1.17.0-alpha | | [SDK Incubator](./sdk-extensions/incubator) | SDK incubator, including YAML based view configuration, LeakDetectingSpanProcessor, and zPages | `opentelemetry-sdk-extension-incubator` | TODO: add version when published | ### Shims diff --git a/all/build.gradle.kts b/all/build.gradle.kts index cbbf93d7eff..2dae993f1f7 100644 --- a/all/build.gradle.kts +++ b/all/build.gradle.kts @@ -8,10 +8,10 @@ otelJava.moduleName.set("io.opentelemetry.all") tasks { // We don't compile much here, just some API boundary tests. This project is mostly for // aggregating jacoco reports and it doesn't work if this isn't at least as high as the - // highest supported Java version in any of our projects. Most of our projects target - // Java 8, except for jfr-events. + // highest supported Java version in any of our projects. All of our projects target + // Java 8. withType(JavaCompile::class) { - options.release.set(11) + options.release.set(8) } val testJavaVersion: String? by project @@ -83,9 +83,7 @@ tasks.named("jacocoTestReport") { !it.absolutePath.contains("io/opentelemetry/exporter/jaeger/internal/protobuf/") && !it.absolutePath.contains("io/opentelemetry/sdk/extension/trace/jaeger/proto/") && !it.absolutePath.contains("io/opentelemetry/semconv/trace/attributes/") && - !it.absolutePath.contains("AutoValue_") && - // TODO(anuraaga): Remove exclusion after enabling coverage for jfr-events - !it.absolutePath.contains("io/opentelemetry/sdk/extension/jfr") + !it.absolutePath.contains("AutoValue_") } ) } diff --git a/all/src/test/java/io/opentelemetry/all/SdkDesignTest.java b/all/src/test/java/io/opentelemetry/all/SdkDesignTest.java index 4fc4d37da2f..8c5095865a4 100644 --- a/all/src/test/java/io/opentelemetry/all/SdkDesignTest.java +++ b/all/src/test/java/io/opentelemetry/all/SdkDesignTest.java @@ -53,7 +53,7 @@ void sdkImplementationOfApiClassesShouldReturnApiTypeOnly() { } static DescribedPredicate implementOrOverride() { - return new DescribedPredicate<>("implement or override a method") { + return new DescribedPredicate("implement or override a method") { @Override public boolean apply(JavaMethod input) { List params = input.getRawParameterTypes(); @@ -78,7 +78,7 @@ public boolean apply(JavaMethod input) { } static DescribedPredicate inPackage(String... requiredPackages) { - return new DescribedPredicate<>("are in " + Arrays.toString(requiredPackages)) { + return new DescribedPredicate("are in " + Arrays.toString(requiredPackages)) { @Override public boolean apply(JavaClass member) { for (String requiredPackage : requiredPackages) { diff --git a/sdk-extensions/jfr-events/README.md b/sdk-extensions/jfr-events/README.md deleted file mode 100644 index c039bc6c1c1..00000000000 --- a/sdk-extensions/jfr-events/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# OpenTelemetry SDK Extension Java Flight Recorder (JFR) Events - -[![Javadocs][javadoc-image]][javadoc-url] - -Create JFR events that can be recorded and viewed in Java Mission Control (JMC). -* Creates Open Telemetry Tracing/Span events for spans - * The thread and stracktrace will be of the thead ending the span which might be different than the thread creating the span. - * Has the fields - * Operation Name - * Trace ID - * Parent Span ID - * Span ID -* Creates Open Telemetry Tracing/Scope events for scopes - * Thread will match the thread the scope was active in and the stacktrace will be when scope was closed - * Multiple scopes might be collected for a single span - * Has the fields - * Trace ID - * Span ID -* Supports the Open Source version of JFR in Java 11. - * Might support back port to OpenJDK 8, but not tested and classes are built with JDK 11 bytecode. - -[javadoc-image]: https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-sdk-extension-jfr-events.svg -[javadoc-url]: https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-extension-jfr-events diff --git a/sdk-extensions/jfr-events/build.gradle.kts b/sdk-extensions/jfr-events/build.gradle.kts deleted file mode 100644 index c45dc715b03..00000000000 --- a/sdk-extensions/jfr-events/build.gradle.kts +++ /dev/null @@ -1,30 +0,0 @@ -plugins { - id("otel.java-conventions") - id("otel.publish-conventions") -} - -description = "OpenTelemetry SDK Extension JFR" -otelJava.moduleName.set("io.opentelemetry.sdk.extension.jfr") - -dependencies { - implementation(project(":api:all")) - implementation(project(":sdk:all")) -} - -tasks { - withType(JavaCompile::class) { - options.release.set(11) - } - - test { - val testJavaVersion: String? by project - if (testJavaVersion == "8") { - enabled = false - } - - // Disabled due to https://bugs.openjdk.java.net/browse/JDK-8245283 - configure { - enabled = false - } - } -} diff --git a/sdk-extensions/jfr-events/gradle.properties b/sdk-extensions/jfr-events/gradle.properties deleted file mode 100644 index 4476ae57e31..00000000000 --- a/sdk-extensions/jfr-events/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -otel.release=alpha diff --git a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrContextStorageWrapper.java b/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrContextStorageWrapper.java deleted file mode 100644 index b9d587dda01..00000000000 --- a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrContextStorageWrapper.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.extension.jfr; - -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.ContextStorage; -import io.opentelemetry.context.Scope; -import javax.annotation.Nullable; - -public final class JfrContextStorageWrapper implements ContextStorage { - - private final ContextStorage wrapped; - - public JfrContextStorageWrapper(ContextStorage wrapped) { - this.wrapped = wrapped; - } - - @Override - public Scope attach(Context toAttach) { - Scope scope = wrapped.attach(toAttach); - ScopeEvent event = new ScopeEvent(Span.fromContext(toAttach).getSpanContext()); - event.begin(); - return () -> { - if (event.shouldCommit()) { - event.commit(); - } - scope.close(); - }; - } - - @Override - @Nullable - public Context current() { - return wrapped.current(); - } -} diff --git a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessor.java b/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessor.java deleted file mode 100644 index e3e9e914c36..00000000000 --- a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.extension.jfr; - -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.internal.shaded.WeakConcurrentMap; -import io.opentelemetry.sdk.common.CompletableResultCode; -import io.opentelemetry.sdk.trace.ReadWriteSpan; -import io.opentelemetry.sdk.trace.ReadableSpan; -import io.opentelemetry.sdk.trace.SpanProcessor; - -/** - * Span processor to create new JFR events for the Span as they are started, and commit on end. - * - *

NOTE: The JfrSpanProcessor measures the timing of spans, avoid if possible to wrap it with any - * other SpanProcessor which may affect timings. When possible, register it first before any other - * processors to allow the most accurate measurements. - */ -public final class JfrSpanProcessor implements SpanProcessor { - - private final WeakConcurrentMap spanEvents = - new WeakConcurrentMap.WithInlinedExpunction<>(); - - private volatile boolean closed; - - @Override - public void onStart(Context parentContext, ReadWriteSpan span) { - if (closed) { - return; - } - if (span.getSpanContext().isValid()) { - SpanEvent event = new SpanEvent(span.toSpanData()); - event.begin(); - spanEvents.put(span.getSpanContext(), event); - } - } - - @Override - public boolean isStartRequired() { - return true; - } - - @Override - public void onEnd(ReadableSpan rs) { - SpanEvent event = spanEvents.remove(rs.getSpanContext()); - if (!closed && event != null && event.shouldCommit()) { - event.commit(); - } - } - - @Override - public boolean isEndRequired() { - return true; - } - - @Override - public CompletableResultCode shutdown() { - closed = true; - return CompletableResultCode.ofSuccess(); - } -} diff --git a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/ScopeEvent.java b/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/ScopeEvent.java deleted file mode 100644 index cf40bb4e103..00000000000 --- a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/ScopeEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.extension.jfr; - -import io.opentelemetry.api.trace.SpanContext; -import jdk.jfr.Category; -import jdk.jfr.Description; -import jdk.jfr.Event; -import jdk.jfr.Label; -import jdk.jfr.Name; - -@Name("io.opentelemetry.context.Scope") -@Label("Scope") -@Category("Open Telemetry Tracing") -@Description( - "Open Telemetry trace event corresponding to the span currently " - + "in scope/active on this thread.") -class ScopeEvent extends Event { - - private final String traceId; - private final String spanId; - - ScopeEvent(SpanContext spanContext) { - this.traceId = spanContext.getTraceId(); - this.spanId = spanContext.getSpanId(); - } - - @Label("Trace Id") - public String getTraceId() { - return traceId; - } - - @Label("Span Id") - public String getSpanId() { - return spanId; - } -} diff --git a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/SpanEvent.java b/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/SpanEvent.java deleted file mode 100644 index 1e239b92937..00000000000 --- a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/SpanEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.extension.jfr; - -import io.opentelemetry.sdk.trace.data.SpanData; -import jdk.jfr.Category; -import jdk.jfr.Description; -import jdk.jfr.Event; -import jdk.jfr.Label; -import jdk.jfr.Name; - -@Label("Span") -@Name("io.opentelemetry.trace.Span") -@Category("Open Telemetry Tracing") -@Description("Open Telemetry trace event corresponding to a span.") -class SpanEvent extends Event { - - private final String operationName; - private final String traceId; - private final String spanId; - private final String parentId; - - SpanEvent(SpanData spanData) { - this.operationName = spanData.getName(); - this.traceId = spanData.getTraceId(); - this.spanId = spanData.getSpanId(); - this.parentId = spanData.getParentSpanId(); - } - - @Label("Operation Name") - public String getOperationName() { - return operationName; - } - - @Label("Trace Id") - public String getTraceId() { - return traceId; - } - - @Label("Span Id") - public String getSpanId() { - return spanId; - } - - @Label("Parent Id") - public String getParentId() { - return parentId; - } -} diff --git a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/package-info.java b/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/package-info.java deleted file mode 100644 index ac7889ff0e5..00000000000 --- a/sdk-extensions/jfr-events/src/main/java/io/opentelemetry/sdk/extension/jfr/package-info.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * Capture Spans and Scopes as events in JFR recordings. - * - * @see io.opentelemetry.sdk.extension.jfr.JfrSpanProcessor - */ -@ParametersAreNonnullByDefault -package io.opentelemetry.sdk.extension.jfr; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sdk-extensions/jfr-events/src/test/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessorTest.java b/sdk-extensions/jfr-events/src/test/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessorTest.java deleted file mode 100644 index 49902d59f1b..00000000000 --- a/sdk-extensions/jfr-events/src/test/java/io/opentelemetry/sdk/extension/jfr/JfrSpanProcessorTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.sdk.extension.jfr; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.ContextStorage; -import io.opentelemetry.context.Scope; -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; -import jdk.jfr.Recording; -import jdk.jfr.consumer.RecordedEvent; -import jdk.jfr.consumer.RecordingFile; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class JfrSpanProcessorTest { - - private static final String OPERATION_NAME = "Test Span"; - - private SdkTracerProvider sdkTracerProvider; - private Tracer tracer; - - @BeforeEach - void setUp() { - sdkTracerProvider = - SdkTracerProvider.builder().addSpanProcessor(new JfrSpanProcessor()).build(); - tracer = sdkTracerProvider.get("JfrSpanProcessorTest"); - } - - @AfterEach - void tearDown() { - sdkTracerProvider.shutdown(); - } - - static { - ContextStorage.addWrapper(JfrContextStorageWrapper::new); - } - - /** - * Test basic single span. - * - * @throws java.io.IOException on io error - */ - @Test - public void basicSpan() throws IOException { - Path output = Files.createTempFile("test-basic-span", ".jfr"); - - try { - Recording recording = new Recording(); - recording.start(); - Span span; - - try (recording) { - - span = tracer.spanBuilder(OPERATION_NAME).setNoParent().startSpan(); - span.end(); - - recording.dump(output); - } - - List events = RecordingFile.readAllEvents(output); - assertThat(events).hasSize(1); - assertThat(events) - .extracting(e -> e.getValue("traceId")) - .isEqualTo(span.getSpanContext().getTraceId()); - assertThat(events) - .extracting(e -> e.getValue("spanId")) - .isEqualTo(span.getSpanContext().getSpanId()); - assertThat(events).extracting(e -> e.getValue("operationName")).isEqualTo(OPERATION_NAME); - } finally { - Files.delete(output); - } - } - - /** - * Test basic single span with a scope. - * - * @throws java.io.IOException on io error - * @throws java.lang.InterruptedException interrupted sleep - */ - @Test - public void basicSpanWithScope() throws IOException, InterruptedException { - Path output = Files.createTempFile("test-basic-span-with-scope", ".jfr"); - - try { - Recording recording = new Recording(); - recording.start(); - Span span; - - try (recording) { - span = tracer.spanBuilder(OPERATION_NAME).setNoParent().startSpan(); - try (Scope s = span.makeCurrent()) { - Thread.sleep(10); - } - span.end(); - - recording.dump(output); - } - - List events = RecordingFile.readAllEvents(output); - assertThat(events).hasSize(2); - assertThat(events) - .extracting(e -> e.getValue("traceId")) - .isEqualTo(span.getSpanContext().getTraceId()); - assertThat(events) - .extracting(e -> e.getValue("spanId")) - .isEqualTo(span.getSpanContext().getSpanId()); - assertThat(events) - .filteredOn(e -> "Span".equals(e.getEventType().getLabel())) - .extracting(e -> e.getValue("operationName")) - .isEqualTo(OPERATION_NAME); - - } finally { - Files.delete(output); - } - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 6c047f80ff0..fcd70dc1225 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -67,7 +67,6 @@ include(":sdk-extensions:aws") include(":sdk-extensions:resources") include(":sdk-extensions:incubator") include(":sdk-extensions:jaeger-remote-sampler") -include(":sdk-extensions:jfr-events") include(":testing-internal") val isCI = System.getenv("CI") != null