Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lambda] new Segment does not appear when using facade as parent #379

Closed
bryanvaz opened this issue Feb 24, 2021 · 4 comments
Closed

[Lambda] new Segment does not appear when using facade as parent #379

bryanvaz opened this issue Feb 24, 2021 · 4 comments
Assignees
Labels

Comments

@bryanvaz
Copy link
Contributor

bryanvaz commented Feb 24, 2021

I'm trying to set the addIncomingRequestData in Lambda. Using this function on the facade Segment does not work, and X-Ray just seems to ignore the additional data:

// Koa middleware
const koaMw = async (ctx, next) => {
  const parent = AWSXRay.getSegment(); // returns the Lambda facade segment
  const segment = parent.addNewSubsegment('Koa');
  parent.addIncomingRequestData(new IncomingRequestData(ctx.req));
  await next(); // Continue Koa request execution
  segment.close();
  parent.http.close();
  // ... Lambda will close the facade segment, so don't worry
}

Screen Shot 2021-02-24 at 3 13 15 PM

As an alternative, I thought that if I created a new Segment and using Lambda's facade Segment's trace_id as the parent for the new Segment I could get it to work. Based on the X-Ray docs, I would expect this to create a new node on the service map that would be downstream from the lambda execution. This was even worse because X-Ray just ignored my new Segment completely.

// Koa middleware
const koaMw = async (ctx, next) => {
  const parent = AWSXRay.getSegment(); // returns the Lambda facade segment

  const amznTraceHeader = mwUtils.processHeaders(ctx);
  const segment = new Segment(
      'Koa',
      amznTraceHeader.Root || amznTraceHeader.root,
      parent.trace_id,
    );
  mwUtils.resolveSampling(amznTraceHeader, segment, ctx);
  segment.addIncomingRequestData(new IncomingRequestData(ctx.req));
  await next(); // Continue Koa request execution
  segment.http.close();
  segment.close();
  segment.flush();
  // ... Lambda will close the facade segment, so don't worry
}

Screen Shot 2021-02-24 at 3 17 37 PM

Is there anyway to create a new downstream service Segment on service map, separate from the Lambda node?
(I need some way to capture the HTTP request details because HTTP API Gateways do not support X-Ray)

Cheers,
Bryan

@bhautikpip bhautikpip self-assigned this Mar 2, 2021
@bhautikpip
Copy link
Contributor

Hi Bryan,

I think as reference from here, I believe segments created within lambda function are treated as facade segments hence no operation could be performed using that segment. I believe when you call parent.addIncomingRequestData(new IncomingRequestData(ctx.req)); from within your lambda function SDK treats that function call as no-op.

addIncomingRequestData(data: IncomingRequestData): void;
As per your original question this answer would explain better on having separate nodes on X-Ray console when you create segment within your lambda function.

@bryanvaz
Copy link
Contributor Author

bryanvaz commented Mar 5, 2021

@bhautikpip Yes, I'm aware of the no-op. that's why I thought using the facade as a parent and creating a new Segment would work.
Specifying the lambda facade as a parent should theoretically work, because it is the same thing that happens when you create a sub request to another service. In that scenario, the second service would use the lambda facade trace_id as the parent in order connect it to the same service graph.

As a note, if you create a new Segment without a parent, the node will show up, but without any relation to the lambda initialization and invocation node, which makes the waterfall kind of useless.

@bhautikpip
Copy link
Contributor

right. I think as per my understanding this case would be similar as having Express server deployed to lambda and Express middleware tries to create segment but Lambda facade segment will ignore that and on the X-Ray console you will only see one node AWS::Lambda::Function as being discussed here #45

@stale
Copy link

stale bot commented Jun 11, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in next 7 days. Thank you for your contributions.

@stale stale bot added the stale label Jun 11, 2021
@stale stale bot closed this as completed Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants