Ramya Karuna
Ramya Karuna

Reputation: 61

Failed to get the current sub/segment from the context and addAnnotation of NULL issue in NodeJS

I am getting "Failed to get the current sub/segment from the context" with node lambda. AFter adding environment variable as suggested in another post, I am getting addAnnotation of NULL. Because of this my test are getting failed.

Is there any workaround to make this pass? Help is much appreciated.

Upvotes: 0

Views: 3916

Answers (1)

AWSSandra
AWSSandra

Reputation: 384

Which other post are you referring to? Can you post the code to reproduce?

When in Lambda, X-Ray does not have access to the segment. The segment is created by Lambda and sent independently. In order for the X-Ray service to reconstruct the full segment/subsegment structure, the SDK picks up an environment varibale set by Lambda, and creates a "facade segment". This represents a placeholder to build off of and cannot be modified.

Typically we advise to create a new subsegment and add the annotation there. Keep in mind, this will only work within the handler.

Upvotes: 2

Related Questions