- 
                Notifications
    
You must be signed in to change notification settings  - Fork 158
 
Description
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?
Suggested Improvement
It would be helpful if captureFetchGlobal could:
- Avoid mutating the global 
fetchin an additionalcaptureFetchStandalonefunction 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).
 
