@apifuse/provider-sdk 2.2.0-beta.4 → 2.2.0-beta.40
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/AUTHORING.md +501 -13
- package/CHANGELOG.md +165 -1
- package/README.md +72 -14
- package/SUBMISSION.md +1 -1
- package/bin/apifuse-check.ts +88 -4
- package/bin/apifuse-dev.ts +38 -5
- package/bin/apifuse-pack-check.ts +22 -2
- package/bin/apifuse-pack-smoke.ts +57 -2
- package/bin/apifuse-pack-types.ts +356 -38
- package/bin/apifuse-perf.ts +14 -13
- package/bin/apifuse-record.ts +691 -68
- package/bin/apifuse-submit-check.ts +518 -37
- package/bin/apifuse-sync-assets.ts +117 -0
- package/bin/submit-check-delimited-text.ts +50 -0
- package/dist/auth-turn/index.d.ts +3 -3
- package/dist/auth-turn/index.js +1 -1
- package/dist/auth.d.ts +14 -0
- package/dist/auth.js +67 -0
- package/dist/ceremonies/index.d.ts +16 -0
- package/dist/ceremonies/index.js +141 -36
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +8 -0
- package/dist/cli/create.d.ts +3 -0
- package/dist/cli/create.js +34 -35
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/dist/cli/templates/provider/Dockerfile.tpl +1 -1
- package/dist/cli/templates/provider/README.md.tpl +4 -4
- package/dist/cli/templates/provider/index.ts.tpl +6 -3
- package/dist/cli/templates/provider/operations/ping.ts.tpl +2 -1
- package/dist/config/loader.d.ts +177 -16
- package/dist/config/loader.js +424 -127
- package/dist/contract-serialization.js +4 -8
- package/dist/contract-types.d.ts +1 -0
- package/dist/contract.js +2 -0
- package/dist/declaration-validation.d.ts +32 -0
- package/dist/declaration-validation.js +207 -0
- package/dist/define.d.ts +51 -25
- package/dist/define.js +752 -38
- package/dist/error-resolution.d.ts +4 -0
- package/dist/error-resolution.js +122 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +40 -0
- package/dist/fixture-sanitization.d.ts +28 -0
- package/dist/fixture-sanitization.js +217 -0
- package/dist/health-scenario.d.ts +1842 -0
- package/dist/health-scenario.js +624 -0
- package/dist/index.d.ts +19 -9
- package/dist/index.js +10 -6
- package/dist/lint.d.ts +6 -1
- package/dist/lint.js +362 -3
- package/dist/native-address.d.ts +43 -0
- package/dist/native-address.js +281 -0
- package/dist/native-egress-policy.d.ts +31 -0
- package/dist/native-egress-policy.js +288 -0
- package/dist/observability.d.ts +5 -2
- package/dist/observability.js +48 -1
- package/dist/provider.d.ts +8 -2
- package/dist/provider.js +3 -1
- package/dist/runtime/auth-flow.d.ts +5 -1
- package/dist/runtime/auth-flow.js +6 -0
- package/dist/runtime/browser.d.ts +1 -0
- package/dist/runtime/browser.js +492 -49
- package/dist/runtime/cache.d.ts +1 -0
- package/dist/runtime/cache.js +169 -15
- package/dist/runtime/choice-wordlist.d.ts +9 -0
- package/dist/runtime/choice-wordlist.js +138 -0
- package/dist/runtime/choice.d.ts +13 -1
- package/dist/runtime/choice.js +490 -102
- package/dist/runtime/executor.d.ts +2 -2
- package/dist/runtime/executor.js +26 -2
- package/dist/runtime/http.d.ts +1 -0
- package/dist/runtime/http.js +515 -53
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/instrumentation.js +366 -8
- package/dist/runtime/native-network-errors.d.ts +33 -0
- package/dist/runtime/native-network-errors.js +69 -0
- package/dist/runtime/native-network.d.ts +96 -0
- package/dist/runtime/native-network.js +1232 -0
- package/dist/runtime/ocr.d.ts +29 -0
- package/dist/runtime/ocr.js +440 -0
- package/dist/runtime/proxy-errors.js +6 -2
- package/dist/runtime/proxy-nodemaven.d.ts +56 -0
- package/dist/runtime/proxy-nodemaven.js +146 -0
- package/dist/runtime/proxy-telemetry.d.ts +80 -1
- package/dist/runtime/proxy-telemetry.js +154 -47
- package/dist/runtime/redirects.d.ts +29 -0
- package/dist/runtime/redirects.js +36 -0
- package/dist/runtime/redis.d.ts +1 -1
- package/dist/runtime/redis.js +4 -2
- package/dist/runtime/request-options.d.ts +68 -1
- package/dist/runtime/request-options.js +548 -0
- package/dist/runtime/resolver-config.d.ts +6 -0
- package/dist/runtime/resolver-config.js +6 -0
- package/dist/runtime/resolver-public.d.ts +1 -0
- package/dist/runtime/resolver-public.js +1 -0
- package/dist/runtime/resolver-shared.d.ts +3 -0
- package/dist/runtime/resolver-shared.js +12 -0
- package/dist/runtime/resolver-vendors/bindings.d.ts +48 -0
- package/dist/runtime/resolver-vendors/bindings.js +40 -0
- package/dist/runtime/resolver-vendors/browser.d.ts +22 -0
- package/dist/runtime/resolver-vendors/browser.js +377 -0
- package/dist/runtime/resolver-vendors/capsolver.d.ts +22 -0
- package/dist/runtime/resolver-vendors/capsolver.js +526 -0
- package/dist/runtime/resolver-vendors/hosts.d.ts +2 -0
- package/dist/runtime/resolver-vendors/hosts.js +33 -0
- package/dist/runtime/resolver-vendors/twocaptcha.d.ts +24 -0
- package/dist/runtime/resolver-vendors/twocaptcha.js +407 -0
- package/dist/runtime/resolver-vendors/types.d.ts +94 -0
- package/dist/runtime/resolver-vendors/types.js +96 -0
- package/dist/runtime/resolver.d.ts +60 -0
- package/dist/runtime/resolver.js +737 -0
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/state.d.ts +3 -0
- package/dist/runtime/state.js +277 -71
- package/dist/runtime/stealth-cookies.d.ts +20 -0
- package/dist/runtime/stealth-cookies.js +111 -0
- package/dist/runtime/stealth.d.ts +28 -3
- package/dist/runtime/stealth.js +519 -255
- package/dist/runtime/stt.js +1 -12
- package/dist/runtime/timeout.d.ts +5 -0
- package/dist/runtime/timeout.js +12 -0
- package/dist/runtime/trace-config.d.ts +12 -0
- package/dist/runtime/trace-config.js +61 -0
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/server/index.d.ts +5 -3
- package/dist/server/index.js +3 -3
- package/dist/server/self-test-input-tokens.d.ts +2 -1
- package/dist/server/self-test-input-tokens.js +18 -14
- package/dist/server/self-test.d.ts +114 -0
- package/dist/server/self-test.js +784 -148
- package/dist/server/serve-implementation.d.ts +213 -0
- package/dist/server/serve-implementation.js +2173 -0
- package/dist/server/serve.d.ts +1 -70
- package/dist/server/serve.js +1 -1130
- package/dist/server/trace-output.d.ts +4 -0
- package/dist/server/trace-output.js +20 -0
- package/dist/server/types.d.ts +30 -5
- package/dist/server/types.js +13 -1
- package/dist/stateful/errors.d.ts +19 -0
- package/dist/stateful/errors.js +24 -0
- package/dist/stateful/http-provider-event-emitter.d.ts +40 -0
- package/dist/stateful/http-provider-event-emitter.js +237 -0
- package/dist/stateful/http-session-owner-registry.d.ts +44 -0
- package/dist/stateful/http-session-owner-registry.js +210 -0
- package/dist/stateful/index.d.ts +18 -0
- package/dist/stateful/index.js +18 -0
- package/dist/stateful/provider-event-delivery-failures.d.ts +32 -0
- package/dist/stateful/provider-event-delivery-failures.js +43 -0
- package/dist/stateful/provider-event-pipeline-metrics.d.ts +46 -0
- package/dist/stateful/provider-event-pipeline-metrics.js +48 -0
- package/dist/stateful/provider-event-pipeline.d.ts +50 -0
- package/dist/stateful/provider-event-pipeline.js +1 -0
- package/dist/stateful/provider-events.d.ts +101 -0
- package/dist/stateful/provider-events.js +289 -0
- package/dist/stateful/session-key.d.ts +15 -0
- package/dist/stateful/session-key.js +86 -0
- package/dist/stateful/stateful-provider-adapter-context.d.ts +5 -0
- package/dist/stateful/stateful-provider-adapter-context.js +42 -0
- package/dist/stateful/stateful-provider-adapter-metrics.d.ts +15 -0
- package/dist/stateful/stateful-provider-adapter-metrics.js +21 -0
- package/dist/stateful/stateful-provider-adapter.d.ts +98 -0
- package/dist/stateful/stateful-provider-adapter.js +287 -0
- package/dist/stateful/stateful-provider-observability.d.ts +62 -0
- package/dist/stateful/stateful-provider-observability.js +161 -0
- package/dist/stateful/stateful-provider-owner-forwarder.d.ts +41 -0
- package/dist/stateful/stateful-provider-owner-forwarder.js +215 -0
- package/dist/stateful/stateful-provider-runtime-context.d.ts +32 -0
- package/dist/stateful/stateful-provider-runtime-context.js +60 -0
- package/dist/stateful/stateful-provider-runtime-executor.d.ts +34 -0
- package/dist/stateful/stateful-provider-runtime-executor.js +52 -0
- package/dist/stateful/stateful-provider-session-routing.d.ts +67 -0
- package/dist/stateful/stateful-provider-session-routing.js +345 -0
- package/dist/stateful/stateful-provider-session-runtime.d.ts +98 -0
- package/dist/stateful/stateful-provider-session-runtime.js +245 -0
- package/dist/stateful-signing.d.ts +18 -0
- package/dist/stateful-signing.js +27 -0
- package/dist/stealth/profiles.js +16 -7
- package/dist/stream-evidence.d.ts +74 -0
- package/dist/stream-evidence.js +785 -0
- package/dist/stream.js +7 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/run.d.ts +32 -2
- package/dist/testing/run.js +489 -21
- package/dist/trace-sanitization.d.ts +5 -0
- package/dist/trace-sanitization.js +45 -0
- package/dist/types.d.ts +545 -23
- package/dist/types.js +1 -0
- package/package.json +44 -5
- package/src/auth-turn/index.ts +1 -1
- package/src/auth.ts +118 -0
- package/src/ceremonies/index.ts +189 -46
- package/src/cli/commands.ts +10 -0
- package/src/cli/create.ts +42 -35
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/src/cli/templates/provider/Dockerfile.tpl +1 -1
- package/src/cli/templates/provider/README.md.tpl +4 -4
- package/src/cli/templates/provider/index.ts.tpl +6 -3
- package/src/cli/templates/provider/operations/ping.ts.tpl +2 -1
- package/src/config/loader.ts +665 -163
- package/src/contract-serialization.ts +5 -7
- package/src/contract-types.ts +1 -0
- package/src/contract.ts +2 -0
- package/src/declaration-validation.ts +266 -0
- package/src/define.ts +970 -87
- package/src/error-resolution.ts +127 -0
- package/src/errors.ts +52 -0
- package/src/fixture-sanitization.ts +248 -0
- package/src/health-scenario.ts +875 -0
- package/src/index.ts +204 -8
- package/src/lint.ts +408 -4
- package/src/native-address.ts +340 -0
- package/src/native-egress-policy.ts +358 -0
- package/src/observability.ts +51 -1
- package/src/provider.ts +133 -0
- package/src/runtime/auth-flow.ts +12 -0
- package/src/runtime/browser.ts +661 -63
- package/src/runtime/cache.ts +189 -14
- package/src/runtime/choice-wordlist.ts +145 -0
- package/src/runtime/choice.ts +631 -120
- package/src/runtime/executor.ts +40 -7
- package/src/runtime/http.ts +641 -61
- package/src/runtime/instrumentation.ts +520 -15
- package/src/runtime/native-network-errors.ts +99 -0
- package/src/runtime/native-network.ts +1605 -0
- package/src/runtime/ocr.ts +523 -0
- package/src/runtime/proxy-errors.ts +12 -4
- package/src/runtime/proxy-nodemaven.ts +221 -0
- package/src/runtime/proxy-telemetry.ts +244 -75
- package/src/runtime/redirects.ts +66 -0
- package/src/runtime/redis.ts +7 -2
- package/src/runtime/request-options.ts +680 -1
- package/src/runtime/resolver-config.ts +6 -0
- package/src/runtime/resolver-public.ts +20 -0
- package/src/runtime/resolver-shared.ts +17 -0
- package/src/runtime/resolver-vendors/bindings.ts +56 -0
- package/src/runtime/resolver-vendors/browser.ts +533 -0
- package/src/runtime/resolver-vendors/capsolver.ts +700 -0
- package/src/runtime/resolver-vendors/hosts.ts +38 -0
- package/src/runtime/resolver-vendors/twocaptcha.ts +539 -0
- package/src/runtime/resolver-vendors/types.ts +212 -0
- package/src/runtime/resolver.ts +1103 -0
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/state.ts +394 -77
- package/src/runtime/stealth-cookies.ts +132 -0
- package/src/runtime/stealth.ts +675 -289
- package/src/runtime/stt.ts +1 -19
- package/src/runtime/timeout.ts +18 -0
- package/src/runtime/trace-config.ts +77 -0
- package/src/serve.ts +6 -1
- package/src/server/index.ts +37 -2
- package/src/server/self-test-input-tokens.ts +29 -14
- package/src/server/self-test.ts +1025 -175
- package/src/server/serve-implementation.ts +3250 -0
- package/src/server/serve.ts +1 -1626
- package/src/server/trace-output.ts +32 -0
- package/src/server/types.ts +13 -1
- package/src/stateful/README.md +146 -0
- package/src/stateful/errors.ts +35 -0
- package/src/stateful/http-provider-event-emitter.ts +314 -0
- package/src/stateful/http-session-owner-registry.ts +306 -0
- package/src/stateful/index.ts +18 -0
- package/src/stateful/provider-event-delivery-failures.ts +80 -0
- package/src/stateful/provider-event-pipeline-metrics.ts +95 -0
- package/src/stateful/provider-event-pipeline.ts +61 -0
- package/src/stateful/provider-events.ts +462 -0
- package/src/stateful/session-key.ts +111 -0
- package/src/stateful/stateful-provider-adapter-context.ts +59 -0
- package/src/stateful/stateful-provider-adapter-metrics.ts +48 -0
- package/src/stateful/stateful-provider-adapter.ts +562 -0
- package/src/stateful/stateful-provider-observability.ts +261 -0
- package/src/stateful/stateful-provider-owner-forwarder.ts +287 -0
- package/src/stateful/stateful-provider-runtime-context.ts +92 -0
- package/src/stateful/stateful-provider-runtime-executor.ts +96 -0
- package/src/stateful/stateful-provider-session-routing.ts +546 -0
- package/src/stateful/stateful-provider-session-runtime.ts +403 -0
- package/src/stateful-signing.ts +46 -0
- package/src/stealth/profiles.ts +17 -7
- package/src/stream-evidence.ts +988 -0
- package/src/stream.ts +8 -1
- package/src/testing/index.ts +10 -1
- package/src/testing/run.ts +658 -15
- package/src/trace-sanitization.ts +63 -0
- package/src/types.ts +660 -38
- package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
- package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
- /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
|
@@ -1,20 +1,60 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
HttpStreamResponse,
|
|
3
|
+
ProviderContext,
|
|
4
|
+
RequestOptions,
|
|
5
|
+
SseMessage,
|
|
6
|
+
StealthSession,
|
|
7
|
+
StealthRedirectRunResult,
|
|
8
|
+
} from "../types.js";
|
|
9
|
+
import { readableBytes, readableLines, readableTextChunks } from "../stream.js";
|
|
10
|
+
import {
|
|
11
|
+
parseHttpRequestInvocation,
|
|
12
|
+
isSensitiveKey,
|
|
13
|
+
redactSensitiveError,
|
|
14
|
+
redactSensitiveText,
|
|
15
|
+
redactUrlQueryParams,
|
|
16
|
+
requestOptionsFromHttpInvocation,
|
|
17
|
+
serializeRequestUrl,
|
|
18
|
+
type SerializedRequestUrl,
|
|
19
|
+
} from "./request-options.js";
|
|
2
20
|
import {
|
|
3
21
|
type CreateTraceContextOptions,
|
|
4
22
|
createTraceContext,
|
|
5
23
|
getTraceRecorder,
|
|
6
24
|
type TraceContext,
|
|
7
25
|
} from "./trace.js";
|
|
26
|
+
import { RESOLVER_INSTRUMENTATION_METADATA } from "./resolver-shared.js";
|
|
8
27
|
|
|
9
28
|
export interface InstrumentationOptions extends CreateTraceContextOptions {}
|
|
10
29
|
|
|
11
|
-
export type InstrumentedProviderContext<T extends ProviderContext
|
|
30
|
+
export type InstrumentedProviderContext<T extends Pick<ProviderContext, "trace">> = Omit<
|
|
31
|
+
T,
|
|
32
|
+
"trace"
|
|
33
|
+
> & {
|
|
12
34
|
trace: TraceContext;
|
|
13
35
|
};
|
|
14
36
|
|
|
15
|
-
type InstrumentedNamespace = "http" | "stealth" | "browser" | "session" | "state";
|
|
37
|
+
type InstrumentedNamespace = "http" | "stealth" | "browser" | "session" | "state" | "resolver";
|
|
16
38
|
|
|
17
39
|
const BROWSER_PAGE_METHODS = new Set(["goto", "fill", "click", "type", "waitForSelector"]);
|
|
40
|
+
const DIAGNOSTIC_BASE_URL = "http://apifuse-instrumentation.invalid";
|
|
41
|
+
|
|
42
|
+
type RequestDiagnostics = {
|
|
43
|
+
diagnosticUrlDegraded?: boolean;
|
|
44
|
+
requestId?: string;
|
|
45
|
+
serializedUrl?: SerializedRequestUrl;
|
|
46
|
+
sensitiveParamNames: readonly string[];
|
|
47
|
+
sensitiveValues: readonly string[];
|
|
48
|
+
traceUrl?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function isThenable(value: unknown): value is PromiseLike<unknown> {
|
|
52
|
+
return (
|
|
53
|
+
(typeof value === "object" || typeof value === "function") &&
|
|
54
|
+
value !== null &&
|
|
55
|
+
typeof (value as { then?: unknown }).then === "function"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
18
58
|
|
|
19
59
|
function getErrorStatus(error: unknown): number | undefined {
|
|
20
60
|
if (
|
|
@@ -84,12 +124,231 @@ function getUrl(
|
|
|
84
124
|
return undefined;
|
|
85
125
|
}
|
|
86
126
|
|
|
127
|
+
function requestOptionsForInvocation(
|
|
128
|
+
namespace: InstrumentedNamespace,
|
|
129
|
+
methodName: string,
|
|
130
|
+
args: readonly unknown[],
|
|
131
|
+
): RequestOptions | undefined {
|
|
132
|
+
if (namespace === "http") {
|
|
133
|
+
const invocation = parseHttpRequestInvocation(methodName, [...args]);
|
|
134
|
+
return invocation ? requestOptionsFromHttpInvocation(invocation) : undefined;
|
|
135
|
+
}
|
|
136
|
+
if (namespace !== "stealth" || methodName !== "fetch" || typeof args[0] !== "string") {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const options = args[1];
|
|
140
|
+
return options !== null && typeof options === "object" && !Array.isArray(options)
|
|
141
|
+
? (options as RequestOptions)
|
|
142
|
+
: undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function fallbackSensitiveValues(options?: RequestOptions): readonly string[] {
|
|
146
|
+
const sensitiveParams = options?.sensitiveParams;
|
|
147
|
+
if (!sensitiveParams || typeof sensitiveParams !== "object") return [];
|
|
148
|
+
return Object.values(sensitiveParams).map(String);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function stripDiagnosticBase(url: string): string {
|
|
152
|
+
return url.startsWith(DIAGNOSTIC_BASE_URL) ? url.slice(DIAGNOSTIC_BASE_URL.length) || "/" : url;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function serializeDiagnosticUrl(
|
|
156
|
+
url: string,
|
|
157
|
+
options?: RequestOptions,
|
|
158
|
+
): { degraded: boolean; serializedUrl: SerializedRequestUrl } {
|
|
159
|
+
try {
|
|
160
|
+
return {
|
|
161
|
+
degraded: false,
|
|
162
|
+
serializedUrl: serializeRequestUrl(url, options?.params, options?.sensitiveParams),
|
|
163
|
+
};
|
|
164
|
+
} catch {
|
|
165
|
+
try {
|
|
166
|
+
const absoluteUrl = new URL(url, DIAGNOSTIC_BASE_URL).toString();
|
|
167
|
+
const serialized = serializeRequestUrl(
|
|
168
|
+
absoluteUrl,
|
|
169
|
+
options?.params,
|
|
170
|
+
options?.sensitiveParams,
|
|
171
|
+
);
|
|
172
|
+
return {
|
|
173
|
+
degraded: false,
|
|
174
|
+
serializedUrl: {
|
|
175
|
+
requestUrl: stripDiagnosticBase(serialized.requestUrl),
|
|
176
|
+
redactedUrl: stripDiagnosticBase(serialized.redactedUrl),
|
|
177
|
+
sensitiveValues: serialized.sensitiveValues,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
} catch {
|
|
181
|
+
const sensitiveParamNames = Object.keys(options?.sensitiveParams ?? {});
|
|
182
|
+
const structural = redactUrlQueryParams(url, sensitiveParamNames);
|
|
183
|
+
return {
|
|
184
|
+
degraded: true,
|
|
185
|
+
serializedUrl: {
|
|
186
|
+
requestUrl: url,
|
|
187
|
+
redactedUrl: structural.redactedUrl,
|
|
188
|
+
sensitiveValues: [
|
|
189
|
+
...new Set([...fallbackSensitiveValues(options), ...structural.sensitiveValues]),
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function snapshotRequestDiagnostics(
|
|
198
|
+
namespace: InstrumentedNamespace,
|
|
199
|
+
methodName: string,
|
|
200
|
+
args: readonly unknown[],
|
|
201
|
+
): RequestDiagnostics {
|
|
202
|
+
const options = requestOptionsForInvocation(namespace, methodName, args);
|
|
203
|
+
const url = typeof args[0] === "string" ? args[0] : undefined;
|
|
204
|
+
const hasSensitiveParams = Boolean(
|
|
205
|
+
options?.sensitiveParams && Object.keys(options.sensitiveParams).length > 0,
|
|
206
|
+
);
|
|
207
|
+
const sensitiveParamNames = Object.keys(options?.sensitiveParams ?? {});
|
|
208
|
+
const diagnosticUrl =
|
|
209
|
+
hasSensitiveParams && url ? serializeDiagnosticUrl(url, options) : undefined;
|
|
210
|
+
const traceUrl =
|
|
211
|
+
hasSensitiveParams && url
|
|
212
|
+
? serializeDiagnosticUrl(url, { sensitiveParams: options?.sensitiveParams }).serializedUrl
|
|
213
|
+
.redactedUrl
|
|
214
|
+
: undefined;
|
|
215
|
+
return {
|
|
216
|
+
...(diagnosticUrl?.degraded ? { diagnosticUrlDegraded: true } : {}),
|
|
217
|
+
...(hasSensitiveParams ? { requestId: crypto.randomUUID() } : {}),
|
|
218
|
+
serializedUrl: diagnosticUrl?.serializedUrl,
|
|
219
|
+
sensitiveParamNames,
|
|
220
|
+
sensitiveValues:
|
|
221
|
+
diagnosticUrl?.serializedUrl.sensitiveValues ?? fallbackSensitiveValues(options),
|
|
222
|
+
traceUrl,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function sanitizeRequestError(error: unknown, diagnostics: RequestDiagnostics): unknown {
|
|
227
|
+
return redactSensitiveError(
|
|
228
|
+
error,
|
|
229
|
+
diagnostics.sensitiveValues,
|
|
230
|
+
diagnostics.serializedUrl?.requestUrl,
|
|
231
|
+
diagnostics.serializedUrl?.redactedUrl,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function isHttpStreamResponse(value: unknown): value is HttpStreamResponse {
|
|
236
|
+
return (
|
|
237
|
+
typeof value === "object" &&
|
|
238
|
+
value !== null &&
|
|
239
|
+
"body" in value &&
|
|
240
|
+
value.body instanceof ReadableStream
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function instrumentHttpStreamConsumption(
|
|
245
|
+
value: HttpStreamResponse,
|
|
246
|
+
recorder: NonNullable<ReturnType<typeof getTraceRecorder>>,
|
|
247
|
+
args: unknown[],
|
|
248
|
+
diagnostics: RequestDiagnostics,
|
|
249
|
+
): HttpStreamResponse {
|
|
250
|
+
const source = value.body;
|
|
251
|
+
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined;
|
|
252
|
+
const body = new ReadableStream<Uint8Array>(
|
|
253
|
+
{
|
|
254
|
+
async pull(controller) {
|
|
255
|
+
try {
|
|
256
|
+
reader ??= source.getReader();
|
|
257
|
+
const chunk = await reader.read();
|
|
258
|
+
if (chunk.done) {
|
|
259
|
+
controller.close();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
controller.enqueue(chunk.value);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
const sanitizedError = sanitizeRequestError(error, diagnostics);
|
|
265
|
+
try {
|
|
266
|
+
await recorder.runSpan(
|
|
267
|
+
"http.stream.consume",
|
|
268
|
+
() => {
|
|
269
|
+
throw sanitizedError;
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
onError: (spanError) =>
|
|
273
|
+
buildSpanAttributes("http", "stream", args, undefined, spanError, diagnostics),
|
|
274
|
+
},
|
|
275
|
+
);
|
|
276
|
+
} catch (recordedError) {
|
|
277
|
+
controller.error(recordedError);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
async cancel(reason) {
|
|
282
|
+
try {
|
|
283
|
+
await (reader ? reader.cancel(reason) : source.cancel(reason));
|
|
284
|
+
} catch (error) {
|
|
285
|
+
throw sanitizeRequestError(error, diagnostics);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{ highWaterMark: 0 },
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
const instrumented = {
|
|
293
|
+
...value,
|
|
294
|
+
body,
|
|
295
|
+
bytes: () => readableBytes(body),
|
|
296
|
+
textChunks: () => readableTextChunks(body),
|
|
297
|
+
lines: () => readableLines(body),
|
|
298
|
+
} satisfies HttpStreamResponse;
|
|
299
|
+
try {
|
|
300
|
+
Object.assign(value, instrumented);
|
|
301
|
+
return value;
|
|
302
|
+
} catch {
|
|
303
|
+
return instrumented;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function isAsyncIterable<T = unknown>(value: unknown): value is AsyncIterable<T> {
|
|
308
|
+
return (
|
|
309
|
+
typeof value === "object" &&
|
|
310
|
+
value !== null &&
|
|
311
|
+
Symbol.asyncIterator in value &&
|
|
312
|
+
typeof value[Symbol.asyncIterator] === "function"
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function instrumentHttpSseConsumption(
|
|
317
|
+
value: AsyncIterable<SseMessage>,
|
|
318
|
+
recorder: NonNullable<ReturnType<typeof getTraceRecorder>>,
|
|
319
|
+
args: unknown[],
|
|
320
|
+
diagnostics: RequestDiagnostics,
|
|
321
|
+
): AsyncIterable<SseMessage> {
|
|
322
|
+
const source = value;
|
|
323
|
+
return {
|
|
324
|
+
async *[Symbol.asyncIterator]() {
|
|
325
|
+
try {
|
|
326
|
+
for await (const event of source) yield event;
|
|
327
|
+
} catch (error) {
|
|
328
|
+
const sanitizedError = sanitizeRequestError(error, diagnostics);
|
|
329
|
+
return await recorder.runSpan(
|
|
330
|
+
"http.sse.consume",
|
|
331
|
+
() => {
|
|
332
|
+
throw sanitizedError;
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
onError: (spanError) =>
|
|
336
|
+
buildSpanAttributes("http", "sse", args, undefined, spanError, diagnostics),
|
|
337
|
+
},
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
87
344
|
function getMethod(
|
|
88
345
|
namespace: InstrumentedNamespace,
|
|
89
346
|
methodName: string,
|
|
90
347
|
args: unknown[],
|
|
91
348
|
): string | undefined {
|
|
92
349
|
if (namespace === "http") {
|
|
350
|
+
// Preserve the original instrumentation contract: generic entry points are
|
|
351
|
+
// reported as REQUEST/STREAM/SSE, independent of transport options.
|
|
93
352
|
return methodName.toUpperCase();
|
|
94
353
|
}
|
|
95
354
|
|
|
@@ -111,9 +370,19 @@ function buildSpanAttributes(
|
|
|
111
370
|
args: unknown[],
|
|
112
371
|
result?: unknown,
|
|
113
372
|
error?: unknown,
|
|
373
|
+
diagnostics: RequestDiagnostics = { sensitiveParamNames: [], sensitiveValues: [] },
|
|
114
374
|
): Record<string, string | number | boolean> {
|
|
115
375
|
const attributes: Record<string, string | number | boolean> = {};
|
|
116
|
-
const
|
|
376
|
+
const rawUrl = getUrl(namespace, args, result);
|
|
377
|
+
const structuralUrl = diagnostics.traceUrl ?? rawUrl;
|
|
378
|
+
const url = structuralUrl
|
|
379
|
+
? redactSensitiveText(
|
|
380
|
+
structuralUrl,
|
|
381
|
+
diagnostics.sensitiveValues,
|
|
382
|
+
diagnostics.serializedUrl?.requestUrl,
|
|
383
|
+
diagnostics.serializedUrl?.redactedUrl,
|
|
384
|
+
)
|
|
385
|
+
: undefined;
|
|
117
386
|
const method = getMethod(namespace, methodName, args);
|
|
118
387
|
const status = error ? getErrorStatus(error) : getResponseStatus(namespace, result);
|
|
119
388
|
const duration = error ? undefined : getResponseDuration(result);
|
|
@@ -121,6 +390,8 @@ function buildSpanAttributes(
|
|
|
121
390
|
if (url) {
|
|
122
391
|
attributes.url = url;
|
|
123
392
|
}
|
|
393
|
+
if (diagnostics.requestId) attributes.request_id = diagnostics.requestId;
|
|
394
|
+
if (diagnostics.diagnosticUrlDegraded) attributes.redaction_degraded = true;
|
|
124
395
|
|
|
125
396
|
if (method) {
|
|
126
397
|
attributes.method = method;
|
|
@@ -145,6 +416,64 @@ function buildSpanAttributes(
|
|
|
145
416
|
return attributes;
|
|
146
417
|
}
|
|
147
418
|
|
|
419
|
+
function isStealthRedirectRunResult(value: unknown): value is StealthRedirectRunResult {
|
|
420
|
+
return (
|
|
421
|
+
typeof value === "object" &&
|
|
422
|
+
value !== null &&
|
|
423
|
+
"reason" in value &&
|
|
424
|
+
typeof value.reason === "string" &&
|
|
425
|
+
"hops" in value &&
|
|
426
|
+
Array.isArray(value.hops) &&
|
|
427
|
+
"final" in value &&
|
|
428
|
+
typeof value.final === "object" &&
|
|
429
|
+
value.final !== null
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function buildStealthRedirectAttributes(
|
|
434
|
+
args: unknown[],
|
|
435
|
+
result: unknown,
|
|
436
|
+
error: unknown,
|
|
437
|
+
diagnostics: RequestDiagnostics,
|
|
438
|
+
): Record<string, string | number | boolean> {
|
|
439
|
+
const attributes = buildSpanAttributes("stealth", "fetch", args, undefined, error, diagnostics);
|
|
440
|
+
if (!isStealthRedirectRunResult(result)) return attributes;
|
|
441
|
+
|
|
442
|
+
attributes.redirect_reason = result.reason;
|
|
443
|
+
attributes.redirect_hop_count = result.hops.length;
|
|
444
|
+
attributes.status = result.final.status;
|
|
445
|
+
if (result.hops.length > 0) {
|
|
446
|
+
const sensitiveValues = new Set(diagnostics.sensitiveValues);
|
|
447
|
+
const path = result.hops
|
|
448
|
+
.map((hop) => {
|
|
449
|
+
const hopUrl = hop.nextUrl ?? hop.url;
|
|
450
|
+
const responseSensitiveParamNames = [...queryParamNames(hopUrl)].filter(isSensitiveKey);
|
|
451
|
+
const structural = redactUrlQueryParams(hopUrl, [
|
|
452
|
+
...new Set([...diagnostics.sensitiveParamNames, ...responseSensitiveParamNames]),
|
|
453
|
+
]);
|
|
454
|
+
for (const value of structural.sensitiveValues) sensitiveValues.add(value);
|
|
455
|
+
const safeUrl = redactSensitiveText(structural.redactedUrl, [...sensitiveValues]);
|
|
456
|
+
return `${hop.method} ${hop.status} ${safeUrl}`;
|
|
457
|
+
})
|
|
458
|
+
.join(" -> ");
|
|
459
|
+
attributes.redirect_path = redactSensitiveText(
|
|
460
|
+
path,
|
|
461
|
+
[...sensitiveValues],
|
|
462
|
+
diagnostics.serializedUrl?.requestUrl,
|
|
463
|
+
diagnostics.serializedUrl?.redactedUrl,
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
return attributes;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function queryParamNames(url: string): Set<string> {
|
|
470
|
+
const queryStart = url.indexOf("?");
|
|
471
|
+
if (queryStart === -1) return new Set();
|
|
472
|
+
const fragmentStart = url.indexOf("#", queryStart);
|
|
473
|
+
const query = url.slice(queryStart + 1, fragmentStart === -1 ? undefined : fragmentStart);
|
|
474
|
+
return new Set(new URLSearchParams(query).keys());
|
|
475
|
+
}
|
|
476
|
+
|
|
148
477
|
function getBrowserPageAttributes(
|
|
149
478
|
methodName: string,
|
|
150
479
|
args: unknown[],
|
|
@@ -230,10 +559,65 @@ function wrapPage<T extends object>(page: T, trace: TraceContext): T {
|
|
|
230
559
|
});
|
|
231
560
|
}
|
|
232
561
|
|
|
562
|
+
function wrapStealthRedirects(
|
|
563
|
+
redirects: StealthSession["redirects"],
|
|
564
|
+
trace: TraceContext,
|
|
565
|
+
): StealthSession["redirects"] {
|
|
566
|
+
const recorder = getTraceRecorder(trace);
|
|
567
|
+
if (!recorder) return redirects;
|
|
568
|
+
|
|
569
|
+
return {
|
|
570
|
+
run(...args: Parameters<StealthSession["redirects"]["run"]>) {
|
|
571
|
+
const diagnosticArgs = [args[0].url, args[0]];
|
|
572
|
+
const diagnostics = snapshotRequestDiagnostics("stealth", "fetch", diagnosticArgs);
|
|
573
|
+
let result: ReturnType<StealthSession["redirects"]["run"]>;
|
|
574
|
+
try {
|
|
575
|
+
result = redirects.run(...args);
|
|
576
|
+
} catch (error) {
|
|
577
|
+
const sanitizedError = sanitizeRequestError(error, diagnostics);
|
|
578
|
+
recorder
|
|
579
|
+
.runSpan(
|
|
580
|
+
"stealth.redirects.run",
|
|
581
|
+
() => {
|
|
582
|
+
throw sanitizedError;
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
onError: (spanError) =>
|
|
586
|
+
buildStealthRedirectAttributes(diagnosticArgs, undefined, spanError, diagnostics),
|
|
587
|
+
},
|
|
588
|
+
)
|
|
589
|
+
.catch(() => undefined);
|
|
590
|
+
throw sanitizedError;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const sanitizedResult = Promise.resolve(result).catch((error: unknown) => {
|
|
594
|
+
throw sanitizeRequestError(error, diagnostics);
|
|
595
|
+
});
|
|
596
|
+
return recorder.runSpan("stealth.redirects.run", () => sanitizedResult, {
|
|
597
|
+
onSuccess: (spanResult) =>
|
|
598
|
+
buildStealthRedirectAttributes(diagnosticArgs, spanResult, undefined, diagnostics),
|
|
599
|
+
onError: (error) =>
|
|
600
|
+
buildStealthRedirectAttributes(diagnosticArgs, undefined, error, diagnostics),
|
|
601
|
+
});
|
|
602
|
+
},
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function wrapStealthSession(session: StealthSession, trace: TraceContext): StealthSession {
|
|
607
|
+
const wrappedSession = wrapNamespace("stealth", session, trace);
|
|
608
|
+
const redirects = wrapStealthRedirects(session.redirects, trace);
|
|
609
|
+
return new Proxy(wrappedSession, {
|
|
610
|
+
get(target, property, receiver) {
|
|
611
|
+
return property === "redirects" ? redirects : Reflect.get(target, property, receiver);
|
|
612
|
+
},
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
|
|
233
616
|
function wrapNamespace<T extends object>(
|
|
234
617
|
namespace: InstrumentedNamespace,
|
|
235
618
|
target: T,
|
|
236
619
|
trace: TraceContext,
|
|
620
|
+
shouldInstrument?: (methodName: string, args: unknown[]) => boolean,
|
|
237
621
|
): T {
|
|
238
622
|
const recorder = getTraceRecorder(trace);
|
|
239
623
|
if (!recorder) {
|
|
@@ -241,15 +625,47 @@ function wrapNamespace<T extends object>(
|
|
|
241
625
|
}
|
|
242
626
|
|
|
243
627
|
const wrappedMethods = new Map<PropertyKey, unknown>();
|
|
628
|
+
const resolverMetadata =
|
|
629
|
+
namespace === "resolver" ? { target, traceRecorder: recorder } : undefined;
|
|
244
630
|
|
|
245
631
|
return new Proxy(target, {
|
|
246
632
|
get(namespaceTarget, property, receiver) {
|
|
633
|
+
if (property === RESOLVER_INSTRUMENTATION_METADATA && resolverMetadata) {
|
|
634
|
+
return resolverMetadata;
|
|
635
|
+
}
|
|
247
636
|
const value = Reflect.get(namespaceTarget, property, receiver);
|
|
248
637
|
|
|
249
638
|
if (typeof value !== "function" || property === "constructor") {
|
|
250
639
|
return value;
|
|
251
640
|
}
|
|
252
641
|
|
|
642
|
+
if (namespace === "resolver" && property === "solve") {
|
|
643
|
+
if (wrappedMethods.has(property)) {
|
|
644
|
+
return wrappedMethods.get(property);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const wrapped = (...args: unknown[]) => {
|
|
648
|
+
const challenge = args[0];
|
|
649
|
+
const challengeKind =
|
|
650
|
+
typeof challenge === "object" &&
|
|
651
|
+
challenge !== null &&
|
|
652
|
+
"kind" in challenge &&
|
|
653
|
+
typeof challenge.kind === "string"
|
|
654
|
+
? challenge.kind
|
|
655
|
+
: undefined;
|
|
656
|
+
return recorder.runSpan(
|
|
657
|
+
"resolver.solve",
|
|
658
|
+
() => Reflect.apply(value, namespaceTarget, [args[0], args[1], recorder]),
|
|
659
|
+
{
|
|
660
|
+
attributes: challengeKind ? { challenge_kind: challengeKind } : undefined,
|
|
661
|
+
},
|
|
662
|
+
);
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
wrappedMethods.set(property, wrapped);
|
|
666
|
+
return wrapped;
|
|
667
|
+
}
|
|
668
|
+
|
|
253
669
|
if (namespace === "browser" && property === "newPage") {
|
|
254
670
|
if (wrappedMethods.has(property)) {
|
|
255
671
|
return wrappedMethods.get(property);
|
|
@@ -329,15 +745,103 @@ function wrapNamespace<T extends object>(
|
|
|
329
745
|
return wrapped;
|
|
330
746
|
}
|
|
331
747
|
|
|
332
|
-
const wrapped = (...args: unknown[]) =>
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
)
|
|
748
|
+
const wrapped = (...args: unknown[]) => {
|
|
749
|
+
if (shouldInstrument && !shouldInstrument(methodName, args)) {
|
|
750
|
+
return Reflect.apply(value, namespaceTarget, args);
|
|
751
|
+
}
|
|
752
|
+
const requestDiagnostics = snapshotRequestDiagnostics(namespace, methodName, args);
|
|
753
|
+
// Invoke first and decide by the RETURN VALUE. `runSpan` always
|
|
754
|
+
// returns a Promise, so unconditionally span-wrapping every member
|
|
755
|
+
// silently rewrote synchronous contracts: `ctx.state.namespace()`
|
|
756
|
+
// (a sync factory) came back as a Promise, and every method call on
|
|
757
|
+
// it threw a raw TypeError — surfaced in production as catchtable's
|
|
758
|
+
// deterministic CONFIRM_STATE_UNAVAILABLE on 2026-07-27 (and the
|
|
759
|
+
// 2026-07-22 reserve internal_error loop before it). Sync members
|
|
760
|
+
// keep their sync contract; only genuinely async operations are
|
|
761
|
+
// recorded as spans.
|
|
762
|
+
let result: unknown;
|
|
763
|
+
try {
|
|
764
|
+
result = Reflect.apply(value, namespaceTarget, args);
|
|
765
|
+
} catch (error) {
|
|
766
|
+
const sanitizedError = sanitizeRequestError(error, requestDiagnostics);
|
|
767
|
+
// A promise-returning implementation may still throw
|
|
768
|
+
// SYNCHRONOUSLY during pre-flight validation. Preserve the
|
|
769
|
+
// synchronous throw contract, but keep recording the failure
|
|
770
|
+
// span (the pre-fidelity wrapper captured these).
|
|
771
|
+
recorder
|
|
772
|
+
.runSpan(
|
|
773
|
+
`${namespace}.${methodName}`,
|
|
774
|
+
() => {
|
|
775
|
+
throw sanitizedError;
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
onError: (spanError) =>
|
|
779
|
+
buildSpanAttributes(
|
|
780
|
+
namespace,
|
|
781
|
+
methodName,
|
|
782
|
+
args,
|
|
783
|
+
undefined,
|
|
784
|
+
spanError,
|
|
785
|
+
requestDiagnostics,
|
|
786
|
+
),
|
|
787
|
+
},
|
|
788
|
+
)
|
|
789
|
+
.catch(() => undefined);
|
|
790
|
+
throw sanitizedError;
|
|
791
|
+
}
|
|
792
|
+
if (!isThenable(result)) {
|
|
793
|
+
// The state namespace factory returns the object whose METHODS
|
|
794
|
+
// are the operations worth tracing — instrument that object so
|
|
795
|
+
// `state.get`/`state.compareAndSet`/… spans exist (they never
|
|
796
|
+
// could before: the factory's return value was destroyed).
|
|
797
|
+
if (
|
|
798
|
+
namespace === "state" &&
|
|
799
|
+
methodName === "namespace" &&
|
|
800
|
+
typeof result === "object" &&
|
|
801
|
+
result !== null
|
|
802
|
+
) {
|
|
803
|
+
return wrapNamespace(namespace, result, trace);
|
|
804
|
+
}
|
|
805
|
+
if (
|
|
806
|
+
namespace === "stealth" &&
|
|
807
|
+
methodName === "createSession" &&
|
|
808
|
+
typeof result === "object" &&
|
|
809
|
+
result !== null
|
|
810
|
+
) {
|
|
811
|
+
return wrapStealthSession(result as StealthSession, trace);
|
|
812
|
+
}
|
|
813
|
+
return result;
|
|
814
|
+
}
|
|
815
|
+
const sanitizedResult = Promise.resolve(result).catch((error: unknown) => {
|
|
816
|
+
throw sanitizeRequestError(error, requestDiagnostics);
|
|
817
|
+
});
|
|
818
|
+
const tracedResult = recorder.runSpan(`${namespace}.${methodName}`, () => sanitizedResult, {
|
|
819
|
+
onSuccess: (spanResult) =>
|
|
820
|
+
buildSpanAttributes(
|
|
821
|
+
namespace,
|
|
822
|
+
methodName,
|
|
823
|
+
args,
|
|
824
|
+
spanResult,
|
|
825
|
+
undefined,
|
|
826
|
+
requestDiagnostics,
|
|
827
|
+
),
|
|
828
|
+
onError: (error) =>
|
|
829
|
+
buildSpanAttributes(namespace, methodName, args, undefined, error, requestDiagnostics),
|
|
830
|
+
});
|
|
831
|
+
return namespace === "http" && methodName === "stream"
|
|
832
|
+
? tracedResult.then((spanResult) =>
|
|
833
|
+
isHttpStreamResponse(spanResult)
|
|
834
|
+
? instrumentHttpStreamConsumption(spanResult, recorder, args, requestDiagnostics)
|
|
835
|
+
: spanResult,
|
|
836
|
+
)
|
|
837
|
+
: namespace === "http" && methodName === "sse"
|
|
838
|
+
? tracedResult.then((spanResult) =>
|
|
839
|
+
isAsyncIterable<SseMessage>(spanResult)
|
|
840
|
+
? instrumentHttpSseConsumption(spanResult, recorder, args, requestDiagnostics)
|
|
841
|
+
: spanResult,
|
|
842
|
+
)
|
|
843
|
+
: tracedResult;
|
|
844
|
+
};
|
|
341
845
|
|
|
342
846
|
wrappedMethods.set(property, wrapped);
|
|
343
847
|
return wrapped;
|
|
@@ -349,7 +853,7 @@ function hasTraceOverrides(options: InstrumentationOptions): boolean {
|
|
|
349
853
|
return options.maxSpans !== undefined || options.onSpan !== undefined;
|
|
350
854
|
}
|
|
351
855
|
|
|
352
|
-
export function wrapWithInstrumentation<T extends ProviderContext
|
|
856
|
+
export function wrapWithInstrumentation<T extends Pick<ProviderContext, "trace">>(
|
|
353
857
|
ctx: T,
|
|
354
858
|
options: InstrumentationOptions = {},
|
|
355
859
|
): InstrumentedProviderContext<T> {
|
|
@@ -370,7 +874,8 @@ export function wrapWithInstrumentation<T extends ProviderContext>(
|
|
|
370
874
|
property === "stealth" ||
|
|
371
875
|
property === "browser" ||
|
|
372
876
|
property === "session" ||
|
|
373
|
-
property === "state"
|
|
877
|
+
property === "state" ||
|
|
878
|
+
property === "resolver"
|
|
374
879
|
) {
|
|
375
880
|
const namespace = property;
|
|
376
881
|
if (wrappedTargets.has(namespace)) {
|