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

Add Java8 support #353

Merged
merged 16 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -103,6 +100,26 @@ 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.
afterEvaluate {
psx95 marked this conversation as resolved.
Show resolved Hide resolved
tasks.named("compileJava"){
options.release = 8
}
}

// Include license check and auto-format support.
spotless {
java {
Expand Down Expand Up @@ -234,12 +251,6 @@ subprojects {
archives javadocJar, sourcesJar
}

javadoc {
Copy link
Contributor Author

@psx95 psx95 Jun 22, 2024

Choose a reason for hiding this comment

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

Minimum JDK version required for building this project is JDK 11, html5 is default and is no longer required.

if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

java {
withJavadocJar()
withSourcesJar()
Expand Down
6 changes: 0 additions & 6 deletions detectors/resources-support/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ dependencies {
testRuntimeOnly(testLibraries.junit5_runtime)
}

afterEvaluate {
tasks.named("compileJava"){
options.release = 8
}
}

test {
// required for discovering JUnit 5 tests
useJUnitPlatform()
Expand Down
6 changes: 0 additions & 6 deletions detectors/resources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion e2e-test-server/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 10 additions & 0 deletions e2e-test-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ 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.
afterEvaluate {
psx95 marked this conversation as resolved.
Show resolved Hide resolved
tasks.named("compileJava"){
// This is only possible since the toolchain guarantees Java 11 presence.
// Toolchain is set in the root build.gradle file.
options.release = 11
}
}

description = 'End-To-End integration testing server'

shadowJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.opentelemetry.trace;

import static com.google.api.client.util.Preconditions.checkNotNull;
import static java.util.AbstractMap.SimpleEntry;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.core.NoCredentialsProvider;
Expand All @@ -40,6 +41,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* This class encapsulates internal implementation details for exporting spans to Google Cloud
Expand All @@ -53,7 +56,10 @@ class InternalTraceExporter implements SpanExporter {
private final TraceTranslator translator;

private static final Map<String, String> HEADERS =
Map.of("User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION);
Stream.of(
psx95 marked this conversation as resolved.
Show resolved Hide resolved
new SimpleEntry<>(
"User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION))
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));
private static final HeaderProvider HEADER_PROVIDER = () -> HEADERS;

private static InternalTraceExporter createWithClient(
Expand Down
Loading