羊肉-功用工具-指针
一个用于记录相关ID的帮助模块.
主要特点:
-
允许您获取、更新和删除相关ID
-
尊重相关标识的常规,即:.
x-correlation- -
手动启用/ 无法调试日志( M)
debug-log-enabled由其它/下游中件取出 -
允许您存储多个相关ID,从而允许您 关联 多个维度的日志(例如:
x-correlation-user-id,或x-correlation-order-id页:1
开始
从国家预防机制安装: npm install @dazn/lambda-powertools-correlation-ids
API 密码
const CorrelationIds = require('@dazn/lambda-powertools-correlation-ids')
// automatically inserts 'x-correlation-' prefix if not provided
CorrelationIds.set('id', '12345678') // records id as x-correlation-id
CorrelationIds.set('x-correlation-username', 'theburningmonk') // records as x-correlation-username
// Manully enable debug logging (debug-log-enabled)
CorrelationIds.debugLoggingEnabled = true
const myCorrelationIds = CorrelationIds.get()
// {
// 'x-correlation-id': '12345678',
// 'x-correlation-username': 'theburningmonk',
// 'debug-log-enabled': 'true'
// }
CorrelationIds.clearAll() // removes all recorded correlation IDs
CorrelationIds.replaceAllWith({ // bypasses the 'x-correlation-' convention
'debug-log-enabled': 'true',
'User-Agent': 'jest test'
})
// Disable debug logging
CorrelationIds.debugLoggingEnabled = false
在实践上,你可能只需要 set 当您想要从您的功能中记录相关ID时.
中间的软件, @dazn/lambda-powertools-middleware-correlation-ids,将自动捕捉所支持的事件源引用事件的相关ID:
-
API 网关( 通过 HTTP 信头)
-
Kinesis(通过JSON有效载荷)
-
SNS( 通过信件属性)
-
与特别领域有关的引用事件
__context__(这就是我们如何给他们注入步骤函数 和Lambda客户端下面)
其他动力工具将使用 get 使用相关标识:
-
@dazn/lambda-powertools-logger在日志中包含已记录的相关ID -
@dazn/lambda-powertools-http-client当您提出 HTTP 请求时, 包含作为 HTTP 头的已记录的相关ID -
@dazn/lambda-powertools-sns-client当您向 SNS 发布消息时, 包含作为 SNS 消息属性的已记录关联ID( ie) .SNS.publish(中文(简体) ) -
@dazn/lambda-powertools-kinesis-client当您向 Kinesis( ie) 发布事件时, 将记录的相关ID作为事件有效载荷的一部分.Kinesis.putRecord财务报告和审定财务报表Kinesis.putRecords(中文(简体) ) -
@dazn/lambda-powertools-step-functions-client当您开始 Step 函数执行( e.SFN.startExecution(中文(简体) ) -
@dazn/lambda-powertools-lambda-client当您直接引用了 Lambda 函数( e.Lambda.invoke财务报告和审定财务报表Lambda.invokeAsync(中文(简体) )