Skip to content

Commit f93664f

Browse files
M-ElsaeedMohammed Ehab
andcommitted
MultiConcurrent XRAY TraceID using utils-lite (#96)
Co-authored-by: Mohammed Ehab <moehabe@amazon.com>
1 parent e61bc63 commit f93664f

File tree

3 files changed

+258
-21
lines changed
  • aws-lambda-java-runtime-interface-client

3 files changed

+258
-21
lines changed

aws-lambda-java-runtime-interface-client/pom.xml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.amazonaws</groupId>
66
<artifactId>aws-lambda-java-runtime-interface-client</artifactId>
@@ -47,9 +47,9 @@
4747
separately from the Runtime Interface Client functionality until we figure something else out.
4848
-->
4949
<multiArch>true</multiArch>
50-
<target_build_os/>
51-
<target_build_arch/>
52-
<ric.classifier/>
50+
<target_build_os />
51+
<target_build_arch />
52+
<ric.classifier />
5353
<!--
5454
Some test/integration/codebuild/buildspec.*.yml files will set -DargLineForReflectionTestOnly=""
5555
as this is not supported by all flavors of java
@@ -68,7 +68,11 @@
6868
<artifactId>aws-lambda-java-serialization</artifactId>
6969
<version>1.1.6</version>
7070
</dependency>
71-
71+
<dependency>
72+
<groupId>software.amazon.awssdk</groupId>
73+
<artifactId>utils-lite</artifactId>
74+
<version>2.34.0</version>
75+
</dependency>
7276
<dependency>
7377
<groupId>org.junit.jupiter</groupId>
7478
<artifactId>junit-jupiter-engine</artifactId>
@@ -152,11 +156,11 @@
152156
<configuration>
153157
<target name="Build JNI libraries for tests">
154158
<exec executable="${project.basedir}/src/main/jni/build-jni-lib.sh"
155-
failonerror="true" logError="true">
156-
<arg value="${project.build.directory}"/>
157-
<arg value="false"/>
158-
<arg value="${target_build_os}"/>
159-
<arg value="${target_build_arch}"/>
159+
failonerror="true" logError="true">
160+
<arg value="${project.build.directory}" />
161+
<arg value="false" />
162+
<arg value="${target_build_os}" />
163+
<arg value="${target_build_arch}" />
160164
</exec>
161165
</target>
162166
</configuration>
@@ -170,11 +174,11 @@
170174
<configuration>
171175
<target name="Build JNI libraries">
172176
<exec executable="${project.basedir}/src/main/jni/build-jni-lib.sh"
173-
failonerror="true" logError="true">
174-
<arg value="${project.build.directory}"/>
175-
<arg value="${multiArch}"/>
176-
<arg value="${target_build_os}"/>
177-
<arg value="${target_build_arch}"/>
177+
failonerror="true" logError="true">
178+
<arg value="${project.build.directory}" />
179+
<arg value="${multiArch}" />
180+
<arg value="${target_build_os}" />
181+
<arg value="${target_build_arch}" />
178182
</exec>
179183
</target>
180184
</configuration>
@@ -269,7 +273,7 @@
269273
</execution>
270274
</executions>
271275
</plugin>
272-
<plugin>
276+
<plugin>
273277
<groupId>org.apache.maven.plugins</groupId>
274278
<artifactId>maven-checkstyle-plugin</artifactId>
275279
<version>${maven-checkstyle-plugin.version}</version>

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/AWSLambda.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.concurrent.ExecutorService;
4141
import java.util.concurrent.Executors;
4242
import java.util.concurrent.TimeUnit;
43+
import software.amazon.awssdk.utilslite.SdkInternalThreadLocal;
4344

4445
/**
4546
* The entrypoint of this class is {@link AWSLambda#startRuntime}. It performs two main tasks:
@@ -73,6 +74,8 @@ public class AWSLambda {
7374
private static final String INIT_TYPE_SNAP_START = "snap-start";
7475

7576
private static final String AWS_LAMBDA_INITIALIZATION_TYPE = System.getenv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_INITIALIZATION_TYPE);
77+
78+
private static final String CONCURRENT_TRACE_ID_KEY = "AWS_LAMBDA_X_TRACE_ID";
7679

7780
static {
7881
// Override the disabledAlgorithms setting to match configuration for openjdk8-u181.
@@ -304,7 +307,11 @@ private static void startRuntimeLoop(LambdaRequestHandler lambdaRequestHandler,
304307
try {
305308
UserFault userFault = null;
306309
InvocationRequest request = exitLoopOnErrors ? runtimeClient.nextInvocation() : runtimeClient.nextInvocationWithExponentialBackoff(lambdaLogger);
307-
setEnvVarForXrayTraceId(request);
310+
if (exitLoopOnErrors) {
311+
setEnvVarForXrayTraceId(request);
312+
} else {
313+
SdkInternalThreadLocal.put(CONCURRENT_TRACE_ID_KEY, request.getXrayTraceId());
314+
}
308315

309316
try {
310317
ByteArrayOutputStream payload = lambdaRequestHandler.call(request);
@@ -321,6 +328,8 @@ private static void startRuntimeLoop(LambdaRequestHandler lambdaRequestHandler,
321328
if (userFault != null) {
322329
lambdaLogger.log(userFault.reportableError(), lambdaLogger.getLogFormat() == LogFormat.JSON ? LogLevel.ERROR : LogLevel.UNDEFINED);
323330
}
331+
332+
SdkInternalThreadLocal.remove(CONCURRENT_TRACE_ID_KEY);
324333
}
325334
} catch (Throwable t) {
326335
if (exitLoopOnErrors || t instanceof LambdaRuntimeClientMaxRetriesExceededException) {

0 commit comments

Comments
 (0)