@serverless/sdk
Advanced tools
Comparing version 0.5.21 to 0.5.22
@@ -31,2 +31,3 @@ import ExpressAppInstrument from './instrumentation/express-app'; | ||
setEndpoint(endpoint: string): undefined; | ||
createTraceSpan(name: string, closure?: (() => T) | (() => Promise<T>)) | ||
} | ||
@@ -33,0 +34,0 @@ |
@@ -5,2 +5,12 @@ # Changelog | ||
### [0.5.22](https://github.com/serverless/console/compare/@serverless/sdk@0.5.21...@serverless/sdk@0.5.22) (2023-08-02) | ||
### Features | ||
- Add support for custom spans ([c43f756](https://github.com/serverless/console/commit/c43f75676ed7a14ed211de0965c010f3cb9080dd)) | ||
### Bug Fixes | ||
- Seperate createTraceSpan tests into its own block ([f6d85b0](https://github.com/serverless/console/commit/f6d85b06c9012c6e5074151ad29c8b1380a146d2)) | ||
### [0.5.21](https://github.com/serverless/console/compare/@serverless/sdk@0.5.20...@serverless/sdk@0.5.21) (2023-08-01) | ||
@@ -7,0 +17,0 @@ |
29
index.js
@@ -13,2 +13,4 @@ 'use strict'; | ||
const ensureString = require('type/string/ensure'); | ||
const isFunction = require('type/function/is'); | ||
const isThenable = require('type/thenable/is'); | ||
const d = require('d'); | ||
@@ -66,3 +68,30 @@ const lazy = require('d/lazy'); | ||
}; | ||
serverlessSdk.createTraceSpan = (name, closure) => { | ||
const span = serverlessSdk._createTraceSpan(name); | ||
if (closure && isThenable(closure)) { | ||
return closure.then( | ||
(result) => { | ||
span.close(); | ||
return result; | ||
}, | ||
(error) => { | ||
span.close(); | ||
throw error; | ||
} | ||
); | ||
} | ||
if (closure && isFunction(closure)) { | ||
let result; | ||
try { | ||
result = closure(); | ||
} finally { | ||
span.close(); | ||
} | ||
return result; | ||
} | ||
return span; | ||
}; | ||
// Private | ||
@@ -69,0 +98,0 @@ const settings = (serverlessSdk._settings = {}); |
{ | ||
"name": "@serverless/sdk", | ||
"repository": "serverless/console", | ||
"version": "0.5.21", | ||
"version": "0.5.22", | ||
"author": "Serverless, Inc.", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90589
1726