在我的 middy 处理程序中,我尝试从https://www.npmjs.com/package/cls-proxify添加 setClsProxyValue
// Export anonymous function
export default handler => middy(handler).use([
() => {
// Set `requestId` in CLS to `requestId/co-relationId` so proxified pino picks it up
setClsProxyValue('requestId', 'testId')
},
// Logging lambda entry params, responses and errors
loggerMiddleware({ logger: logger }),
//other middleware
httpErrorHandler(),
]);
添加 -
() => {
// Set `requestId` in CLS to `requestId/co-relationId` so proxified pino picks it up
setClsProxyValue('requestId', 'testId')
},
处理程序中的一段代码抛出:
**Middleware must be an object**
11 |
12 | // Export anonymous function
> 13 | export default handler => middy(handler).use([
| ^
14 | () => {
15 | // Set `requestId` in CLS to `requestId/co-relationId` so proxified pino picks it up
16 | setClsProxyValue('requestId', 'testId')
}
如果我删除
() => {} ,
并只添加setClsProxyValue('requestId', 'testId')
,它会抛出,
No context available. ns.run() or ns.bind() must be called first.
我也试过
const baseHandler = (event, context) => {
/* your business logic */
// Set `requestId` in CLS to `requestId/co-relationId` so proxified pino picks it up
setClsProxyValue('requestId', 'testId')
}
// Export anonymous function
export default handler => middy(baseHandler).use([
])
- 如何解决这个问题?
- 如何在 middy 处理程序中访问相关性 ID/请求 ID?