aws / aws-xray-sdk-node

The official AWS X-Ray SDK for Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

captureHTTPsGlobal intercepting RAPIDClient.postInitError

icholy opened this issue · comments

I'm getting the following error in one of my lambdas:

ERROR	Error: Missing AWS Lambda trace data for X-Ray. Ensure Active Tracing is enabled and no subsegments are created outside the function handler.
    at Object.contextMissingLogError [as contextMissing] (/var/task/lambda.js:40055:27)
    at Segment.resolveLambdaTraceData (/var/task/lambda.js:40428:49)
    at Object.getSegment (/var/task/lambda.js:40125:25)
    at Object.resolveSegment (/var/task/lambda.js:40104:25)
    at captureOutgoingHTTPs (/var/task/lambda.js:42220:37)
    at Object.captureHTTPsRequest [as request] (/var/task/lambda.js:42309:16)
    at RAPIDClient._post (file:///var/runtime/index.mjs:510:33)
    at RAPIDClient.postInitError (file:///var/runtime/index.mjs:460:14)
    at Object.uncaughtException (file:///var/runtime/index.mjs:1177:14)
    at process.<anonymous> (file:///var/runtime/index.mjs:1185:20)

It appears that there's an uncaught exception somewhere in my init code. The lambda runtime is attempting to report the error to some http endpoint. However, the xray instrumentation is preventing that from working.

I know I can set AWS_XRAY_CONTEXT_MISSING, but I feel like the xray sdk should work with the runtime without any additional workarounds.

Can you please provide an overview of any upstream services that may be calling this Lambda function, and if possible, share your init code that is throwing this error?

As mentioned in the error message, can you also please ensure that Active Tracing is enabled on this Lambda and that all subsegments (including the AWSXRay.captureHTTPsGlobal line) are being created within the Lambda handler?

Why would AWSXRay.captureHTTPsGlobal be called in the handler? It seems like you'd only want to install those hooks once during init.

I'll try to get you a simple repro.

Lambda creates a facade parent segment at the beginning of the handler function, so any custom subsegments or initialization of instrumentation should be initialized inside the function handler to be captured and have the Lambda facade segment as their parent.

Providing a sample of your implementation (including the "init" step where the instrumentations are initialized) would be very helpful in debugging this further.