2

As I understand, XRay has to be initialized before every AWS clients, and http clients if I want to also trace outgoing http requests. This is the code for XRay initialization.

import aws from 'aws-sdk'
import AWSXRay from 'aws-xray-sdk'
import http from 'http'
import https from 'https'

AWSXRay.captureHTTPsGlobal(http)
AWSXRay.captureHTTPsGlobal(https)
AWSXRay.capturePromise()
AWSXRay.captureAWS(aws)

It seems easy for a single lambda. However, I have a NodeJS serverless project which has a bunch of lambdas, and many more will be added soon. I'm finding a solution that meets

  • No code duplicate for the initialization
  • The initialization is done more or less automatically for developers. I don't want the developers to manually initialize xray during development

I'm thinking about a module, named 'xray-initialization.ts', and hopefully inject import './xray-initialization' into a lambda handler with a build tool. Is it feasible?

Hung Tran
  • 1,595
  • 2
  • 17
  • 17

0 Answers0