Skip to content

Lambda- successive invocations reusing first invocation's facade segment #405

Open
@Dave-McCraw

Description

@Dave-McCraw

Successive invocations of a lambda are adding to the trace of the initial invocation. I presume I've got this set up incorrectly but I'm struggling to identify what it is.

The first invocation trace looks like:

image

A later one looks like this:

image

Simplified code:

const AWSXRay = require("aws-xray-sdk");
const AWS = AWSXRay.captureAWS(require("aws-sdk"));
const AWS_EXECUTION_ENV = process.env.AWS_EXECUTION_ENV;

async function processLocation(event) {
  AWSXRay.setContextMissingStrategy(() => {});
  xrayEnabled = !!AWS_EXECUTION_ENV;

  if (xrayEnabled) {
    let facadeSegment = AWSXRay.getSegment();
    console.log("Starting segment is called: " + facadeSegment.name); 
    let segment = facadeSegment.addNewSubsegment("Root");
    AWSXRay.setSegment(segment);
    segment.addMetadata("event data", JSON.stringify(event));
  }

The log statement outputs:

image

Any pointers?

Later in the lambda I call AWSXRay.setSegment(subSegment); before making parallel HTTP calls otherwise I found the auto-instrumented segments using captureHTTPsGlobal wouldn't attach to the correct parent segments. It's around here that it smells bad to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions