Skip to content

[Serverless] remove LambdaContext - #3531

Merged
maxday merged 19 commits into
masterfrom
maxday/remove-lambda-context
Jun 7, 2022
Merged

maxday merged 19 commits into
masterfrom
maxday/remove-lambda-context

Conversation

@maxday

@maxday maxday commented Apr 29, 2022

Copy link
Copy Markdown
Contributor

What Does This Do

Following this PR : #3506 and DataDog/datadog-agent#11825
LambdaHandler is not needed anymore which simplifies the code

Motivation

Additional Notes

@maxday maxday added the tag: do not merge Do not merge changes label Apr 29, 2022
@maxday
maxday requested a review from a team as a code owner April 29, 2022 19:41
@maxday maxday changed the title [WIP][Serverless] remove LambdaContext [Serverless] remove LambdaContext May 18, 2022
@maxday maxday removed the tag: do not merge Do not merge changes label May 18, 2022

@devinsba devinsba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the one constant that should be moved

AgentSpan span =
startSpan(UTF8BytesString.create("dd-tracer-serverless-span"), lambdaContext);
final AgentSpan span;
final UTF8BytesString invocationSpan = UTF8BytesString.create("dd-tracer-serverless-span");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pull this to a location where it can be static? LambdaHandler.java is probably a good place

@maxday
maxday requested a review from devinsba May 19, 2022 23:31
traceID,
samplingPriority);
return new ExtractedContext(
DDId.from(traceID), DDId.ZERO, samplingPriority, DEFAULT, null, 0, null, null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this line says that this lambda will have a parent with span ID 0 (so it will be a root span), what about the case of one lambda calling another? Is the lambda layer doing some remapping outside the javaagent that we don't see here?

Maybe a class comment that outlines the flow would be helpful

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'll add a comment.
Basically this span will be dropped by the extension since the extension is creating the top level invocation span on its own to avoid duplicating the logic of parsing the context in 6 different runtimes (this is our universal instrumentation project)
We just need this span for any subsequent created spans (custom spans or auto instrumented spans) so they will parented to this span and the trace will be consistent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a valid trace when a Lambda is calling another Lambda
Screen Shot 2022-05-20 at 12 22 24 PM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind posting the json too?

Also would it be possible for us to integration test this? Can we run the lambda layer as a docker container?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure how the children end up with the correct parent, since the extension will have a span ID that the Java code won't know, unless the extension uses the span ID we communicate back in the notifyEndInvocation headers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I am saying here is: if the customer attempts to modify the active span during their handler code, adding tags for example, do those changes get lost? Or do they get copied into the extensions span?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see, sorry for the confusion. Indeed they would be lost.
Only extra tags provided via environment variables DD_TAGS or DD_EXTRA_TAGS / datadog.yml config file would be kept.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm Ok with this if this shortcoming is documented somewhere (so that support can point users there). If you can point me to a docs PR or somewhere in the serverless docs that show this then I can 👍 the PR

I expect that this will surprise users so I don't want a bunch of support requests getting to our team

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not able to alter the Datadog generated lambda span is OK. We did hear from customers a lot in the past on how to tag the lambda span with an invocation/request specific tag (such as user id, etc.) However, with the recent support of capturing the request/response payloads into the lambda span OOB https://docs.datadoghq.com/serverless/configuration?tab=datadogcli#collect-the-request-and-response-payloads, I expect majority of customers no longer need to add custom tags to the lambda span any longer, because all the invocation specific information can already be captured to the span automatically. For custom tags that don't vary invocation by invocation, customers can use DD_TAGS.

Speaking of doc, I suggest adopting the lazy approach here to avoid confusing customers with things they don't even need to know. That said, I suggest only documenting this shortcoming in the release notes as a breaking change (java tracing is relatively new to serverless, don't expect customers actually are adding custom tags to the lambda span today). If customers prove that we are wrong and they still have a valid reason to add custom invocation-specific tags to the lambda span that we generate, I think we should actually come up with a solution to support that somehow instead of documenting it as a shortcoming/limitation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to remember this as we gain more java users

@maxday
maxday requested a review from devinsba May 20, 2022 16:25
@maxday
maxday merged commit 5cb8bc5 into master Jun 7, 2022
@maxday
maxday deleted the maxday/remove-lambda-context branch June 7, 2022 15:29
@github-actions github-actions Bot added this to the 0.103.0 milestone Jun 7, 2022
@devinsba devinsba added the tag: serverless Serverless support label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: serverless Serverless support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants