This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-client-js.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a10271  Fix request header (#128)
2a10271 is described below

commit 2a102711c82fed7f91e8ea3502db83e08fc7179a
Author: Fine0830 <fanxue0...@gmail.com>
AuthorDate: Tue Jun 25 15:51:45 2024 +0800

    Fix request header (#128)
---
 src/trace/interceptors/fetch.ts | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/trace/interceptors/fetch.ts b/src/trace/interceptors/fetch.ts
index f62f975..b6746e0 100644
--- a/src/trace/interceptors/fetch.ts
+++ b/src/trace/interceptors/fetch.ts
@@ -49,8 +49,7 @@ export default function windowFetch(options: 
CustomOptionsType, segments: Segmen
         url = new URL(window.location.href);
         url.pathname = args[0];
       }
-    }  
-
+    }
 
     const noTraceOrigins = customConfig.noTraceOrigins.some((rule: string | 
RegExp) => {
       if (typeof rule === 'string') {
@@ -79,16 +78,20 @@ export default function windowFetch(options: 
CustomOptionsType, segments: Segmen
       const index = segment.spans.length;
       const values = 
`${1}-${traceIdStr}-${segmentId}-${index}-${service}-${instance}-${endpoint}-${peer}`;
 
-      if (!args[1]) {
-        args[1] = {};
-      }
-      if (!args[1].headers) {
-        args[1].headers = new Headers();
-      }
-      if (args[1].headers instanceof Headers) {
-        args[1].headers.append('sw8', values);
+      if (args[0] instanceof Request) {
+        args[0].headers.append('sw8', values);
       } else {
-        args[1].headers['sw8'] = values;
+        if (!args[1]) {
+          args[1] = {};
+        }
+        if (!args[1].headers) {
+          args[1].headers = new Headers();
+        }
+        if (args[1].headers instanceof Headers) {
+          args[1].headers.append('sw8', values);
+        } else {
+          args[1].headers['sw8'] = values;
+        }
       }
     }
 

Reply via email to