Skip to content

Commit

Permalink
Allow lambda passthrough trace header
Browse files Browse the repository at this point in the history
  • Loading branch information
majanjua-amzn committed Jun 7, 2024
1 parent 1502470 commit c49f12e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/core/lib/patchers/aws3_p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ const getXRayMiddleware = (config: RegionResolvedConfig, manualSegment?: Segment
}
}

args.request.headers['X-Amzn-Trace-Id'] = traceHeader;
if (!segment.noOp) {
args.request.headers['X-Amzn-Trace-Id'] = traceHeader;
}

let res;
try {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/lib/patchers/aws_p.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ function captureAWSRequest(req) {
const data = parent.segment ? parent.segment.additionalTraceData : parent.additionalTraceData;

var buildListener = function(req) {
if (parent.noOp) {
return;
}
let traceHeader = 'Root=' + traceId + ';Parent=' + subsegment.id +
';Sampled=' + (subsegment.notTraced ? '0' : '1');
if (data != null) {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/lib/patchers/http_p.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ function enableCapture(module, downstreamXRayEnabled, subsegmentCallback) {
options.headers = {};
}

options.headers['X-Amzn-Trace-Id'] = 'Root=' + root.trace_id + ';Parent=' + subsegment.id +
';Sampled=' + (subsegment.notTraced ? '0' : '1');
if (!parent.noOp) {
options.headers['X-Amzn-Trace-Id'] = 'Root=' + root.trace_id + ';Parent=' + subsegment.id +
';Sampled=' + (subsegment.notTraced ? '0' : '1');
}

const errorCapturer = function errorCapturer(e) {
if (subsegmentCallback) {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ var utils = {
if (!traceData) {
traceData = {};
logger.getLogger().error('_X_AMZN_TRACE_ID is empty or has an invalid format');
} else if (traceData.root && !traceData.parent && !traceData.sampled) {
// Lambda PassThrough only has root, treat as valid in this case and mark the segment
segment.noOp = true;
valid = true;
} else if (!traceData.root || !traceData.parent || !traceData.sampled) {
logger.getLogger().error('_X_AMZN_TRACE_ID is missing required information');
} else {
Expand Down

0 comments on commit c49f12e

Please sign in to comment.