Skip to content

Commit d78f20f

Browse files
author
Raphael Manke
committed
add bug reproduce steps
1 parent 1359b4c commit d78f20f

7 files changed

+7968
-28
lines changed

Diff for: README.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
# Welcome to your CDK TypeScript project
1+
# Bug report for AWS powertools typescript
22

3-
This is a blank project for CDK development with TypeScript.
3+
This repo is a minimal reproduction of a bug in the AWS powertools typescript library.
4+
The Tracing module is not working as expected.
5+
Fetch calls that are made with the native nodejs 18 fetch function are not traced.
6+
Whereas fetch calls that are made with the node-fetch library are traced.
47

5-
The `cdk.json` file tells the CDK Toolkit how to execute your app.
8+
The screenshot shows the difference between the two fetch calls.
9+
See the code in [`lib/node-18-fetch.ts`](lib/node-18-fetch.ts) for more details.
10+
11+
![Alt text](image.png)
612

713
## Useful commands
814

9-
* `npm run build` compile typescript to js
10-
* `npm run watch` watch for changes and compile
11-
* `npm run test` perform the jest unit tests
12-
* `cdk deploy` deploy this stack to your default AWS account/region
13-
* `cdk diff` compare deployed stack with current state
14-
* `cdk synth` emits the synthesized CloudFormation template
15+
- `npm run build` compile typescript to js
16+
- `npm run watch` watch for changes and compile
17+
- `npm run test` perform the jest unit tests
18+
- `cdk deploy` deploy this stack to your default AWS account/region
19+
- `cdk diff` compare deployed stack with current state
20+
- `cdk synth` emits the synthesized CloudFormation template

Diff for: image.png

237 KB
Loading

Diff for: lib/aws-powertools-node-18-fetch-stack.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import * as cdk from 'aws-cdk-lib';
2-
import { Construct } from 'constructs';
1+
import * as cdk from "aws-cdk-lib";
2+
import { Runtime, Tracing } from "aws-cdk-lib/aws-lambda";
3+
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
4+
import { Construct } from "constructs";
35
// import * as sqs from 'aws-cdk-lib/aws-sqs';
46

57
export class AwsPowertoolsNode18FetchStack extends cdk.Stack {
68
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
79
super(scope, id, props);
810

9-
// The code that defines your stack goes here
10-
11-
// example resource
12-
// const queue = new sqs.Queue(this, 'AwsPowertoolsNode18FetchQueue', {
13-
// visibilityTimeout: cdk.Duration.seconds(300)
14-
// });
11+
new NodejsFunction(this, "Node18Fetch", {
12+
entry: "lib/node-18-fetch.ts",
13+
runtime: Runtime.NODEJS_18_X,
14+
tracing: Tracing.ACTIVE,
15+
timeout: cdk.Duration.seconds(30),
16+
});
1517
}
1618
}

Diff for: lib/node-18-fetch.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { LambdaInterface } from "@aws-lambda-powertools/commons";
2+
import { Tracer } from "@aws-lambda-powertools/tracer";
3+
import nodeFetch from "node-fetch";
4+
5+
const tracer = new Tracer();
6+
7+
class Lambda implements LambdaInterface {
8+
// Decorate your handler class method
9+
10+
@tracer.captureMethod()
11+
private async nativeFetch() {
12+
const response = await fetch("https://api.github.com/users/aws-samples");
13+
const json = await response.json();
14+
return json;
15+
}
16+
17+
@tracer.captureMethod()
18+
private async nodeFetch() {
19+
const response = await nodeFetch(
20+
"https://api.github.com/users/aws-samples"
21+
);
22+
const json = await response.json();
23+
return json;
24+
}
25+
26+
public async handler(_event: unknown, _context: unknown): Promise<void> {
27+
await this.nativeFetch();
28+
await this.nodeFetch();
29+
}
30+
}
31+
32+
const handlerClass = new Lambda();
33+
export const handler = handlerClass.handler.bind(handlerClass); //

0 commit comments

Comments
 (0)