@serverless/sdk
Advanced tools
Comparing version 0.4.4 to 0.5.0
@@ -5,2 +5,25 @@ # Changelog | ||
## [0.5.0](https://github.com/serverless/console/compare/@serverless/sdk@0.4.4...@serverless/sdk@0.5.0) (2023-02-02) | ||
### ⚠ BREAKING CHANGES | ||
- All internal warnings need to be configured via `serverlessSdk._reportWarning` to be reflected as captured events | ||
- `serverless._reportSdkError` is renamed to `serverless._reportError` | ||
### Features | ||
- Dedicated internal endpoint for reporting warnings ([685cb2a](https://github.com/serverless/console/commit/685cb2a7a24313c01d961fa6d26d7547b6b1c93d)) | ||
- Support different SDK error types and reflect the type in structured log ([d45cbfa](https://github.com/serverless/console/commit/d45cbfaa7950927aa920992ab8444d3d666553b5)) | ||
- Write captured events reported with `.capture*` methods to stdout ([4f940eb](https://github.com/serverless/console/commit/4f940ebacab518e71fa60eafd17d511144a7f353)) | ||
### Bug Fixes | ||
- Ensure to always generate captured events for internal errors ([dc1e70f](https://github.com/serverless/console/commit/dc1e70f9ff21c6ca30492869294c219e2faa01ac)) | ||
- Ensure to always generate captured events for internal warnings ([eef80e0](https://github.com/serverless/console/commit/eef80e06a086dc3c1af20b75803abcc8b9a94666)) | ||
### Maintenance Improvements | ||
- Reflect internal error types in structured log ([0f7f554](https://github.com/serverless/console/commit/0f7f554a069ba7660d80acada2309246b59a2438)) | ||
- Rename `._reportSdkError` to `._reportError` ([33327cb](https://github.com/serverless/console/commit/33327cbe0ddcf5daf60c7217f35f2f3f41a34c62)) | ||
### [0.4.4](https://github.com/serverless/console/compare/@serverless/sdk@0.4.3...@serverless/sdk@0.4.4) (2023-02-01) | ||
@@ -7,0 +30,0 @@ |
@@ -29,3 +29,3 @@ # Serverless SDK | ||
Record captured error | ||
Record captured error. Captured error is sent to Serverless Console backend and printed to the stdout in structured format (writing to stdout can be disabled with `SLS_DISABLE_CAPTURED_EVENTS_STDOUT` env var) | ||
@@ -39,3 +39,3 @@ - `error` - Captured error | ||
Record warning | ||
Record warning. Captured warning is sent to Serverless Console backend and printed to the stdout in structured format (writing to stdout can be disabled with `SLS_DISABLE_CAPTURED_EVENTS_STDOUT` env var) | ||
@@ -42,0 +42,0 @@ - `message` - Warning message |
19
index.js
@@ -20,3 +20,4 @@ 'use strict'; | ||
const createWarningCapturedEvent = require('./lib/create-warning-captured-event'); | ||
const reportSdkError = require('./lib/report-sdk-error'); | ||
const reportError = require('./lib/report-error'); | ||
const reportWarning = require('./lib/report-warning'); | ||
const pkgJson = require('./package'); | ||
@@ -44,4 +45,4 @@ | ||
createErrorCapturedEvent(error, options); | ||
} catch (reportError) { | ||
reportSdkError(reportError); | ||
} catch (internalError) { | ||
reportError(internalError); | ||
} | ||
@@ -52,4 +53,4 @@ }; | ||
createWarningCapturedEvent(message, options); | ||
} catch (reportError) { | ||
reportSdkError(reportError); | ||
} catch (internalError) { | ||
reportError(internalError); | ||
} | ||
@@ -61,3 +62,3 @@ }; | ||
} catch (error) { | ||
reportSdkError(error, { type: 'USER' }); | ||
reportError(error, { type: 'USER' }); | ||
} | ||
@@ -96,2 +97,5 @@ }; | ||
10000; | ||
serverlessSdk._settings.disableCapturedEventsStdout = Boolean( | ||
process.env.SLS_DISABLE_CAPTURED_EVENTS_STDOUT || options.disableCapturedEventsStdout | ||
); | ||
@@ -119,3 +123,4 @@ if (!settings.disableHttpMonitoring) { | ||
serverlessSdk._createTraceSpan = (name, options = {}) => new TraceSpan(name, options); | ||
serverlessSdk._reportSdkError = reportSdkError; | ||
serverlessSdk._reportError = reportError; | ||
serverlessSdk._reportWarning = reportWarning; | ||
serverlessSdk._isDebugMode = Boolean(process.env.SLS_SDK_DEBUG); | ||
@@ -122,0 +127,0 @@ serverlessSdk._debugLog = (...args) => { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
const ServerlessSdkError = require('./error'); | ||
const reportSdkError = require('./report-sdk-error'); | ||
const reportError = require('./report-error'); | ||
@@ -53,3 +53,3 @@ class CapturedEvent { | ||
} catch (error) { | ||
reportSdkError(error, { type: 'USER' }); | ||
reportError(error, { type: 'USER' }); | ||
} | ||
@@ -56,0 +56,0 @@ if (options._origin) this._origin = options._origin; |
@@ -10,2 +10,9 @@ 'use strict'; | ||
const typeMap = new Map([ | ||
['unhandled', 1], | ||
['handledUser', 2], | ||
['handledSdkUser', 3], | ||
['handledSdkInternal', 4], | ||
]); | ||
module.exports = (error, options = {}) => { | ||
@@ -22,3 +29,4 @@ const timestamp = options._timestamp || process.hrtime.bigint(); | ||
const tags = { type: options._type === 'unhandled' ? 1 : 2 }; | ||
const type = options._type || 'handledUser'; | ||
const tags = { type: typeMap.get(type) }; | ||
if (isError(error)) { | ||
@@ -34,3 +42,23 @@ tags.name = error.name; | ||
if ( | ||
options._origin === 'nodeConsole' || | ||
type !== 'handledUser' || | ||
serverlessSdk._settings.disableCapturedEventsStdout | ||
) { | ||
return capturedEvent; | ||
} | ||
const errorLogData = { | ||
source: 'serverlessSdk', | ||
type: 'ERROR_TYPE_CAUGHT_USER', | ||
name: tags.name, | ||
message: tags.message, | ||
stack: tags.stacktrace, | ||
}; | ||
if (options.fingerprint) errorLogData.fingerprint = options.fingerprint; | ||
console.error(errorLogData); | ||
return capturedEvent; | ||
}; | ||
const serverlessSdk = require('../'); |
@@ -8,2 +8,8 @@ 'use strict'; | ||
const typeMap = new Map([ | ||
['user', 1], | ||
['sdkUser', 2], | ||
['sdkInternal', 3], | ||
]); | ||
module.exports = (message, options = {}) => { | ||
@@ -14,3 +20,5 @@ const timestamp = process.hrtime.bigint(); | ||
return new CapturedEvent('telemetry.warning.generated.v1', { | ||
const type = options._type || 'user'; | ||
const stackTrace = resolveStackTraceString(); | ||
const capturedEvent = new CapturedEvent('telemetry.warning.generated.v1', { | ||
timestamp, | ||
@@ -21,7 +29,28 @@ customTags: options.tags, | ||
'warning.message': message, | ||
'warning.type': options.type || 1, | ||
'warning.stacktrace': resolveStackTraceString(), | ||
'warning.type': typeMap.get(type), | ||
'warning.stacktrace': stackTrace, | ||
}, | ||
_origin: options._origin, | ||
}); | ||
if ( | ||
options._origin === 'nodeConsole' || | ||
type !== 'user' || | ||
serverlessSdk._settings.disableCapturedEventsStdout | ||
) { | ||
return capturedEvent; | ||
} | ||
const warnLogData = { | ||
source: 'serverlessSdk', | ||
type: 'WARNING_TYPE_USER', | ||
message, | ||
stack: stackTrace, | ||
}; | ||
if (options.fingerprint) warnLogData.fingerprint = options.fingerprint; | ||
console.warn(warnLogData); | ||
return capturedEvent; | ||
}; | ||
const serverlessSdk = require('../'); |
'use strict'; | ||
const reportSdkError = require('../../report-sdk-error'); | ||
const reportError = require('../../report-error'); | ||
@@ -71,3 +71,3 @@ const instrumentedLayers = new WeakMap(); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
return originalHandleRequest.call(this, req, res, next); | ||
@@ -84,3 +84,3 @@ } | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -104,3 +104,3 @@ return next(...args); | ||
} catch (sdkError) { | ||
reportSdkError(sdkError); | ||
reportError(sdkError); | ||
return originalHandleError.call(this, error, req, res, next); | ||
@@ -107,0 +107,0 @@ } |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const { errorMonitor } = require('events'); | ||
const reportSdkError = require('../report-sdk-error'); | ||
const reportError = require('../report-error'); | ||
@@ -64,3 +64,3 @@ let shouldIgnoreFollowingRequest = false; | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -82,3 +82,3 @@ return originalWrite.call(this, chunk, encoding, callback); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -107,3 +107,3 @@ return originalEnd.call(this, chunk, encoding, callback); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -123,3 +123,3 @@ }); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -126,0 +126,0 @@ }); |
@@ -8,3 +8,3 @@ 'use strict'; | ||
const createWarningCapturedEvent = require('../create-warning-captured-event'); | ||
const reportSdkError = require('../report-sdk-error'); | ||
const reportError = require('../report-error'); | ||
@@ -38,16 +38,8 @@ const nodeConsole = console; | ||
const input = args[0]; | ||
if (args.length === 1 && isPlainObject(input) && input.source === 'serverlessSdk') { | ||
createErrorCapturedEvent(input.message, { | ||
_name: input.name, | ||
_stack: input.stack, | ||
_origin: 'nodeConsole', | ||
}); | ||
} else { | ||
createErrorCapturedEvent( | ||
args.length === 1 && isError(input) ? input : resolveMessage(args), | ||
{ _origin: 'nodeConsole' } | ||
); | ||
} | ||
if (args.length === 1 && isPlainObject(input) && input.source === 'serverlessSdk') return; | ||
createErrorCapturedEvent(args.length === 1 && isError(input) ? input : resolveMessage(args), { | ||
_origin: 'nodeConsole', | ||
}); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -59,9 +51,6 @@ }; | ||
try { | ||
if (isPlainObject(args[0]) && args[0].source === 'serverlessSdk') { | ||
createWarningCapturedEvent(args[0].message, { _origin: 'nodeConsole', type: 2 }); | ||
} else { | ||
createWarningCapturedEvent(resolveMessage(args), { _origin: 'nodeConsole' }); | ||
} | ||
if (args.length === 1 && isPlainObject(args[0]) && args[0].source === 'serverlessSdk') return; | ||
createWarningCapturedEvent(resolveMessage(args), { _origin: 'nodeConsole' }); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -68,0 +57,0 @@ }; |
'use strict'; | ||
const Module = require('module'); | ||
const reportSdkError = require('../../report-sdk-error'); | ||
const reportError = require('../../report-error'); | ||
@@ -14,3 +14,3 @@ const installers = new Map(); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
return; | ||
@@ -49,3 +49,3 @@ } | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -52,0 +52,0 @@ } |
@@ -11,3 +11,3 @@ 'use strict'; | ||
const ServerlessSdkError = require('./error'); | ||
const reportSdkError = require('./report-sdk-error'); | ||
const reportError = require('./report-error'); | ||
@@ -129,3 +129,3 @@ const isValidTagName = RegExp.prototype.test.bind(/^[a-zA-Z0-9_.-]+$/); | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -162,3 +162,3 @@ return this; | ||
} catch (error) { | ||
reportSdkError(error); | ||
reportError(error); | ||
} | ||
@@ -165,0 +165,0 @@ return this; |
{ | ||
"name": "@serverless/sdk", | ||
"repository": "serverless/console", | ||
"version": "0.4.4", | ||
"version": "0.5.0", | ||
"author": "Serverless, Inc.", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -69,2 +69,6 @@ # @serverless/sdk | ||
##### `SLS_DISABLE_CAPTURED_EVENTS_STDOUT` (or `options.disableCapturedEventsStdout`) | ||
Disable writing captured events registered via `.captureError` and `.captureWarning` to stdout | ||
##### `SLS_TRACE_MAX_CAPTURED_BODY_SIZE_KB` (or `options.traceMaxCapturedBodySizeKb`) | ||
@@ -71,0 +75,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
69707
36
1363
90
12