Skip to content

Commit 6e69831

Browse files
author
Daniel Bot
committed
feat: first version of @aws-lambda-powertools-correlation
1 parent 491663e commit 6e69831

File tree

9 files changed

+16227
-0
lines changed

9 files changed

+16227
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# build
2+
lib
3+
4+
# include types
5+
!src/types/*.d.ts
6+
7+
# include jest config
8+
!jest.config.js
9+
!.eslintrc.js
10+
11+
# npm
12+
node_modules
13+
npm_debug.log*
14+
15+
# yalc
16+
yalc.lock
17+

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
11
# aws-lambda-powertools-correlation
22
Correlation Ids for aws-lambda-powertools
3+
4+
5+
<h3>Features</h3>
6+
7+
1. Middleware to enable injecting correlation ids from the request into the <i>AsyncLocalStorage</i>
8+
```typescript
9+
import { enableCorrelationIds } from '@aws-lambda-powertools-correlation';
10+
import middy from '@middy/core';
11+
import * as Lambda from 'aws-lambda';
12+
13+
export const handler = (_handler: Lambda.APIGatewayProxyHandlerV2) => {
14+
return middy(_handler).use(enableCorrelationIds());
15+
};
16+
```
17+
18+
19+
2. Utility to extend the powertools logger with correlation ids: <i>injectCorrelationIds(logger)</i>
20+
21+
```typescript
22+
import { injectCorrelationIds } from '@aws-lambda-powertools-correlation';
23+
import { Logger } from '@aws-lambda-powertools/logger'
24+
25+
const logger = new Logger();
26+
27+
export const handler = (_handler: Lambda.APIGatewayProxyHandlerV2) => {
28+
return middy(_handler)
29+
.use(enableCorrelationIds())
30+
.before(() => { injectCorrelationIds(logger) });
31+
};
32+
```
33+
34+
3. Utility to get correlation ids from the AsyncLocalStorage: <i>getCorrelationIds()</i>
35+
```typescript
36+
import { useCorrelationIds } from '@aws-lambda-powertools-correlation';
37+
38+
const correlationIds = useCorrelationIds();
39+
40+
```
41+
42+
<h3>Dependencies</h3>
43+
44+
- @aws-sdk/util-dynamodb
45+
- @aws-lambda-powertools/logger
46+
47+

0 commit comments

Comments
 (0)