@serverless/sdk
Advanced tools
Comparing version 0.5.11 to 0.5.12
@@ -5,2 +5,8 @@ # Changelog | ||
### [0.5.12](https://github.com/serverless/console/compare/@serverless/sdk@0.5.11...@serverless/sdk@0.5.12) (2023-04-26) | ||
### Features | ||
- Full resolution of paths that involve nested express routers ([e3641aa](https://github.com/serverless/console/commit/e3641aa245c2471bf1a4eae895af13674bf5d222)) | ||
### [0.5.11](https://github.com/serverless/console/compare/@serverless/sdk@0.5.10...@serverless/sdk@0.5.11) (2023-04-21) | ||
@@ -7,0 +13,0 @@ |
@@ -21,2 +21,3 @@ 'use strict'; | ||
let expressRouteData; | ||
let isRouterMiddleware; | ||
try { | ||
@@ -30,6 +31,7 @@ if (!expressSpansMap.has(req)) { | ||
const endTime = process.hrtime.bigint(); | ||
if (expressRouteData.route && expressRouteData.route.path && rootSpan) { | ||
const rootSpan = serverlessSdk.traceSpans.root; | ||
if (rootSpan && expressRouteData.path) { | ||
// Override eventual API Gateway's `resourcePath` | ||
rootSpan.tags.delete('aws.lambda.http_router.path'); | ||
rootSpan.tags.set('aws.lambda.http_router.path', expressRouteData.route.path); | ||
rootSpan.tags.set('aws.lambda.http_router.path', expressRouteData.path); | ||
} | ||
@@ -45,3 +47,3 @@ for (const subSpan of openedSpans) { | ||
const { routeSpan, openedSpans } = expressRouteData; | ||
const isRouterMiddleware = Boolean(!routeSpan && this.route); | ||
isRouterMiddleware = Boolean(!routeSpan && this.route); | ||
const middlewareSpanName = (() => { | ||
@@ -58,19 +60,19 @@ if (routeSpan) { | ||
} | ||
return isRouterMiddleware | ||
? 'express.middleware.router' | ||
: `express.middleware.${generateMiddlewareName(this.name) || 'unknown'}`; | ||
if (isRouterMiddleware) return 'express.middleware.router'; | ||
if (this.name === 'router' && this.path) { | ||
return `express.middleware.router.${generateMiddlewareName(this.path) || 'unknown'}`; | ||
} | ||
return `express.middleware.${generateMiddlewareName(this.name) || 'unknown'}`; | ||
})(); | ||
middlewareSpan = serverlessSdk._createTraceSpan(middlewareSpanName); | ||
openedSpans.add(middlewareSpan); | ||
if ( | ||
this.path && | ||
(!expressRouteData.path || expressRouteData.path.length < this.path.length) | ||
) { | ||
expressRouteData.path = this.path; | ||
if (this.path) { | ||
if (isRouterMiddleware) { | ||
expressRouteData.path = (expressRouteData.nestedPath || '') + this.path; | ||
} else { | ||
expressRouteData.nestedPath = (expressRouteData.nestedPath || '') + this.path; | ||
} | ||
} | ||
if (this.method) expressRouteData.method = this.method; | ||
if (isRouterMiddleware) { | ||
expressRouteData.routeSpan = middlewareSpan; | ||
expressRouteData.route = this.route; | ||
} | ||
if (isRouterMiddleware) expressRouteData.routeSpan = middlewareSpan; | ||
} catch (error) { | ||
@@ -86,5 +88,3 @@ reportError(error); | ||
middlewareSpan.close(); | ||
if (this.route) { | ||
delete expressRouteData.routeSpan; | ||
} | ||
if (isRouterMiddleware) delete expressRouteData.routeSpan; | ||
} | ||
@@ -139,3 +139,1 @@ } catch (error) { | ||
const serverlessSdk = require('../../..'); | ||
const rootSpan = serverlessSdk.traceSpans.root; |
{ | ||
"name": "@serverless/sdk", | ||
"repository": "serverless/console", | ||
"version": "0.5.11", | ||
"version": "0.5.12", | ||
"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
81353
1576