getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Sentry Lambda layer with mockserver issue #4175

Closed luchees closed 2 years ago

luchees commented 2 years ago

Package + Version

Version:

arn:aws:lambda:ap-southeast-1:943013980633:layer:SentryNodeServerlessSDK:34

Description

We are using Sentry as a Layer in Lambda. We run integration tests on our Lambdas with mockserver. When making calls to mockserver to mock certain AWS calls we trigger sentry errors. The layer is very hard to debug and we do not know how to disable this without deleting the layer.

Mockserver is using a self signed certificate

When removing the lambda layer and the NODE_OPTIONS '-r @sentry/serverless/dist/awslambda-auto ' It works

“Error: Protocol \“http:\” not supported. Expected \“https:\“”,       

image

luchees commented 2 years ago

We found the issue:

Serverless lambda auto-sentry wrapped all node requests with custom function but it determine protocol by looking into httpAgent.protocol https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/integrations/utils/http.ts#L164-L167

Default agent it already has protocol on the root of object

Agent {                                             
  _events: [Object: null prototype] {               
    free: [Function (anonymous)],                   
    newListener: [Function: maybeEnableKeylog]      
  },                                                
  _eventsCount: 2,                                  
  _maxListeners: undefined,                         
  defaultPort: 443,                                 
  protocol: 'https:',                               
  options: { path: null },                          
  requests: {},                                     
  sockets: {},                                      
  freeSockets: {},                                  
  keepAliveMsecs: 1000,                             
  keepAlive: false,                                 
  maxSockets: Infinity,                             
  maxFreeSockets: 256,                              
  scheduling: 'fifo',                               
  maxTotalSockets: Infinity,                        
  totalSocketCount: 0,                              
  maxCachedSessions: 100,                           
  _sessionCache: { map: {}, list: [] },             
  [Symbol(kCapture)]: false                         
}                                                   

But in HttpProxyAgent it is inside proxy property not in root

MockserverHttpProxyAgent {                                     
  _events: [Object: null prototype] {},                        
  _eventsCount: 0,                                             
  _maxListeners: undefined,                                    
  timeout: null,                                               
  maxFreeSockets: 1,                                           
  maxSockets: 1,                                               
  maxTotalSockets: Infinity,                                   
  sockets: {},                                                 
  freeSockets: {},                                             
  requests: {},                                                
  options: {},                                                 
  secureProxy: true,                                           
  proxy: {                                                     
    host: '10.0.4.105',                                        
    protocol: 'https',                                         
    rejectUnauthorized: false,                                 
    requestCert: true,                                         
    port: 1080                                                 
  },                                                           
  [Symbol(kCapture)]: false                                    
}                                                              

We solved this by adding the protocol property to the httpAgent used by Mockserver.