You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I make requests using the Fetch API and using Tracer, the X-Amzn-Trace-Id header should be constructed and forwarded along with the request so that I can get a full trace for a request.
For example, if I have an API Gateway A -> Lambda A -> API Gateway B -> Lambda B, and the first function in the chain is instrumented with Tracer, we should be able to see a trace like this:
This is already supported when using the global http and https modules and their derivatives (i.e. axios) but doesn't work in our implementation when using Tracer with fetch.
Current Behavior
Currently the setup described above generates two disconnected traces, one for each API Gateway -> Lambda pair.
Make a request to the first API Gateway endpoint (i.e. http POST https://api-id.execute-api.eu-west-1.amazonaws.com/stage/functionA userId=1
Observe the traces
Possible Solution
Our implementation of the fetch module diverges significantly from the one in aws-xray-sdk-node-fetch. Their implementation relies on monkey patching, which as far as I can tell would only work with CJS.
During the implementation, we followed the types present in @types/node which suggest it's not possible to modify the Request object when instrumenting.
In reality however request object in the message has a addHeader() method that can be used to forward the X-Amzn-Trace-Id.
To make this work, we should construct the header to include the Root, Parent, and Sampled fields and add it to the request. I made a PoC of this and I already got it working. The screenshot at the top of the issue comes from a request instrumented with Tracer using Fetch.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered:
Expected Behavior
When I make requests using the Fetch API and using Tracer, the
X-Amzn-Trace-Id
header should be constructed and forwarded along with the request so that I can get a full trace for a request.For example, if I have an API Gateway A -> Lambda A -> API Gateway B -> Lambda B, and the first function in the chain is instrumented with Tracer, we should be able to see a trace like this:
This is already supported when using the global
http
andhttps
modules and their derivatives (i.e.axios
) but doesn't work in our implementation when using Tracer withfetch
.Current Behavior
Currently the setup described above generates two disconnected traces, one for each API Gateway -> Lambda pair.
Code snippet
Steps to Reproduce
http POST https://api-id.execute-api.eu-west-1.amazonaws.com/stage/functionA userId=1
Possible Solution
Our implementation of the
fetch
module diverges significantly from the one inaws-xray-sdk-node-fetch
. Their implementation relies on monkey patching, which as far as I can tell would only work with CJS.On our side we decided (#1619) to instead use the
node:diagnostics_channel
which is the recommended way to instrument requests made withfetch
.During the implementation, we followed the types present in
@types/node
which suggest it's not possible to modify theRequest
object when instrumenting.In reality however
request
object in themessage
has aaddHeader()
method that can be used to forward theX-Amzn-Trace-Id
.To make this work, we should construct the header to include the
Root
,Parent
, andSampled
fields and add it to the request. I made a PoC of this and I already got it working. The screenshot at the top of the issue comes from a request instrumented with Tracer using Fetch.Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered: