@instana/serverless
Advanced tools
Comparing version
@@ -6,2 +6,6 @@ # Change Log | ||
## [4.6.3](https://github.com/instana/nodejs/compare/v4.6.2...v4.6.3) (2025-03-05) | ||
**Note:** Version bump only for package @instana/serverless | ||
## [4.6.2](https://github.com/instana/nodejs/compare/v4.6.1...v4.6.2) (2025-02-24) | ||
@@ -8,0 +12,0 @@ |
{ | ||
"name": "@instana/serverless", | ||
"version": "4.6.2", | ||
"version": "4.6.3", | ||
"description": "Internal utility package for serverless Node.js tracing and monitoring with Instana", | ||
@@ -68,7 +68,7 @@ "author": { | ||
"dependencies": { | ||
"@instana/core": "4.6.2", | ||
"@instana/core": "4.6.3", | ||
"agent-base": "^6.0.2", | ||
"https-proxy-agent": "^7.0.2" | ||
}, | ||
"gitHead": "d70ba21a091202ed248f083d546052a63e861ddc" | ||
"gitHead": "7dc62e64ec6015db2184484fa6142a3eb0c552e0" | ||
} |
@@ -11,6 +11,6 @@ /* | ||
const uninstrumented = require('./uninstrumentedHttp'); | ||
const constants = require('./constants'); | ||
let logger = require('./console_logger'); | ||
let logger; | ||
const layerExtensionHostname = 'localhost'; | ||
@@ -20,10 +20,7 @@ const layerExtensionPort = process.env.INSTANA_LAYER_EXTENSION_PORT | ||
: 7365; | ||
let useLambdaExtension = false; | ||
const timeoutEnvVar = 'INSTANA_TIMEOUT'; | ||
let defaultTimeout = 500; | ||
const layerExtensionTimeout = process.env.INSTANA_LAMBDA_EXTENSION_TIMEOUT_IN_MS | ||
? Number(process.env.INSTANA_LAMBDA_EXTENSION_TIMEOUT_IN_MS) | ||
: 500; | ||
let backendTimeout = defaultTimeout; | ||
@@ -33,55 +30,58 @@ const proxyEnvVar = 'INSTANA_ENDPOINT_PROXY'; | ||
let stopSendingOnFailure = true; | ||
let propagateErrorsUpstream = false; | ||
let requestHasFailed = false; | ||
let warningsHaveBeenLogged = false; | ||
const disableCaCheckEnvVar = 'INSTANA_DISABLE_CA_CHECK'; | ||
const disableCaCheck = process.env[disableCaCheckEnvVar] === 'true'; | ||
if (process.env[proxyEnvVar] && !environmentUtil.sendUnencrypted) { | ||
const proxyUrl = process.env[proxyEnvVar]; | ||
logger.info( | ||
`The environment variable ${proxyEnvVar} is set. Requests to the Instana back end will be routed via a proxy ` + | ||
`server: ${proxyUrl}.` | ||
); | ||
let requestHasFailed = false; | ||
let warningsHaveBeenLogged = false; | ||
const { HttpsProxyAgent } = require('https-proxy-agent'); | ||
proxyAgent = new HttpsProxyAgent(proxyUrl); | ||
} else if (process.env[proxyEnvVar] && environmentUtil.sendUnencrypted) { | ||
logger.warn( | ||
`Both ${proxyEnvVar} and ${environmentUtil.sendUnencryptedEnvVar} are set, but this combination is not supported.` + | ||
' Requests to the Instana back end will not be routed via a proxy server.' | ||
); | ||
} | ||
const defaults = { | ||
config: {}, | ||
identityProvider: null, | ||
stopSendingOnFailure: true, | ||
propagateErrorsUpstream: false, | ||
defaultTimeout: 500, | ||
backendTimeout: 500, | ||
useLambdaExtension: false | ||
}; | ||
let options; | ||
let hostHeader; | ||
exports.init = function init( | ||
identityProvider, | ||
_logger, | ||
_stopSendingOnFailure, | ||
_propagateErrorsUpstream, | ||
_defaultTimeout, | ||
_useLambdaExtension | ||
) { | ||
stopSendingOnFailure = _stopSendingOnFailure == null ? true : _stopSendingOnFailure; | ||
propagateErrorsUpstream = _propagateErrorsUpstream == null ? false : _propagateErrorsUpstream; | ||
defaultTimeout = _defaultTimeout == null ? defaultTimeout : _defaultTimeout; | ||
useLambdaExtension = _useLambdaExtension; | ||
backendTimeout = defaultTimeout; | ||
exports.init = function init(opts) { | ||
options = Object.assign(defaults, opts); | ||
logger = options.config.logger; | ||
if (process.env[proxyEnvVar] && !environmentUtil.sendUnencrypted) { | ||
const proxyUrl = process.env[proxyEnvVar]; | ||
logger.info( | ||
`The environment variable ${proxyEnvVar} is set. Requests to the Instana back end will be routed via a proxy ` + | ||
`server: ${proxyUrl}.` | ||
); | ||
const { HttpsProxyAgent } = require('https-proxy-agent'); | ||
proxyAgent = new HttpsProxyAgent(proxyUrl); | ||
} else if (process.env[proxyEnvVar] && environmentUtil.sendUnencrypted) { | ||
logger.warn( | ||
`Both ${proxyEnvVar} and ${environmentUtil.sendUnencryptedEnvVar} are set, ` + | ||
'but this combination is not supported.' + | ||
' Requests to the Instana back end will not be routed via a proxy server.' | ||
); | ||
} | ||
if (process.env[timeoutEnvVar]) { | ||
backendTimeout = parseInt(process.env[timeoutEnvVar], 10); | ||
if (isNaN(backendTimeout) || backendTimeout < 0) { | ||
options.backendTimeout = parseInt(process.env[timeoutEnvVar], 10); | ||
if (isNaN(options.backendTimeout) || options.backendTimeout < 0) { | ||
logger.warn( | ||
`The value of ${timeoutEnvVar} (${process.env[timeoutEnvVar]}) cannot be parsed to a valid numerical value. ` + | ||
`Will fall back to the default timeout (${defaultTimeout} ms).` | ||
`Will fall back to the default timeout (${options.defaultTimeout} ms).` | ||
); | ||
backendTimeout = defaultTimeout; | ||
options.backendTimeout = 500; | ||
} | ||
} | ||
if (identityProvider) { | ||
hostHeader = identityProvider.getHostHeader(); | ||
if (options.identityProvider) { | ||
hostHeader = options.identityProvider.getHostHeader(); | ||
if (hostHeader == null) { | ||
@@ -94,8 +94,2 @@ hostHeader = 'nodejs-serverless'; | ||
if (_logger) { | ||
logger = _logger; | ||
} | ||
requestHasFailed = false; | ||
// Heartbeat is only for the AWS Lambda extension | ||
@@ -105,3 +99,3 @@ // IMPORTANT: the @instana/aws-lambda package will not | ||
// SpanBuffer sends data asap and when the handler is finished the rest is sent. | ||
if (useLambdaExtension) { | ||
if (options.useLambdaExtension) { | ||
scheduleLambdaExtensionHeartbeatRequest(); | ||
@@ -187,3 +181,3 @@ } | ||
// Make sure we do not try to talk to the Lambda extension again. | ||
useLambdaExtension = false; | ||
options.useLambdaExtension = false; | ||
clearInterval(heartbeatInterval); | ||
@@ -241,3 +235,3 @@ | ||
function getBackendTimeout(localUseLambdaExtension) { | ||
return localUseLambdaExtension ? layerExtensionTimeout : backendTimeout; | ||
return localUseLambdaExtension ? layerExtensionTimeout : options.backendTimeout; | ||
} | ||
@@ -256,5 +250,5 @@ | ||
// decide whether to fall back to sending to the back end directly or give up sending data completely. | ||
let localUseLambdaExtension = useLambdaExtension; | ||
let localUseLambdaExtension = options.useLambdaExtension; | ||
if (requestHasFailed && stopSendingOnFailure) { | ||
if (requestHasFailed && options.stopSendingOnFailure) { | ||
logger.info( | ||
@@ -298,3 +292,3 @@ `Not attempting to send data to ${resourcePath} as a previous request has already timed out or failed.` | ||
const options = { | ||
const reqOptions = { | ||
hostname: localUseLambdaExtension ? layerExtensionHostname : environmentUtil.getBackendHost(), | ||
@@ -313,6 +307,6 @@ port: localUseLambdaExtension ? layerExtensionPort : environmentUtil.getBackendPort(), | ||
options.timeout = getBackendTimeout(localUseLambdaExtension); | ||
reqOptions.timeout = getBackendTimeout(localUseLambdaExtension); | ||
if (proxyAgent && !localUseLambdaExtension) { | ||
options.agent = proxyAgent; | ||
reqOptions.agent = proxyAgent; | ||
} | ||
@@ -333,3 +327,3 @@ | ||
req = transport.request(options); | ||
req = transport.request(reqOptions); | ||
} else { | ||
@@ -344,3 +338,3 @@ // If (a) our Lambda extension is available, or if (b) a user-provided proxy is in use, we do *not* apply the | ||
// to end the processing. Otherwise, the callback is provided here to http.request(). | ||
req = transport.request(options, () => { | ||
req = transport.request(reqOptions, () => { | ||
// When the Node.js process is frozen while the request is pending, and then thawed later, | ||
@@ -399,3 +393,3 @@ // this can trigger a stale, bogus timeout event (because from the perspective of the freshly thawed Node.js | ||
// Make sure we do not try to talk to the Lambda extension again. | ||
useLambdaExtension = localUseLambdaExtension = false; | ||
options.useLambdaExtension = localUseLambdaExtension = false; | ||
clearInterval(heartbeatInterval); | ||
@@ -411,3 +405,3 @@ | ||
if (!propagateErrorsUpstream) { | ||
if (!options.propagateErrorsUpstream) { | ||
if (proxyAgent) { | ||
@@ -427,3 +421,3 @@ logger.warn( | ||
handleCallback(propagateErrorsUpstream ? e : undefined); | ||
handleCallback(options.propagateErrorsUpstream ? e : undefined); | ||
} | ||
@@ -435,3 +429,3 @@ }); | ||
if (useLambdaExtension && finalLambdaRequest) { | ||
if (options.useLambdaExtension && finalLambdaRequest) { | ||
clearInterval(heartbeatInterval); | ||
@@ -485,3 +479,3 @@ } | ||
// Make sure we do not try to talk to the Lambda extension again. | ||
useLambdaExtension = localUseLambdaExtension = false; | ||
options.useLambdaExtension = localUseLambdaExtension = false; | ||
clearInterval(heartbeatInterval); | ||
@@ -519,10 +513,12 @@ | ||
const message = | ||
'Could not send traces and metrics to Instana. The Instana back end did not respond in the configured timeout ' + | ||
`of ${backendTimeout} ms. The timeout can be configured by setting the environment variable ${timeoutEnvVar}.`; | ||
'Could not send traces and metrics to Instana. The Instana back end did not respond ' + | ||
'in the configured timeout ' + | ||
`of ${options.backendTimeout} ms. The timeout can be configured by ` + | ||
`setting the environment variable ${timeoutEnvVar}.`; | ||
if (!propagateErrorsUpstream) { | ||
if (!options.propagateErrorsUpstream) { | ||
logger.warn(message); | ||
} | ||
handleCallback(propagateErrorsUpstream ? new Error(message) : undefined); | ||
handleCallback(options.propagateErrorsUpstream ? new Error(message) : undefined); | ||
} | ||
@@ -529,0 +525,0 @@ } |
@@ -8,4 +8,2 @@ /* | ||
const logger = require('./console_logger'); | ||
const instanaEndpointUrlEnvVar = 'INSTANA_ENDPOINT_URL'; | ||
@@ -15,2 +13,3 @@ const instanaAgentKeyEnvVar = 'INSTANA_AGENT_KEY'; | ||
let logger; | ||
let valid = false; | ||
@@ -30,2 +29,6 @@ let backendHost = null; | ||
exports.init = config => { | ||
logger = config.logger; | ||
}; | ||
exports.validate = function validate({ validateInstanaAgentKey } = {}) { | ||
@@ -32,0 +35,0 @@ _validate(process.env[instanaEndpointUrlEnvVar], process.env[instanaAgentKeyEnvVar], validateInstanaAgentKey); |
@@ -9,5 +9,6 @@ /* | ||
exports.backendConnector = require('./backend_connector'); | ||
exports.consoleLogger = require('./console_logger'); | ||
// TODO: rename in major release to simply "exports.logger" | ||
exports.consoleLogger = require('./logger'); | ||
exports.constants = require('./constants'); | ||
exports.environment = require('./environment'); | ||
exports.headers = require('./headers'); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
57850
5.05%793
13.12%12
-33.33%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated