aws / aws-xray-sdk-java

The official AWS X-Ray Recorder SDK for Java.
Apache License 2.0
96 stars 99 forks source link

Support Lambda PassThrough trace header propagation #409

Closed majanjua-amzn closed 3 months ago

majanjua-amzn commented 3 months ago

Issue

Lambda is implementing PassThrough mode which allows customers to send traces through instrumented lambda functions without those functions being traced. The way this is done is by changing the trace header structure from Root=...;Parent=...;Sampled=1 in the active tracing case to Root=... in the PassThrough case. As such, our SDK needs to be updated to handle this.

Changes

Testing

Ran many extensive tests using v2.16.0, v2.17.0, and these changes to compare the outcomes. In these tests I configured 3 lambda functions to interact with each other ALL instrumented with the new changes:

The trace headers in the below cases are from logging System.getenv("_X_AMZN_TRACE_ID") in the lambda functions themselves

The following are some important cases that prove the functionality of the code change

Case 1.a: Lambda A Active → Lambda B PassThrough → Lambda C Active

A: Root=1-66abd797-167a78c02dcfeb4551890716;Parent=ad075ec25766d3f9;Sampled=1;Lineage=456f6a97:0
B: Root=1-66abd797-167a78c02dcfeb4551890716;Parent=57696313aea6f4a2;Sampled=1;Lineage=8408dcb0:0
C: Root=1-66abd797-167a78c02dcfeb4551890716;Parent=710d6393cf68bccc;Sampled=1;Lineage=7d2b6fd0:0

Image

Case 1.b: Same thing but Lambda A Active sets Sampled=0

A: Root=1-66b32340-6a4114ff44ca3e5240b1ac5b;Parent=63033870537134cd;Sampled=0;Lineage=456f6a97:0
B: Root=1-66b32340-6a4114ff44ca3e5240b1ac5b;Parent=63033870537134cd;Sampled=0;Lineage=8408dcb0:0
C: Root=1-66b32340-6a4114ff44ca3e5240b1ac5b;Parent=71d11ee442af5530;Sampled=0;Lineage=7d2b6fd0:0

Case 2: Lambda A PassThrough → Lambda B Active → Lambda C PassThrough

Case 3.a: Calling Lambda B PassThrough → Lambda C PassThrough

Case 3.b: Calling Lambda B Active → Lambda C Active

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.