routeflow-browser 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +4 -0
- package/dist/client.js +8 -4
- package/dist/external_spans.js +1 -1
- package/dist/fetch_patch.js +25 -8
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HTTP client for sending events to Routeflow backend.
|
|
3
3
|
*/
|
|
4
|
-
//
|
|
5
|
-
const BACKEND_URL =
|
|
6
|
-
? "http://127.0.0.1:5004"
|
|
7
|
-
: "https://routeflow-backend-production.up.railway.app";
|
|
4
|
+
// Hardcoded backend URL - always use production
|
|
5
|
+
const BACKEND_URL = "https://routeflow-backend-production.up.railway.app";
|
|
8
6
|
const INGEST_ENDPOINT = "/v1/ingest";
|
|
7
|
+
/**
|
|
8
|
+
* Get the current backend URL.
|
|
9
|
+
*/
|
|
10
|
+
export function getBackendUrl() {
|
|
11
|
+
return BACKEND_URL;
|
|
12
|
+
}
|
|
9
13
|
/**
|
|
10
14
|
* Send events to Routeflow backend.
|
|
11
15
|
*/
|
package/dist/external_spans.js
CHANGED
package/dist/fetch_patch.js
CHANGED
|
@@ -5,12 +5,28 @@ import { isSameOrigin } from "./validate";
|
|
|
5
5
|
import { getOrCreateSessionId, generateTraceId } from "./trace";
|
|
6
6
|
import { getCurrentFrontendRoute } from "./route";
|
|
7
7
|
import { trackExternalFetch } from "./external_spans";
|
|
8
|
+
import { getBackendUrl } from "./client";
|
|
8
9
|
const TRACE_ID_HEADER = "x-routeflow-trace-id";
|
|
9
10
|
const SESSION_ID_HEADER = "x-routeflow-session-id";
|
|
10
11
|
const FRONTEND_ROUTE_HEADER = "x-routeflow-frontend-route";
|
|
11
12
|
let originalFetch;
|
|
12
13
|
let isPatched = false;
|
|
13
14
|
let trackExternal = false;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a URL is targeting the backend (where we should inject headers).
|
|
17
|
+
*/
|
|
18
|
+
function isBackendRequest(url) {
|
|
19
|
+
try {
|
|
20
|
+
const backendUrl = getBackendUrl();
|
|
21
|
+
const urlObj = new URL(url, window.location.href);
|
|
22
|
+
const backendObj = new URL(backendUrl);
|
|
23
|
+
// Match by origin (protocol + hostname + port)
|
|
24
|
+
return urlObj.origin === backendObj.origin;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
14
30
|
/**
|
|
15
31
|
* Patch window.fetch to add correlation headers.
|
|
16
32
|
*/
|
|
@@ -30,13 +46,15 @@ export function patchFetch(enableExternalTracking) {
|
|
|
30
46
|
: input instanceof URL
|
|
31
47
|
? input.href
|
|
32
48
|
: input.url;
|
|
49
|
+
const isBackend = isBackendRequest(url);
|
|
33
50
|
const sameOrigin = isSameOrigin(url);
|
|
34
|
-
// Add correlation headers for
|
|
35
|
-
|
|
36
|
-
if (sameOrigin) {
|
|
51
|
+
// Add correlation headers ONLY for backend requests
|
|
52
|
+
if (isBackend) {
|
|
37
53
|
init = addCorrelationHeaders(input, init);
|
|
38
54
|
}
|
|
39
|
-
// Track external spans if enabled
|
|
55
|
+
// Track external spans if enabled and not same-origin
|
|
56
|
+
// Note: We don't add correlation headers to external requests anymore
|
|
57
|
+
// unless they happen to be the backend
|
|
40
58
|
if (trackExternal && !sameOrigin) {
|
|
41
59
|
return trackAndFetch(url, init);
|
|
42
60
|
}
|
|
@@ -73,15 +91,14 @@ function addCorrelationHeaders(input, init) {
|
|
|
73
91
|
}
|
|
74
92
|
/**
|
|
75
93
|
* Track external fetch call and execute it.
|
|
76
|
-
*
|
|
94
|
+
* Note: Headers are NOT added here - only if isBackendRequest() is true (already handled in patchedFetch).
|
|
77
95
|
*/
|
|
78
96
|
async function trackAndFetch(url, init) {
|
|
79
97
|
const startTime = performance.now();
|
|
80
98
|
let response = null;
|
|
81
99
|
let error = null;
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
init = addCorrelationHeaders(url, init);
|
|
100
|
+
// Note: We don't add correlation headers here anymore
|
|
101
|
+
// Headers are only added if isBackendRequest() returned true (handled in patchedFetch)
|
|
85
102
|
try {
|
|
86
103
|
response = await originalFetch(url, init);
|
|
87
104
|
return response;
|
package/package.json
CHANGED