Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

captureFetchGlobal returns a wrapped fetch but still overrides global fetch #711

Open
yvele opened this issue Feb 19, 2025 · 0 comments
Open

Comments

@yvele
Copy link

yvele commented Feb 19, 2025

I'm using aws-xray-sdk-fetch to trace HTTPS requests that goes outside AWS.

My application (AWS Lambda) also uses the AWS AppConfig Agent client via another fetch call to localhost.

When using captureFetchGlobal, all fetch calls are being traced—including AppConfig Agent's localhost requests.

Expected Behavior

I would like to only trace external fetch calls and not trace localhost calls.

Current Behavior

With captureFetchGlobal, the global fetch is wrapped, causing all fetch requests to be traced, including those to localhost.

import { captureFetchGlobal } from "aws-xray-sdk-fetch";

const fetch = captureFetchGlobal();

export default async function send(url, body) {
  // ✅ I want to trace this fetch
  const response = await fetch(url, {
    method : "POST",
    body : JSON.stringify(body),
    headers : {
      "Content-Type" : "application/json"
    }
  });

  if (!response.ok) {
    throw new Error(`${response.statusText} (${response.statusCode})` );
  }
}

In another function:

export default async function getAppConfigLatestJson() {
  // ❌ I do NOT want to trace this fetch
  const response = await fetch(url);
  return await response.json();
}

Issue

The captureFetchGlobal function returns a specific fetch function but still wraps the global fetch object. This behavior is counterintuitive, as I expected only the assigned fetch to be traced.

How to only trace the first fetch?

image

Suggested Improvement

It would be helpful if captureFetchGlobal could:

  • Avoid mutating the global fetch in an additional captureFetchStandalone function and return a wrapped instance that can be selectively used.
  • Alternatively, provide an option to filter which requests to trace (e.g., by hostname or URL pattern).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant