@introspection-sdk/introspection-proxy 0.20.0 → 0.21.0
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/proxy.d.ts +0 -7
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +0 -16
- package/dist/proxy.js.map +1 -1
- package/package.json +7 -4
- package/.turbo/turbo-build.log +0 -4
- package/eslint.config.mjs +0 -4
- package/src/index.ts +0 -21
- package/src/lazy.ts +0 -46
- package/src/proxy.ts +0 -260
- package/src/tracing.ts +0 -106
- package/tsconfig.json +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* alongside the `introspection-pi` instrumentation wrapper) without pulling
|
|
11
11
|
* in the full `introspection-node` surface.
|
|
12
12
|
*/
|
|
13
|
-
export {
|
|
13
|
+
export { createProxyFetch, installProxyFetch, resolveForwardProxyUrl, } from "./proxy.js";
|
|
14
14
|
export type { ProxyFetchOptions } from "./proxy.js";
|
|
15
15
|
export { PROXY_CALL_SPAN_NAME, PROXY_TRACER_NAME } from "./tracing.js";
|
|
16
16
|
export type { ProxyMode } from "./tracing.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACvE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
* alongside the `introspection-pi` instrumentation wrapper) without pulling
|
|
11
11
|
* in the full `introspection-node` surface.
|
|
12
12
|
*/
|
|
13
|
-
export {
|
|
13
|
+
export { createProxyFetch, installProxyFetch, resolveForwardProxyUrl, } from "./proxy.js";
|
|
14
14
|
export { PROXY_CALL_SPAN_NAME, PROXY_TRACER_NAME } from "./tracing.js";
|
|
15
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/proxy.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Dispatcher } from "undici";
|
|
2
1
|
export interface ProxyFetchOptions {
|
|
3
2
|
egressProxyUrl?: string;
|
|
4
3
|
egressProxyHosts?: string;
|
|
@@ -19,12 +18,6 @@ export interface ProxyFetchOptions {
|
|
|
19
18
|
propagateBaggage?: boolean;
|
|
20
19
|
}
|
|
21
20
|
export declare function resolveForwardProxyUrl(): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Returns a single dispatcher. When egress hosts are scoped, returns the
|
|
24
|
-
* forward dispatcher (the egress/forward split is per-request inside
|
|
25
|
-
* {@link createProxyFetch}).
|
|
26
|
-
*/
|
|
27
|
-
export declare function getProxyDispatcher(options?: ProxyFetchOptions): Dispatcher | undefined;
|
|
28
21
|
/** @internal Used by the lazy installer to preserve the pre-install fetch. */
|
|
29
22
|
export declare function createProxyFetchWithBase(options: ProxyFetchOptions | undefined, baseFetch: typeof fetch): typeof fetch;
|
|
30
23
|
export declare function createProxyFetch(options?: ProxyFetchOptions): typeof fetch;
|
package/dist/proxy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAiBD,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,SAAS,CAQ3D;AAqDD,8EAA8E;AAC9E,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,iBAAiB,YAAK,EAC/B,SAAS,EAAE,OAAO,KAAK,GACtB,OAAO,KAAK,CAsFd;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,iBAAsB,GAC9B,OAAO,KAAK,CAEd;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,IAAI,CAU7E"}
|
package/dist/proxy.js
CHANGED
|
@@ -61,22 +61,6 @@ function buildEgressDispatcher(proxyUrl) {
|
|
|
61
61
|
},
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Returns a single dispatcher. When egress hosts are scoped, returns the
|
|
66
|
-
* forward dispatcher (the egress/forward split is per-request inside
|
|
67
|
-
* {@link createProxyFetch}).
|
|
68
|
-
*/
|
|
69
|
-
export function getProxyDispatcher(options = {}) {
|
|
70
|
-
const egressUrl = resolveEgressUrl(options);
|
|
71
|
-
const egressHostSet = resolveEgressHosts(options);
|
|
72
|
-
if (egressUrl && egressHostSet.size > 0) {
|
|
73
|
-
return buildEgressDispatcher(egressUrl);
|
|
74
|
-
}
|
|
75
|
-
if (resolveForwardProxyUrl()) {
|
|
76
|
-
return new EnvHttpProxyAgent();
|
|
77
|
-
}
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
64
|
function toUrlString(input) {
|
|
81
65
|
if (typeof input === "string")
|
|
82
66
|
return input;
|
package/dist/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,KAAK,EACL,iBAAiB,EAEjB,KAAK,IAAI,WAAW,GAErB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,6EAA6E;AAC7E,4EAA4E;AAC5E,gEAAgE;AAChE,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAsBpD,SAAS,gBAAgB,CAAC,OAA0B;IAClD,OAAO,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;AACxE,CAAC;AAED,SAAS,kBAAkB,CAAC,OAA0B;IACpD,MAAM,GAAG,GACP,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,GAAG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|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Outbound HTTP proxy helpers for routing fetch-based clients through the Introspection egress proxy or a standard forward proxy",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=22
|
|
7
|
+
"node": ">=22"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "./dist/index.js",
|
|
@@ -19,9 +19,12 @@
|
|
|
19
19
|
"default": "./dist/lazy.js"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/"
|
|
24
|
+
],
|
|
22
25
|
"dependencies": {
|
|
23
26
|
"@opentelemetry/api": "^1.9.0",
|
|
24
|
-
"undici": "^8.
|
|
27
|
+
"undici": "^8.10.0"
|
|
25
28
|
},
|
|
26
29
|
"devDependencies": {
|
|
27
30
|
"@types/node": "^22.20.1",
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
"scripts": {
|
|
34
37
|
"lint": "eslint . --max-warnings 0",
|
|
35
38
|
"check-types": "tsc --noEmit",
|
|
36
|
-
"build": "tsc",
|
|
39
|
+
"build": "rm -rf dist && tsc",
|
|
37
40
|
"clean": "rm -rf dist"
|
|
38
41
|
}
|
|
39
42
|
}
|
package/.turbo/turbo-build.log
DELETED
package/eslint.config.mjs
DELETED
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@introspection-sdk/introspection-proxy`
|
|
3
|
-
*
|
|
4
|
-
* Lightweight, dependency-minimal helpers for routing `fetch`-based clients
|
|
5
|
-
* through the Introspection egress credential-injection proxy or a standard
|
|
6
|
-
* forward proxy. Depends only on undici and the zero-dependency
|
|
7
|
-
* `@opentelemetry/api` (proxied requests emit `introspection-proxy-call`
|
|
8
|
-
* spans that no-op unless the host process registers a tracer provider — no
|
|
9
|
-
* OTel SDK or provider-SDK dependencies), so it can be used standalone (e.g.
|
|
10
|
-
* alongside the `introspection-pi` instrumentation wrapper) without pulling
|
|
11
|
-
* in the full `introspection-node` surface.
|
|
12
|
-
*/
|
|
13
|
-
export {
|
|
14
|
-
getProxyDispatcher,
|
|
15
|
-
createProxyFetch,
|
|
16
|
-
installProxyFetch,
|
|
17
|
-
resolveForwardProxyUrl,
|
|
18
|
-
} from "./proxy.js";
|
|
19
|
-
export type { ProxyFetchOptions } from "./proxy.js";
|
|
20
|
-
export { PROXY_CALL_SPAN_NAME, PROXY_TRACER_NAME } from "./tracing.js";
|
|
21
|
-
export type { ProxyMode } from "./tracing.js";
|
package/src/lazy.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { ProxyFetchOptions } from "./proxy.js";
|
|
2
|
-
|
|
3
|
-
export interface LazyProxyFetchInstallation {
|
|
4
|
-
/** Load and initialize the proxy engine. Concurrent calls share one promise. */
|
|
5
|
-
ready(): Promise<typeof fetch>;
|
|
6
|
-
/** Restore the fetch implementation that was active before installation. */
|
|
7
|
-
restore(): void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Install a proxy-enforcing fetch guard without loading Undici eagerly.
|
|
12
|
-
*
|
|
13
|
-
* The guard is installed synchronously, so outbound requests cannot race proxy
|
|
14
|
-
* initialization. The first request waits for the real proxy implementation;
|
|
15
|
-
* callers that own process startup can invoke `ready()` after their listener is
|
|
16
|
-
* bound to overlap initialization with the rest of application bootstrap.
|
|
17
|
-
*/
|
|
18
|
-
export function installLazyProxyFetch(
|
|
19
|
-
options: ProxyFetchOptions = {},
|
|
20
|
-
): LazyProxyFetchInstallation {
|
|
21
|
-
const original = globalThis.fetch;
|
|
22
|
-
let proxyPromise: Promise<typeof fetch> | undefined;
|
|
23
|
-
|
|
24
|
-
const ready = (): Promise<typeof fetch> => {
|
|
25
|
-
proxyPromise ??= import("./proxy.js").then(({ createProxyFetchWithBase }) =>
|
|
26
|
-
createProxyFetchWithBase(options, original),
|
|
27
|
-
);
|
|
28
|
-
return proxyPromise;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const guardedFetch: typeof fetch = async (input, init) => {
|
|
32
|
-
const proxiedFetch = await ready();
|
|
33
|
-
return proxiedFetch(input, init);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
globalThis.fetch = guardedFetch;
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
ready,
|
|
40
|
-
restore() {
|
|
41
|
-
if (globalThis.fetch === guardedFetch) {
|
|
42
|
-
globalThis.fetch = original;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
package/src/proxy.ts
DELETED
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Outbound HTTP proxy helpers for `fetch`-based clients.
|
|
3
|
-
*
|
|
4
|
-
* Two proxy modes, selected per-request:
|
|
5
|
-
*
|
|
6
|
-
* - **Egress credential-injection proxy** (`INTROSPECTION_EGRESS_URL`):
|
|
7
|
-
* plain-HTTP reverse proxy that routes by `Host` header and injects upstream
|
|
8
|
-
* credentials via ext_proc. Only used for hosts listed in
|
|
9
|
-
* `INTROSPECTION_ENDPOINT_HOSTS` (comma-separated). When the host list is
|
|
10
|
-
* empty, egress is disabled and all traffic uses the forward proxy.
|
|
11
|
-
*
|
|
12
|
-
* - **Forward CONNECT proxy** (`HTTPS_PROXY` / `HTTP_PROXY`): opaque TLS
|
|
13
|
-
* tunnel the proxy cannot read or modify. Used for all other hosts (S3,
|
|
14
|
-
* GitHub, npm, etc.).
|
|
15
|
-
*/
|
|
16
|
-
import { Socket } from "node:net";
|
|
17
|
-
import { connect as tlsConnect } from "node:tls";
|
|
18
|
-
import { context, propagation } from "@opentelemetry/api";
|
|
19
|
-
import {
|
|
20
|
-
Agent,
|
|
21
|
-
EnvHttpProxyAgent,
|
|
22
|
-
buildConnector,
|
|
23
|
-
fetch as undiciFetch,
|
|
24
|
-
type Dispatcher,
|
|
25
|
-
} from "undici";
|
|
26
|
-
import {
|
|
27
|
-
matchesNoProxy,
|
|
28
|
-
parseNoProxyEntries,
|
|
29
|
-
tracedProxyCall,
|
|
30
|
-
} from "./tracing.js";
|
|
31
|
-
|
|
32
|
-
// Agent sessions commonly pause for tools or user input between model calls.
|
|
33
|
-
// Undici's 4-second default closes the otherwise reusable egress connection
|
|
34
|
-
// before the next call, forcing another proxy socket handshake.
|
|
35
|
-
const EGRESS_KEEP_ALIVE_TIMEOUT_MS = 10 * 60 * 1000;
|
|
36
|
-
|
|
37
|
-
export interface ProxyFetchOptions {
|
|
38
|
-
egressProxyUrl?: string;
|
|
39
|
-
egressProxyHosts?: string;
|
|
40
|
-
forwardProxyUrl?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Emit an `introspection-proxy-call` OTel span per proxied request
|
|
43
|
-
* (default true). Spans no-op unless the host process registered a tracer
|
|
44
|
-
* provider. Direct requests (no proxy, or `NO_PROXY` hosts) never get a
|
|
45
|
-
* span regardless of this flag.
|
|
46
|
-
*/
|
|
47
|
-
tracing?: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Propagate active OTel baggage alongside trace context (default false).
|
|
50
|
-
* Enable only for trusted application endpoints; baggage can contain
|
|
51
|
-
* conversation or identity correlation and must not be sent to arbitrary
|
|
52
|
-
* third-party hosts.
|
|
53
|
-
*/
|
|
54
|
-
propagateBaggage?: boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function resolveEgressUrl(options: ProxyFetchOptions): string | undefined {
|
|
58
|
-
return options.egressProxyUrl ?? process.env.INTROSPECTION_EGRESS_URL;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function resolveEgressHosts(options: ProxyFetchOptions): Set<string> {
|
|
62
|
-
const raw =
|
|
63
|
-
options.egressProxyHosts ?? process.env.INTROSPECTION_ENDPOINT_HOSTS ?? "";
|
|
64
|
-
return new Set(
|
|
65
|
-
raw
|
|
66
|
-
.split(",")
|
|
67
|
-
.map((h) => h.trim().toLowerCase())
|
|
68
|
-
.filter(Boolean),
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function resolveForwardProxyUrl(): string | undefined {
|
|
73
|
-
return (
|
|
74
|
-
process.env.HTTPS_PROXY ||
|
|
75
|
-
process.env.https_proxy ||
|
|
76
|
-
process.env.HTTP_PROXY ||
|
|
77
|
-
process.env.http_proxy ||
|
|
78
|
-
undefined
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function buildEgressDispatcher(proxyUrl: string): Dispatcher {
|
|
83
|
-
const url = new URL(proxyUrl);
|
|
84
|
-
const useTls = url.protocol === "https:";
|
|
85
|
-
const port = Number(url.port) || (useTls ? 443 : 80);
|
|
86
|
-
const host = url.hostname;
|
|
87
|
-
|
|
88
|
-
return new Agent({
|
|
89
|
-
keepAliveTimeout: EGRESS_KEEP_ALIVE_TIMEOUT_MS,
|
|
90
|
-
keepAliveMaxTimeout: EGRESS_KEEP_ALIVE_TIMEOUT_MS,
|
|
91
|
-
connect(
|
|
92
|
-
_options: buildConnector.Options,
|
|
93
|
-
callback: buildConnector.Callback,
|
|
94
|
-
): void {
|
|
95
|
-
if (useTls) {
|
|
96
|
-
const socket = tlsConnect({ host, port, servername: host });
|
|
97
|
-
socket.once("secureConnect", () => callback(null, socket));
|
|
98
|
-
socket.once("error", (err) => callback(err, null));
|
|
99
|
-
} else {
|
|
100
|
-
const socket = new Socket();
|
|
101
|
-
socket.connect(port, host, () => callback(null, socket));
|
|
102
|
-
socket.once("error", (err) => callback(err, null));
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Returns a single dispatcher. When egress hosts are scoped, returns the
|
|
110
|
-
* forward dispatcher (the egress/forward split is per-request inside
|
|
111
|
-
* {@link createProxyFetch}).
|
|
112
|
-
*/
|
|
113
|
-
export function getProxyDispatcher(
|
|
114
|
-
options: ProxyFetchOptions = {},
|
|
115
|
-
): Dispatcher | undefined {
|
|
116
|
-
const egressUrl = resolveEgressUrl(options);
|
|
117
|
-
const egressHostSet = resolveEgressHosts(options);
|
|
118
|
-
if (egressUrl && egressHostSet.size > 0) {
|
|
119
|
-
return buildEgressDispatcher(egressUrl);
|
|
120
|
-
}
|
|
121
|
-
if (resolveForwardProxyUrl()) {
|
|
122
|
-
return new EnvHttpProxyAgent();
|
|
123
|
-
}
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function toUrlString(input: RequestInfo | URL): string {
|
|
128
|
-
if (typeof input === "string") return input;
|
|
129
|
-
if (input instanceof URL) return input.toString();
|
|
130
|
-
return (input as Request).url;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function downgradeToHttp(url: string | URL): string {
|
|
134
|
-
const s = typeof url === "string" ? url : url.toString();
|
|
135
|
-
return s.startsWith("https://") ? "http://" + s.slice(8) : s;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function withInjectedTraceContext(
|
|
139
|
-
opts: Record<string, unknown>,
|
|
140
|
-
propagateBaggage: boolean,
|
|
141
|
-
): Record<string, unknown> {
|
|
142
|
-
const headers = new Headers(opts.headers as HeadersInit | undefined);
|
|
143
|
-
propagation.inject(context.active(), headers, {
|
|
144
|
-
set(carrier, key, value) {
|
|
145
|
-
if (!propagateBaggage && key.toLowerCase() === "baggage") return;
|
|
146
|
-
carrier.set(key, value);
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
return { ...opts, headers };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** @internal Used by the lazy installer to preserve the pre-install fetch. */
|
|
153
|
-
export function createProxyFetchWithBase(
|
|
154
|
-
options: ProxyFetchOptions = {},
|
|
155
|
-
baseFetch: typeof fetch,
|
|
156
|
-
): typeof fetch {
|
|
157
|
-
// Capture the real fetch now, before installProxyFetch swaps
|
|
158
|
-
// globalThis.fetch to this wrapper. The per-request fallback below must not
|
|
159
|
-
// re-read the global, or it would recurse into the installed proxy.
|
|
160
|
-
const base = baseFetch;
|
|
161
|
-
const egressUrl = resolveEgressUrl(options);
|
|
162
|
-
const egressHosts = resolveEgressHosts(options);
|
|
163
|
-
const egressIsPlainHttp =
|
|
164
|
-
!!egressUrl && new URL(egressUrl).protocol === "http:";
|
|
165
|
-
|
|
166
|
-
const egress = egressUrl ? buildEgressDispatcher(egressUrl) : undefined;
|
|
167
|
-
const forward = resolveForwardProxyUrl()
|
|
168
|
-
? new EnvHttpProxyAgent()
|
|
169
|
-
: undefined;
|
|
170
|
-
|
|
171
|
-
if (!egress && !forward) return base;
|
|
172
|
-
|
|
173
|
-
const tracing = options.tracing ?? true;
|
|
174
|
-
// Snapshot NO_PROXY once, like EnvHttpProxyAgent does at construction. Used
|
|
175
|
-
// only to decide span emission — undici owns the actual routing.
|
|
176
|
-
const noProxyEntries = parseNoProxyEntries(process.env);
|
|
177
|
-
|
|
178
|
-
return (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
|
|
179
|
-
const url = new URL(toUrlString(input));
|
|
180
|
-
const hostname = url.hostname.toLowerCase();
|
|
181
|
-
|
|
182
|
-
const useEgress =
|
|
183
|
-
!!egress && egressHosts.size > 0 && egressHosts.has(hostname);
|
|
184
|
-
const dispatcher = useEgress ? egress : forward;
|
|
185
|
-
|
|
186
|
-
if (!dispatcher) return base(input, init);
|
|
187
|
-
|
|
188
|
-
let target: string | URL;
|
|
189
|
-
let opts: Record<string, unknown>;
|
|
190
|
-
|
|
191
|
-
if (typeof Request !== "undefined" && input instanceof Request) {
|
|
192
|
-
target = input.url;
|
|
193
|
-
opts = {
|
|
194
|
-
method: input.method,
|
|
195
|
-
headers: input.headers,
|
|
196
|
-
body: input.body,
|
|
197
|
-
signal: input.signal,
|
|
198
|
-
redirect: input.redirect,
|
|
199
|
-
credentials: input.credentials,
|
|
200
|
-
...init,
|
|
201
|
-
dispatcher,
|
|
202
|
-
};
|
|
203
|
-
if (input.body != null) opts.duplex = "half";
|
|
204
|
-
} else {
|
|
205
|
-
target = input as string | URL;
|
|
206
|
-
opts = { ...init, dispatcher };
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (useEgress && egressIsPlainHttp) {
|
|
210
|
-
target = downgradeToHttp(target);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const execute = () =>
|
|
214
|
-
undiciFetch(
|
|
215
|
-
target as unknown as Parameters<typeof undiciFetch>[0],
|
|
216
|
-
withInjectedTraceContext(
|
|
217
|
-
opts,
|
|
218
|
-
options.propagateBaggage ?? false,
|
|
219
|
-
) as unknown as Parameters<typeof undiciFetch>[1],
|
|
220
|
-
) as unknown as Promise<Response>;
|
|
221
|
-
|
|
222
|
-
// A forward-dispatched request to a NO_PROXY host goes direct inside
|
|
223
|
-
// EnvHttpProxyAgent — no proxy hop, so no proxy span (in-cluster clients
|
|
224
|
-
// trace those calls themselves as `introspection-api-call`).
|
|
225
|
-
const viaProxy =
|
|
226
|
-
useEgress || !matchesNoProxy(hostname, url.port, noProxyEntries);
|
|
227
|
-
if (!tracing || !viaProxy) return execute();
|
|
228
|
-
|
|
229
|
-
const method = (
|
|
230
|
-
init?.method ??
|
|
231
|
-
(typeof Request !== "undefined" && input instanceof Request
|
|
232
|
-
? input.method
|
|
233
|
-
: "GET")
|
|
234
|
-
).toUpperCase();
|
|
235
|
-
return tracedProxyCall(
|
|
236
|
-
useEgress ? "egress" : "forward",
|
|
237
|
-
method,
|
|
238
|
-
url,
|
|
239
|
-
execute,
|
|
240
|
-
);
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function createProxyFetch(
|
|
245
|
-
options: ProxyFetchOptions = {},
|
|
246
|
-
): typeof fetch {
|
|
247
|
-
return createProxyFetchWithBase(options, globalThis.fetch);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export function installProxyFetch(options: ProxyFetchOptions = {}): () => void {
|
|
251
|
-
const original = globalThis.fetch;
|
|
252
|
-
const proxied = createProxyFetch(options);
|
|
253
|
-
if (proxied === original) return () => {};
|
|
254
|
-
globalThis.fetch = proxied;
|
|
255
|
-
return () => {
|
|
256
|
-
if (globalThis.fetch === proxied) {
|
|
257
|
-
globalThis.fetch = original;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
package/src/tracing.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenTelemetry span instrumentation for proxied requests.
|
|
3
|
-
*
|
|
4
|
-
* Emits one `introspection-proxy-call` CLIENT span per request that is
|
|
5
|
-
* actually routed through a proxy (egress credential-injection or forward
|
|
6
|
-
* CONNECT). Requests that go direct — no proxy configured, or the host is
|
|
7
|
-
* excluded via `NO_PROXY` — deliberately get no span: in-cluster callers
|
|
8
|
-
* (`NO_PROXY` covers the DP API) already trace those calls at the client
|
|
9
|
-
* layer, so proxy spans and client-layer spans stay mutually exclusive.
|
|
10
|
-
*
|
|
11
|
-
* Depends only on `@opentelemetry/api`: without a registered tracer provider
|
|
12
|
-
* every span here is a no-op, so the package stays safe to load in bare Node
|
|
13
|
-
* processes (e.g. the sandbox `NODE_OPTIONS` preload).
|
|
14
|
-
*
|
|
15
|
-
* Attributes are intentionally lean — transport shape only (method, host,
|
|
16
|
-
* port, query-stripped URL, proxy mode, status). Tenant/task identity is
|
|
17
|
-
* inferred server-side from the request's JWT, or stamped globally by the
|
|
18
|
-
* host process's span processors, never duplicated here. Query strings are
|
|
19
|
-
* stripped because they can carry capability tokens (presigned URLs,
|
|
20
|
-
* share ids).
|
|
21
|
-
*/
|
|
22
|
-
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
23
|
-
|
|
24
|
-
export const PROXY_CALL_SPAN_NAME = "introspection-proxy-call";
|
|
25
|
-
export const PROXY_TRACER_NAME = "@introspection-sdk/introspection-proxy";
|
|
26
|
-
|
|
27
|
-
export type ProxyMode = "egress" | "forward";
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Parse `NO_PROXY`/`no_proxy` into normalized entries. Mirrors undici's
|
|
31
|
-
* `EnvHttpProxyAgent` semantics closely enough to decide span emission —
|
|
32
|
-
* undici still owns the actual routing decision.
|
|
33
|
-
*/
|
|
34
|
-
export function parseNoProxyEntries(env: NodeJS.ProcessEnv): string[] {
|
|
35
|
-
const raw = env.NO_PROXY ?? env.no_proxy ?? "";
|
|
36
|
-
return raw
|
|
37
|
-
.split(",")
|
|
38
|
-
.map((entry) => entry.trim().toLowerCase())
|
|
39
|
-
.filter(Boolean);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Whether `hostname[:port]` matches a `NO_PROXY` entry (i.e. goes direct). */
|
|
43
|
-
export function matchesNoProxy(
|
|
44
|
-
hostname: string,
|
|
45
|
-
port: string,
|
|
46
|
-
entries: string[],
|
|
47
|
-
): boolean {
|
|
48
|
-
for (const raw of entries) {
|
|
49
|
-
if (raw === "*") return true;
|
|
50
|
-
let entry = raw;
|
|
51
|
-
let entryPort = "";
|
|
52
|
-
const colon = entry.lastIndexOf(":");
|
|
53
|
-
if (colon !== -1 && !entry.slice(colon).includes("]")) {
|
|
54
|
-
entryPort = entry.slice(colon + 1);
|
|
55
|
-
entry = entry.slice(0, colon);
|
|
56
|
-
}
|
|
57
|
-
if (entryPort && entryPort !== port) continue;
|
|
58
|
-
if (entry.startsWith(".")) entry = entry.slice(1);
|
|
59
|
-
if (hostname === entry || hostname.endsWith(`.${entry}`)) return true;
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Run `execute` inside an `introspection-proxy-call` CLIENT span. */
|
|
65
|
-
export function tracedProxyCall(
|
|
66
|
-
mode: ProxyMode,
|
|
67
|
-
method: string,
|
|
68
|
-
url: URL,
|
|
69
|
-
execute: () => Promise<Response>,
|
|
70
|
-
): Promise<Response> {
|
|
71
|
-
const tracer = trace.getTracer(PROXY_TRACER_NAME);
|
|
72
|
-
const port = Number(url.port) || (url.protocol === "https:" ? 443 : 80);
|
|
73
|
-
return tracer.startActiveSpan(
|
|
74
|
-
PROXY_CALL_SPAN_NAME,
|
|
75
|
-
{
|
|
76
|
-
kind: SpanKind.CLIENT,
|
|
77
|
-
attributes: {
|
|
78
|
-
"http.request.method": method,
|
|
79
|
-
"server.address": url.hostname,
|
|
80
|
-
"server.port": port,
|
|
81
|
-
"url.full": url.origin + url.pathname,
|
|
82
|
-
"url.path": url.pathname,
|
|
83
|
-
"introspection.proxy.mode": mode,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
async (span) => {
|
|
87
|
-
try {
|
|
88
|
-
const response = await execute();
|
|
89
|
-
span.setAttribute("http.response.status_code", response.status);
|
|
90
|
-
if (response.status >= 400) {
|
|
91
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
92
|
-
}
|
|
93
|
-
return response;
|
|
94
|
-
} catch (err) {
|
|
95
|
-
span.recordException(err instanceof Error ? err : String(err));
|
|
96
|
-
span.setStatus({
|
|
97
|
-
code: SpanStatusCode.ERROR,
|
|
98
|
-
message: err instanceof Error ? err.message : String(err),
|
|
99
|
-
});
|
|
100
|
-
throw err;
|
|
101
|
-
} finally {
|
|
102
|
-
span.end();
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
);
|
|
106
|
-
}
|