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

feat: add java 17 & 21 support #61

Merged
merged 6 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
![Version](https://img.shields.io/badge/version-1.0.40-green.svg)
[![codecov](https://codecov.io/gh/lumigo-io/java-tracer/branch/master/graph/badge.svg?token=D3IZ5hQwaQ)](https://codecov.io/gh/lumigo-io/java-tracer)

Supported Runtimes: Java 8, Java 11
Supported Runtimes: Java 8, Java 11, Java 17, Java 21

## Building With Lumigo

### Maven

Include lumigo java tracer dependency, for [Maven](https://maven.apache.org) projects, use:

```xml
Expand Down Expand Up @@ -99,7 +98,7 @@ class MyFunction implements RequestHandler<String, String> {
}
```

### Java 11 Support
### Support Java 11 and Above

Add the environment variable `JAVA_TOOL_OPTIONS` to your Lambda functions and set it to
`-Djdk.attach.allowAttachSelf=true` in addition to the manual code mentioned above.
16 changes: 2 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@
<organization>Lumigo</organization>
<organizationUrl>https://lumigo.io/</organizationUrl>
</developer>
<developer>
<name>Uri Parush</name>
<email>[email protected]</email>
<organization>Lumigo</organization>
<organizationUrl>https://lumigo.io</organizationUrl>
</developer>
<developer>
<name>Saar Tochner</name>
<email>[email protected]</email>
<organization>Lumigo</organization>
<organizationUrl>https://lumigo.io</organizationUrl>
</developer>
</developers>

<organization>
Expand Down Expand Up @@ -161,12 +149,12 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.9.10</version>
<version>1.14.14</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.9.10</version>
<version>1.14.14</version>
</dependency>

<!-- Testing dependencies -->
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/io/lumigo/core/SpansContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ private SpansContainer() {}
public void init(Map<String, String> env, Reporter reporter, Context context, Object event) {
this.clear();
this.reporter = reporter;
awsTracerId = env.get(AMZN_TRACE_ID);
int javaVersion = AwsUtils.parseJavaVersion(System.getProperty("java.version"));
if (javaVersion > 11) {
awsTracerId = System.getProperty("com.amazonaws.xray.traceHeader");
} else {
awsTracerId = env.get(AMZN_TRACE_ID);
}
Logger.debug("awsTracerId {}", awsTracerId);

AwsUtils.TriggeredBy triggeredBy = AwsUtils.extractTriggeredByFromEvent(event);
long startTime = System.currentTimeMillis();
this.baseSpan =
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/lumigo/core/utils/AwsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ public static synchronized Span.READINESS getFunctionReadiness() {
}
}

public static int parseJavaVersion(String version) {
try {
String[] parts = version.split("\\.");

if (parts[0].equals("1")) {
// For version before Java 9 the version looks like: 1.X.minor.
// example 1.8.0 or 1.5.0.
return Integer.parseInt(parts[1]);
}
// From java 9 the version looks like: 9.0.1 or 11.2.1 or 21.0.11,
// So we only parse the first part.
return Integer.parseInt(parts[0]);
} catch (Exception e) {
Logger.error("Failed to parse java version", e);
return -1;
nadav3396 marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* This function seeks for the value of className in all the super classes of the given object.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/lumigo/handlers/LumigoRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public OUTPUT handleRequest(INPUT input, Context context) {
}
try {
Logger.debug("Start {} Lumigo tracer", LumigoRequestHandler.class.getName());
Logger.debug("Envs {}", envUtil.getEnv());
try {
spansContainer.init(envUtil.getEnv(), reporter, context, input);
Future<?> submit = executorService.submit(() -> Installer.install());
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/lumigo/core/utils/AwsUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.json.JSONException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.skyscreamer.jsonassert.JSONAssert;

class AwsUtilsTest {
Expand Down Expand Up @@ -246,4 +248,20 @@ void test_extractTriggeredByFromEvent_scheduledEvent() throws JSONException {
awsLambdaEventGenerator.scheduledEvent())),
true);
}

@ParameterizedTest
@CsvSource({
"1.5.0, 5",
"1.8.151_a, 8",
"10.0.1, 10",
"17.0.10, 17",
"21.0.3, 21",
"22.0.1, 22",
"notRealVersion, -1"
})
void test_parseJavaVersion_oldVersion(String rawVersion, int expectedVersion) throws Exception {
int version = AwsUtils.parseJavaVersion(rawVersion);

assertEquals(expectedVersion, version);
}
}