Skip to content

Commit cde6ff8

Browse files
authored
feat: support java 17 & 21 (#61)
1 parent 501063e commit cde6ff8

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
![Version](https://img.shields.io/badge/version-1.0.40-green.svg)
55
[![codecov](https://codecov.io/gh/lumigo-io/java-tracer/branch/master/graph/badge.svg?token=D3IZ5hQwaQ)](https://codecov.io/gh/lumigo-io/java-tracer)
66

7-
Supported Runtimes: Java 8, Java 11
7+
Supported Runtimes: Java 8, Java 11, Java 17, Java 21
88

99
## Building With Lumigo
1010

1111
### Maven
12-
1312
Include lumigo java tracer dependency, for [Maven](https://maven.apache.org) projects, use:
1413

1514
```xml
@@ -99,7 +98,7 @@ class MyFunction implements RequestHandler<String, String> {
9998
}
10099
```
101100

102-
### Java 11 Support
101+
### Support Java 11 and Above
103102

104103
Add the environment variable `JAVA_TOOL_OPTIONS` to your Lambda functions and set it to
105104
`-Djdk.attach.allowAttachSelf=true` in addition to the manual code mentioned above.

pom.xml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@
2727
<organization>Lumigo</organization>
2828
<organizationUrl>https://lumigo.io/</organizationUrl>
2929
</developer>
30-
<developer>
31-
<name>Uri Parush</name>
32-
<email>uri@lumigo.io</email>
33-
<organization>Lumigo</organization>
34-
<organizationUrl>https://lumigo.io</organizationUrl>
35-
</developer>
36-
<developer>
37-
<name>Saar Tochner</name>
38-
<email>saart@lumigo.io</email>
39-
<organization>Lumigo</organization>
40-
<organizationUrl>https://lumigo.io</organizationUrl>
41-
</developer>
4230
</developers>
4331

4432
<organization>
@@ -161,12 +149,12 @@
161149
<dependency>
162150
<groupId>net.bytebuddy</groupId>
163151
<artifactId>byte-buddy</artifactId>
164-
<version>1.9.10</version>
152+
<version>1.14.14</version>
165153
</dependency>
166154
<dependency>
167155
<groupId>net.bytebuddy</groupId>
168156
<artifactId>byte-buddy-agent</artifactId>
169-
<version>1.9.10</version>
157+
<version>1.14.14</version>
170158
</dependency>
171159

172160
<!-- Testing dependencies -->

src/main/java/io/lumigo/core/SpansContainer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ private SpansContainer() {}
6262
public void init(Map<String, String> env, Reporter reporter, Context context, Object event) {
6363
this.clear();
6464
this.reporter = reporter;
65-
awsTracerId = env.get(AMZN_TRACE_ID);
65+
int javaVersion = AwsUtils.parseJavaVersion(System.getProperty("java.version"));
66+
if (javaVersion > 11) {
67+
awsTracerId = System.getProperty("com.amazonaws.xray.traceHeader");
68+
} else {
69+
awsTracerId = env.get(AMZN_TRACE_ID);
70+
}
71+
Logger.debug("awsTracerId {}", awsTracerId);
72+
6673
AwsUtils.TriggeredBy triggeredBy = AwsUtils.extractTriggeredByFromEvent(event);
6774
long startTime = System.currentTimeMillis();
6875
this.baseSpan =

src/main/java/io/lumigo/core/utils/AwsUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@ public static synchronized Span.READINESS getFunctionReadiness() {
243243
}
244244
}
245245

246+
public static int parseJavaVersion(String version) {
247+
try {
248+
String[] parts = version.split("\\.");
249+
250+
if (parts[0].equals("1")) {
251+
// For version before Java 9 the version looks like: 1.X.minor.
252+
// example 1.8.0 or 1.5.0.
253+
return Integer.parseInt(parts[1]);
254+
}
255+
// From java 9 the version looks like: 9.0.1 or 11.2.1 or 21.0.11,
256+
// So we only parse the first part.
257+
return Integer.parseInt(parts[0]);
258+
} catch (Exception e) {
259+
Logger.error("Failed to parse java version", e);
260+
return -1;
261+
}
262+
}
263+
246264
/**
247265
* This function seeks for the value of className in all the super classes of the given object.
248266
*

src/main/java/io/lumigo/handlers/LumigoRequestHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public OUTPUT handleRequest(INPUT input, Context context) {
4444
}
4545
try {
4646
Logger.debug("Start {} Lumigo tracer", LumigoRequestHandler.class.getName());
47+
Logger.debug("Envs {}", envUtil.getEnv());
4748
try {
4849
spansContainer.init(envUtil.getEnv(), reporter, context, input);
4950
Future<?> submit = executorService.submit(() -> Installer.install());

src/test/java/io/lumigo/core/utils/AwsUtilsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.json.JSONException;
88
import org.junit.jupiter.api.DisplayName;
99
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.params.ParameterizedTest;
11+
import org.junit.jupiter.params.provider.CsvSource;
1012
import org.skyscreamer.jsonassert.JSONAssert;
1113

1214
class AwsUtilsTest {
@@ -246,4 +248,20 @@ void test_extractTriggeredByFromEvent_scheduledEvent() throws JSONException {
246248
awsLambdaEventGenerator.scheduledEvent())),
247249
true);
248250
}
251+
252+
@ParameterizedTest
253+
@CsvSource({
254+
"1.5.0, 5",
255+
"1.8.151_a, 8",
256+
"10.0.1, 10",
257+
"17.0.10, 17",
258+
"21.0.3, 21",
259+
"22.0.1, 22",
260+
"notRealVersion, -1"
261+
})
262+
void test_parseJavaVersion_oldVersion(String rawVersion, int expectedVersion) throws Exception {
263+
int version = AwsUtils.parseJavaVersion(rawVersion);
264+
265+
assertEquals(expectedVersion, version);
266+
}
249267
}

0 commit comments

Comments
 (0)