diff --git a/README.md b/README.md index 8c0418d1..5b23c101 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ Provides OpenTelemetry Exporters for Google Cloud Operations. ## Building -This project requires a mock server for Google Cloud APIs. To build and test, do the following: +> [!IMPORTANT] +> This project requires Java 11 to build and test. All artifacts published from this project support Java 8 or higher, unless otherwise noted. + +This project requires a mock server for Google Cloud APIs. To build and test, do the following: ``` $ ./gradlew test diff --git a/build.gradle b/build.gradle index 0b594182..62b94b9c 100644 --- a/build.gradle +++ b/build.gradle @@ -85,9 +85,6 @@ subprojects { group = "com.google.cloud.opentelemetry" // Note: Version now comes from nebula plugin - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - repositories { mavenCentral() mavenLocal() @@ -103,6 +100,24 @@ subprojects { archivesBaseName = "${project.name}" } + // Support for some higher language versions can only be achieved using Toolchains. + // Compatibility matrix at https://docs.gradle.org/current/userguide/compatibility.html#java + // See https://docs.gradle.org/current/userguide/toolchains.html#toolchains + java { + toolchain { + languageVersion = JavaLanguageVersion.of(11) + } + } + + // This ensures bytecode compatibility with Java 8 by ensuring that symbols not + // available in Java 8 are not used in the source code. + // This is equivalent of setting --release flag in Java compiler introduced in Java 9. + // Note that the toolchain used is Java 11 - which means Java 11 is required + // to build this project. + compileJava { + it.options.release = 8 + } + // Include license check and auto-format support. spotless { java { @@ -234,12 +249,6 @@ subprojects { archives javadocJar, sourcesJar } - javadoc { - if(JavaVersion.current().isJava9Compatible()) { - options.addBooleanOption('html5', true) - } - } - java { withJavadocJar() withSourcesJar() diff --git a/detectors/resources-support/build.gradle b/detectors/resources-support/build.gradle index b7022a5e..29737c2a 100644 --- a/detectors/resources-support/build.gradle +++ b/detectors/resources-support/build.gradle @@ -24,12 +24,6 @@ dependencies { testRuntimeOnly(testLibraries.junit5_runtime) } -afterEvaluate { - tasks.named("compileJava"){ - options.release = 8 - } -} - test { // required for discovering JUnit 5 tests useJUnitPlatform() diff --git a/detectors/resources/build.gradle b/detectors/resources/build.gradle index cf76652b..ebe7a8d3 100644 --- a/detectors/resources/build.gradle +++ b/detectors/resources/build.gradle @@ -15,12 +15,6 @@ */ description = 'Google Cloud resource provider for OpenTelemetry' -afterEvaluate { - tasks.named("compileJava"){ - options.release = 8 - } -} - dependencies { implementation(libraries.opentelemetry_api) implementation(libraries.opentelemetry_sdk) diff --git a/e2e-test-server/README.md b/e2e-test-server/README.md index f7d154fa..ba622c3e 100644 --- a/e2e-test-server/README.md +++ b/e2e-test-server/README.md @@ -1,12 +1,15 @@ # End to End tests +> [!NOTE] +> This module requires at least Java 11 to run. + A set of end to end integration tests. These are run inside various environments to ensure GCP automagiks work and data flows into google cloud. ## Building a Docker image. -From the *root* directory of the projet, run: +From the *root* directory of the project, run: ``` docker build . --file=e2e.Dockerfile diff --git a/e2e-test-server/build.gradle b/e2e-test-server/build.gradle index 3d71636b..2ed92c91 100644 --- a/e2e-test-server/build.gradle +++ b/e2e-test-server/build.gradle @@ -23,6 +23,14 @@ application { mainClass.set('com.google.cloud.opentelemetry.endtoend.Server') } +// Java 11 required to build this module since it has a dependency on Cloud Functions. +// Cloud Functions (Gen2) have Java 11 minimum requirement. +compileJava{ + // This is only possible since the toolchain guarantees Java 11 presence. + // Toolchain is set in the root build.gradle file. + it.options.release = 11 +} + description = 'End-To-End integration testing server' shadowJar { diff --git a/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java b/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java index 40966945..ec5f6e03 100644 --- a/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java +++ b/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java @@ -39,7 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -167,7 +167,7 @@ private Attributes instrumentationLibraryLabels( instrumentationScopeInfo.getName()) .put( AttributeKey.stringKey(LABEL_INSTRUMENTATION_VERSION), - Objects.requireNonNullElse(instrumentationScopeInfo.getVersion(), "")) + Optional.ofNullable(instrumentationScopeInfo.getVersion()).orElse("")) .build(); } diff --git a/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/InternalTraceExporter.java b/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/InternalTraceExporter.java index dfd84fd9..87a20ae9 100644 --- a/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/InternalTraceExporter.java +++ b/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/InternalTraceExporter.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -53,7 +54,8 @@ class InternalTraceExporter implements SpanExporter { private final TraceTranslator translator; private static final Map HEADERS = - Map.of("User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION); + Collections.singletonMap( + "User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION); private static final HeaderProvider HEADER_PROVIDER = () -> HEADERS; private static InternalTraceExporter createWithClient(