Skip to content

Feature Request: support for tracing NodeJs 18 native fetch calls #1619

Closed
@RaphaelManke

Description

@RaphaelManke

Expected Behaviour

In our Team we use the native nodeJS 18 fetch module to make api calls.

We were expecting that fetch calls would be traced the same as they where when we used node-fetch.

Current Behaviour

The fetch calls are not traced whereas the node-fetch calls are traced.

The x-ray traces show only the api calls made with node-fetch.

image

Code snippet

import { LambdaInterface } from "@aws-lambda-powertools/commons";
import { Tracer } from "@aws-lambda-powertools/tracer";
import nodeFetch from "node-fetch";

const tracer = new Tracer();

class Lambda implements LambdaInterface {
  // Decorate your handler class method

  @tracer.captureMethod()
  private async nativeFetch() {
    const response = await fetch("https://api.github.com/users/aws-samples");
    const json = await response.json();
    return json;
  }

  @tracer.captureMethod()
  private async nodeFetch() {
    const response = await nodeFetch(
      "https://api.github.com/users/aws-samples"
    );
    const json = await response.json();
    return json;
  }

  public async handler(_event: unknown, _context: unknown): Promise<void> {
    await this.nativeFetch();
    await this.nodeFetch();
  }
}

const handlerClass = new Lambda();
export const handler = handlerClass.handler.bind(handlerClass); //

Steps to Reproduce

  1. clone the bug repo https://github.com/RaphaelManke/aws-powertools-node-18-tracing-fetch-bug
  2. npm install
  3. npm run cdk deploy
  4. invoke the lambda

Possible Solution

No response

Powertools for AWS Lambda (TypeScript) version

1.11.1

AWS Lambda function runtime

18.x

Packaging format used

npm

Execution logs

No response

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedenhancementPRs that introduce minor changes, usually to existing featurestracerThis item relates to the Tracer Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions