Repository navigation
[Serverless] Auto-instrument AWS Lambda Handler - #3506
Conversation
| implementation deps.okhttp | ||
|
|
||
| api 'com.fasterxml.jackson.core:jackson-core:2.11.0' | ||
| api 'com.fasterxml.jackson.core:jackson-databind:2.11.0' |
There was a problem hiding this comment.
I am not sure how bad this is for non serverless usage
We definitely need Jackson (or similar) to send a JSON version of the context / user event but maybe we could load this only for a serverless build?
|
|
||
| @Override | ||
| public String instrumentedType() { | ||
| return this.instrumentedType; |
There was a problem hiding this comment.
I'll start the ball rolling (this is not a full review, just a few things I noticed):
Edit: I realize DummyContext assumes the ids rather than using it as a parentDummyContextis not needed. Since the headers returned are the standard datadog headers, you can use the normal extraction mechanism. Seepropagate().extract()
There are problems with the dependencies. Adding classes to the bootstrap means they will be at the top of the classpath hierarchy, with something like jackson, this is sure to cause conflicts.
(normally)
LambdaHandlershould be in the instrumentation module and listed as a helper class- Dependencies should be listed in the instrumentation module
- We use
Moshifor JSON serialization
The bigger issue is that all classes used by the instrumentation need to be injected into the instrumented classloader. So even just using okhttp and moshi means injecting a lot of classes (all of which have to be listed as helpers).
The correct solution is probably implementing the LambdaHandler in dd-trace-core and having the instrumentation call that. This way, there are no extra dependencies and you can reuse the Okhttp client
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| public class DummyLambdaContext implements AgentSpan.Context { |
There was a problem hiding this comment.
I think that this context is not needed, and the code could just use the ExtractedContext and only fill in the interesting values in it. That would also mean that the changes to buildSpanContext can be removed as well.
There was a problem hiding this comment.
Ah, I just realized that the spanId part is different. Still think that it could have a better name and extend ExtractedContext with that part.
There was a problem hiding this comment.
you're right! I've renamed it to LambdaContext which now extends ExtractedContext. This has also drastically simplified the changes to CoreTracer
bantonsson
left a comment
There was a problem hiding this comment.
LGTM
There is failure in the check task that needs to be fixed. You can see the problem here https://output.circle-artifacts.com/output/job/31aaaaf5-9915-4b41-8399-e4e2a6bc9817/artifacts/0/reports/dd-trace-core/codenarc/test.html
If you want to run the check locally, then do:
./gradlew dd-trace-core:check -PskipTests
|
Also, please |
|
Some more check failures 😉 This will run |
|
|
||
| private static final String DATADOG_TRACE_ID = "x-datadog-trace-id"; | ||
| private static final String DATADOG_SPAN_ID = "x-datadog-span-id"; | ||
| private static final String DATADOG_SAMPLING_PRIORITY = "x-datadog-sampling-priority"; |
What Does This Do
Add support for AWS Handler auto-instrumentation
Note : Since the invocation span is created in the extension (to unify logic to detect downstream AWS services across all AWS Lambda supported runtimes), we need to create a
dummy spanwith the exact same spanID + traceID. This allows any newly created span inherit from the correct context.Motivation
Code-free instrumentation for AWS Lambda