diff --git a/README.md b/README.md index 7d84221..31604a1 100644 --- a/README.md +++ b/README.md @@ -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 @@ -99,7 +98,7 @@ class MyFunction implements RequestHandler { } ``` -### 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. diff --git a/pom.xml b/pom.xml index e9c384b..5019453 100644 --- a/pom.xml +++ b/pom.xml @@ -27,18 +27,6 @@ Lumigo https://lumigo.io/ - - Uri Parush - uri@lumigo.io - Lumigo - https://lumigo.io - - - Saar Tochner - saart@lumigo.io - Lumigo - https://lumigo.io - @@ -161,12 +149,12 @@ net.bytebuddy byte-buddy - 1.9.10 + 1.14.14 net.bytebuddy byte-buddy-agent - 1.9.10 + 1.14.14 diff --git a/src/main/java/io/lumigo/core/SpansContainer.java b/src/main/java/io/lumigo/core/SpansContainer.java index c8c692e..04ff49d 100644 --- a/src/main/java/io/lumigo/core/SpansContainer.java +++ b/src/main/java/io/lumigo/core/SpansContainer.java @@ -62,7 +62,14 @@ private SpansContainer() {} public void init(Map 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 = diff --git a/src/main/java/io/lumigo/core/utils/AwsUtils.java b/src/main/java/io/lumigo/core/utils/AwsUtils.java index e0b8547..b78867c 100644 --- a/src/main/java/io/lumigo/core/utils/AwsUtils.java +++ b/src/main/java/io/lumigo/core/utils/AwsUtils.java @@ -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; + } + } + /** * This function seeks for the value of className in all the super classes of the given object. * diff --git a/src/main/java/io/lumigo/handlers/LumigoRequestHandler.java b/src/main/java/io/lumigo/handlers/LumigoRequestHandler.java index aa626dc..d32cede 100644 --- a/src/main/java/io/lumigo/handlers/LumigoRequestHandler.java +++ b/src/main/java/io/lumigo/handlers/LumigoRequestHandler.java @@ -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()); diff --git a/src/test/java/io/lumigo/core/utils/AwsUtilsTest.java b/src/test/java/io/lumigo/core/utils/AwsUtilsTest.java index 4281fa5..753b85d 100644 --- a/src/test/java/io/lumigo/core/utils/AwsUtilsTest.java +++ b/src/test/java/io/lumigo/core/utils/AwsUtilsTest.java @@ -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 { @@ -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); + } }