@apifuse/provider-sdk 2.2.0-beta.38 → 2.2.0-beta.39
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/CHANGELOG.md +4 -0
- package/dist/declaration-validation.d.ts +7 -0
- package/dist/declaration-validation.js +22 -0
- package/dist/define.d.ts +2 -2
- package/dist/define.js +32 -22
- package/dist/index.d.ts +2 -1
- package/dist/runtime/executor.d.ts +2 -2
- package/dist/runtime/executor.js +3 -1
- package/dist/runtime/instrumentation.d.ts +2 -2
- package/dist/runtime/proxy-telemetry.d.ts +41 -1
- package/dist/runtime/proxy-telemetry.js +59 -56
- package/dist/server/index.d.ts +2 -0
- package/dist/server/serve-implementation.d.ts +2 -0
- package/dist/server/serve-implementation.js +81 -30
- package/package.json +1 -1
- package/src/declaration-validation.ts +41 -4
- package/src/define.ts +52 -38
- package/src/index.ts +4 -0
- package/src/runtime/executor.ts +11 -6
- package/src/runtime/instrumentation.ts +5 -2
- package/src/runtime/proxy-telemetry.ts +100 -99
- package/src/server/index.ts +8 -0
- package/src/server/serve-implementation.ts +90 -8
|
@@ -12,51 +12,49 @@ import type {
|
|
|
12
12
|
|
|
13
13
|
export const PROVIDER_TELEMETRY_HEADER = "X-ApiFuse-Provider-Telemetry";
|
|
14
14
|
|
|
15
|
-
type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
15
|
+
export type ProxyTelemetryLogPayload = {
|
|
16
|
+
provider: ProxyVendorName;
|
|
17
|
+
userAgentSource?: ProxyUserAgentSource;
|
|
18
|
+
protocol?: ProxyProtocol;
|
|
19
|
+
cacheStatus: ProxyCacheStatus;
|
|
20
|
+
cacheHit: boolean;
|
|
21
|
+
resolutionMs: number;
|
|
22
|
+
allocatorMs?: number;
|
|
23
|
+
allocatorStatus?: number;
|
|
24
|
+
allocatorBodyClass?: SmartproxyAllocatorBodyClass;
|
|
25
|
+
allocatorAttempts?: number;
|
|
26
|
+
lockWaitMs?: number;
|
|
27
|
+
redisReadMs?: number;
|
|
28
|
+
redisWriteMs?: number;
|
|
29
|
+
poolAgeMs?: number;
|
|
30
|
+
poolExpiresInMs?: number;
|
|
31
|
+
attempts: number;
|
|
32
|
+
refreshes?: number;
|
|
33
|
+
attemptSamples?: {
|
|
34
|
+
n: number;
|
|
35
|
+
a: number;
|
|
36
|
+
i?: number;
|
|
37
|
+
h?: string;
|
|
38
|
+
o: ProxyAttemptTelemetryEvent["outcome"];
|
|
39
|
+
c?: string;
|
|
40
|
+
s?: number;
|
|
41
|
+
d?: number;
|
|
42
|
+
}[];
|
|
43
|
+
/** Distinct vendors attempted across the resolution chain, in order seen. */
|
|
44
|
+
vendors?: ProxyVendorName[];
|
|
45
|
+
/** Cross-vendor failover events (bounded). */
|
|
46
|
+
failovers?: {
|
|
47
|
+
v: ProxyVendorName;
|
|
48
|
+
nx?: ProxyVendorName;
|
|
49
|
+
p: ProxyVendorFailoverTelemetryEvent["phase"];
|
|
50
|
+
r: ProxyVendorFailoverTelemetryEvent["reason"];
|
|
51
|
+
a?: number;
|
|
52
|
+
}[];
|
|
41
53
|
};
|
|
42
54
|
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
i?: number;
|
|
47
|
-
h?: string;
|
|
48
|
-
o: "ok" | "error";
|
|
49
|
-
c?: string;
|
|
50
|
-
s?: number;
|
|
51
|
-
d?: number;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type CompactVendorFailoverSample = {
|
|
55
|
-
v: ProxyVendorName;
|
|
56
|
-
nx?: ProxyVendorName;
|
|
57
|
-
p: "resolution" | "transport";
|
|
58
|
-
r: ProxyVendorFailoverTelemetryEvent["reason"];
|
|
59
|
-
a?: number;
|
|
55
|
+
type ProviderTelemetryHeader = {
|
|
56
|
+
v: 1;
|
|
57
|
+
proxy?: ProxyTelemetryLogPayload;
|
|
60
58
|
};
|
|
61
59
|
|
|
62
60
|
const MAX_HEADER_BYTES = 4_096;
|
|
@@ -163,7 +161,7 @@ export class ProxyTelemetryCollector implements ProxyTelemetrySink {
|
|
|
163
161
|
});
|
|
164
162
|
}
|
|
165
163
|
|
|
166
|
-
|
|
164
|
+
toLogPayload(): ProxyTelemetryLogPayload | undefined {
|
|
167
165
|
const [first, ...rest] = this.#events;
|
|
168
166
|
if (!first) return undefined;
|
|
169
167
|
|
|
@@ -196,62 +194,65 @@ export class ProxyTelemetryCollector implements ProxyTelemetrySink {
|
|
|
196
194
|
}),
|
|
197
195
|
first,
|
|
198
196
|
);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
: {}),
|
|
253
|
-
},
|
|
197
|
+
return {
|
|
198
|
+
provider: serving.provider,
|
|
199
|
+
...(aggregate.userAgentSource ? { userAgentSource: aggregate.userAgentSource } : {}),
|
|
200
|
+
...(serving.protocol ? { protocol: serving.protocol } : {}),
|
|
201
|
+
cacheStatus: aggregate.cacheStatus,
|
|
202
|
+
cacheHit: aggregate.cacheHit,
|
|
203
|
+
resolutionMs: aggregate.resolutionMs,
|
|
204
|
+
...(aggregate.allocatorMs !== undefined ? { allocatorMs: aggregate.allocatorMs } : {}),
|
|
205
|
+
...(aggregate.allocatorStatus !== undefined
|
|
206
|
+
? { allocatorStatus: aggregate.allocatorStatus }
|
|
207
|
+
: {}),
|
|
208
|
+
...(aggregate.allocatorBodyClass !== undefined
|
|
209
|
+
? { allocatorBodyClass: aggregate.allocatorBodyClass }
|
|
210
|
+
: {}),
|
|
211
|
+
...(aggregate.allocatorAttempts !== undefined
|
|
212
|
+
? { allocatorAttempts: aggregate.allocatorAttempts }
|
|
213
|
+
: {}),
|
|
214
|
+
...(aggregate.lockWaitMs !== undefined ? { lockWaitMs: aggregate.lockWaitMs } : {}),
|
|
215
|
+
...(aggregate.redisReadMs !== undefined ? { redisReadMs: aggregate.redisReadMs } : {}),
|
|
216
|
+
...(aggregate.redisWriteMs !== undefined ? { redisWriteMs: aggregate.redisWriteMs } : {}),
|
|
217
|
+
...(aggregate.poolAgeMs !== undefined ? { poolAgeMs: aggregate.poolAgeMs } : {}),
|
|
218
|
+
...(aggregate.poolExpiresInMs !== undefined
|
|
219
|
+
? { poolExpiresInMs: aggregate.poolExpiresInMs }
|
|
220
|
+
: {}),
|
|
221
|
+
attempts: aggregate.attempts,
|
|
222
|
+
...(aggregate.refreshes !== undefined ? { refreshes: aggregate.refreshes } : {}),
|
|
223
|
+
...(this.#attempts.length > 0
|
|
224
|
+
? {
|
|
225
|
+
attemptSamples: this.#attempts.map((attempt, index) => ({
|
|
226
|
+
n: index + 1,
|
|
227
|
+
a: attempt.attempt,
|
|
228
|
+
...(attempt.poolIndex === undefined ? {} : { i: attempt.poolIndex }),
|
|
229
|
+
...(attempt.proxyHash ? { h: attempt.proxyHash } : {}),
|
|
230
|
+
o: attempt.outcome,
|
|
231
|
+
...(attempt.errorCode ? { c: attempt.errorCode } : {}),
|
|
232
|
+
...(attempt.status === undefined ? {} : { s: attempt.status }),
|
|
233
|
+
...(attempt.durationMs === undefined ? {} : { d: attempt.durationMs }),
|
|
234
|
+
})),
|
|
235
|
+
}
|
|
236
|
+
: {}),
|
|
237
|
+
...(vendors.length > 1 ? { vendors } : {}),
|
|
238
|
+
...(this.#failovers.length > 0
|
|
239
|
+
? {
|
|
240
|
+
failovers: this.#failovers.map((failover) => ({
|
|
241
|
+
v: failover.vendor,
|
|
242
|
+
...(failover.nextVendor ? { nx: failover.nextVendor } : {}),
|
|
243
|
+
p: failover.phase,
|
|
244
|
+
r: failover.reason,
|
|
245
|
+
...(failover.attempt === undefined ? {} : { a: failover.attempt }),
|
|
246
|
+
})),
|
|
247
|
+
}
|
|
248
|
+
: {}),
|
|
254
249
|
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
toHeaderValue(): string | undefined {
|
|
253
|
+
const proxy = this.toLogPayload();
|
|
254
|
+
if (!proxy) return undefined;
|
|
255
|
+
const payload: ProviderTelemetryHeader = { v: 1, proxy };
|
|
255
256
|
|
|
256
257
|
const encoded = encodeBase64Url(JSON.stringify(payload));
|
|
257
258
|
if (encoded.length > MAX_HEADER_BYTES) return undefined;
|
package/src/server/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
ProxyCacheStatus,
|
|
3
|
+
ProxyProtocol,
|
|
4
|
+
ProxyUserAgentSource,
|
|
5
|
+
ProxyVendorName,
|
|
6
|
+
SmartproxyAllocatorBodyClass,
|
|
7
|
+
} from "../config/loader.js";
|
|
8
|
+
export type { ProxyTelemetryLogPayload } from "../runtime/proxy-telemetry.js";
|
|
1
9
|
export {
|
|
2
10
|
createServerApp,
|
|
3
11
|
createServerAppAsync,
|
|
@@ -54,7 +54,11 @@ import {
|
|
|
54
54
|
PROXY_EDGE_AUTH_REJECTED_CODE,
|
|
55
55
|
PROXY_POOL_EXHAUSTED_CODE,
|
|
56
56
|
} from "../runtime/proxy-errors.js";
|
|
57
|
-
import {
|
|
57
|
+
import {
|
|
58
|
+
PROVIDER_TELEMETRY_HEADER,
|
|
59
|
+
ProxyTelemetryCollector,
|
|
60
|
+
type ProxyTelemetryLogPayload,
|
|
61
|
+
} from "../runtime/proxy-telemetry.js";
|
|
58
62
|
import type * as ResolverRuntimeModule from "../runtime/resolver.js";
|
|
59
63
|
import { createUnsupportedResolverClient } from "../runtime/resolver-shared.js";
|
|
60
64
|
import {
|
|
@@ -579,7 +583,9 @@ function resolveOperationConnectionId(
|
|
|
579
583
|
// absent so it can never override a valid id or key a real scope. Requests
|
|
580
584
|
// without any usable id fall back to the documented missing-connection
|
|
581
585
|
// sentinel scope instead of scoping context/affinity/state under "".
|
|
582
|
-
return
|
|
586
|
+
return (
|
|
587
|
+
normalizeConnectionId(request.connection?.id) ?? normalizeConnectionId(request.connectionId)
|
|
588
|
+
);
|
|
583
589
|
}
|
|
584
590
|
|
|
585
591
|
function normalizeConnectionId(id: string | undefined): string | undefined {
|
|
@@ -808,6 +814,7 @@ function createAuthFlowContext(
|
|
|
808
814
|
request: AuthFlowRequest,
|
|
809
815
|
options: ProviderServerRuntimeOptions,
|
|
810
816
|
state: ProviderRuntimeState,
|
|
817
|
+
proxyTelemetry?: ProxyTelemetryCollector,
|
|
811
818
|
signal?: AbortSignal,
|
|
812
819
|
): {
|
|
813
820
|
context: FlowContext;
|
|
@@ -825,6 +832,7 @@ function createAuthFlowContext(
|
|
|
825
832
|
const proxyClientOptions = {
|
|
826
833
|
upstream: { proxy: provider.proxy },
|
|
827
834
|
affinityKey: resolveAuthFlowProxyAffinityKey(provider, request),
|
|
835
|
+
telemetry: proxyTelemetry,
|
|
828
836
|
};
|
|
829
837
|
const resolverIdentityScope = resolveProviderResolverIdentityScope(
|
|
830
838
|
provider,
|
|
@@ -834,6 +842,7 @@ function createAuthFlowContext(
|
|
|
834
842
|
const stealthClientOptions = {
|
|
835
843
|
upstream: proxyClientOptions.upstream,
|
|
836
844
|
affinityKey: proxyClientOptions.affinityKey,
|
|
845
|
+
telemetry: proxyTelemetry,
|
|
837
846
|
};
|
|
838
847
|
const { capabilityModules } = options;
|
|
839
848
|
const logStealthCleanupError = (error: unknown) =>
|
|
@@ -951,6 +960,7 @@ type ProviderServerLogEventBase = ProviderRequestCost & {
|
|
|
951
960
|
route: string;
|
|
952
961
|
requestId?: string;
|
|
953
962
|
status: number;
|
|
963
|
+
proxy?: ProxyTelemetryLogPayload;
|
|
954
964
|
};
|
|
955
965
|
|
|
956
966
|
export type ProviderServerLogEvent =
|
|
@@ -1487,6 +1497,7 @@ function logProviderError(
|
|
|
1487
1497
|
status: number,
|
|
1488
1498
|
cost: ProviderRequestCost,
|
|
1489
1499
|
declaredErrorCode?: OperationErrorCode,
|
|
1500
|
+
proxyTelemetry?: ProxyTelemetryCollector,
|
|
1490
1501
|
): void {
|
|
1491
1502
|
const code = isProviderError(error)
|
|
1492
1503
|
? (error.code ?? "provider_error")
|
|
@@ -1506,6 +1517,7 @@ function logProviderError(
|
|
|
1506
1517
|
typeof error.code === "string" &&
|
|
1507
1518
|
!SDK_OWNED_PROVIDER_ERROR_CODES.has(error.code) &&
|
|
1508
1519
|
declaredErrorCode === undefined;
|
|
1520
|
+
const proxy = proxyTelemetry?.toLogPayload();
|
|
1509
1521
|
const emit = typeof logger === "function" ? logger : defaultProviderServerLogger;
|
|
1510
1522
|
emit({
|
|
1511
1523
|
level: status >= 500 ? "error" : "warn",
|
|
@@ -1516,6 +1528,7 @@ function logProviderError(
|
|
|
1516
1528
|
...(requestId ? { requestId } : {}),
|
|
1517
1529
|
status,
|
|
1518
1530
|
...cost,
|
|
1531
|
+
...(proxy ? { proxy } : {}),
|
|
1519
1532
|
code,
|
|
1520
1533
|
errorClass,
|
|
1521
1534
|
message,
|
|
@@ -1568,7 +1581,9 @@ function logProviderSuccess(
|
|
|
1568
1581
|
requestId: string | undefined,
|
|
1569
1582
|
status: number,
|
|
1570
1583
|
cost: ProviderRequestCost,
|
|
1584
|
+
proxyTelemetry?: ProxyTelemetryCollector,
|
|
1571
1585
|
): void {
|
|
1586
|
+
const proxy = proxyTelemetry?.toLogPayload();
|
|
1572
1587
|
const emit = typeof logger === "function" ? logger : defaultProviderServerLogger;
|
|
1573
1588
|
emit({
|
|
1574
1589
|
level: "info",
|
|
@@ -1579,6 +1594,7 @@ function logProviderSuccess(
|
|
|
1579
1594
|
...(requestId ? { requestId } : {}),
|
|
1580
1595
|
status,
|
|
1581
1596
|
...cost,
|
|
1597
|
+
...(proxy ? { proxy } : {}),
|
|
1582
1598
|
});
|
|
1583
1599
|
}
|
|
1584
1600
|
|
|
@@ -2067,6 +2083,7 @@ async function handleAuthFlow(
|
|
|
2067
2083
|
route: AuthRoute,
|
|
2068
2084
|
options: ProviderServerRuntimeOptions,
|
|
2069
2085
|
state: ProviderRuntimeState,
|
|
2086
|
+
proxyTelemetry?: ProxyTelemetryCollector,
|
|
2070
2087
|
signal?: AbortSignal,
|
|
2071
2088
|
): Promise<Response | AuthFlowResponse> {
|
|
2072
2089
|
const flow = provider.auth?.flow;
|
|
@@ -2081,7 +2098,14 @@ async function handleAuthFlow(
|
|
|
2081
2098
|
// any flow code runs instead of at whatever point the ceremony first reads
|
|
2082
2099
|
// the env. `abort` stays exempt: a user must always be able to cancel a
|
|
2083
2100
|
// stranded flow even when provisioning is broken.
|
|
2084
|
-
const { context, getPatch } = createAuthFlowContext(
|
|
2101
|
+
const { context, getPatch } = createAuthFlowContext(
|
|
2102
|
+
provider,
|
|
2103
|
+
request,
|
|
2104
|
+
options,
|
|
2105
|
+
state,
|
|
2106
|
+
proxyTelemetry,
|
|
2107
|
+
signal,
|
|
2108
|
+
);
|
|
2085
2109
|
try {
|
|
2086
2110
|
if (route !== "abort") {
|
|
2087
2111
|
assertRequiredSecretsPresent(provider, context.env);
|
|
@@ -2553,6 +2577,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2553
2577
|
body.requestId,
|
|
2554
2578
|
response.status,
|
|
2555
2579
|
finishRequestCost(requestCost),
|
|
2580
|
+
proxyTelemetry,
|
|
2556
2581
|
);
|
|
2557
2582
|
return responseWithProviderTelemetry(response, proxyTelemetry);
|
|
2558
2583
|
}
|
|
@@ -2566,6 +2591,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2566
2591
|
body.requestId,
|
|
2567
2592
|
200,
|
|
2568
2593
|
finishRequestCost(requestCost),
|
|
2594
|
+
proxyTelemetry,
|
|
2569
2595
|
);
|
|
2570
2596
|
return c.json(response);
|
|
2571
2597
|
} catch (error) {
|
|
@@ -2582,6 +2608,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2582
2608
|
status,
|
|
2583
2609
|
finishRequestCost(requestCost),
|
|
2584
2610
|
declaredErrorCode,
|
|
2611
|
+
proxyTelemetry,
|
|
2585
2612
|
);
|
|
2586
2613
|
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2587
2614
|
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
@@ -2595,6 +2622,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2595
2622
|
|
|
2596
2623
|
app.post("/auth/start", async (c) => {
|
|
2597
2624
|
let rawBody: unknown;
|
|
2625
|
+
const proxyTelemetry = new ProxyTelemetryCollector();
|
|
2598
2626
|
const requestCost = startRequestCost();
|
|
2599
2627
|
try {
|
|
2600
2628
|
rawBody = await c.req.raw
|
|
@@ -2608,6 +2636,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2608
2636
|
"start",
|
|
2609
2637
|
options,
|
|
2610
2638
|
state,
|
|
2639
|
+
proxyTelemetry,
|
|
2611
2640
|
c.req.raw.signal,
|
|
2612
2641
|
);
|
|
2613
2642
|
logProviderSuccess(
|
|
@@ -2618,8 +2647,13 @@ function createServerAppWithCapabilityModules(
|
|
|
2618
2647
|
body.requestId,
|
|
2619
2648
|
response instanceof Response ? response.status : 200,
|
|
2620
2649
|
finishRequestCost(requestCost),
|
|
2650
|
+
proxyTelemetry,
|
|
2621
2651
|
);
|
|
2622
|
-
|
|
2652
|
+
if (response instanceof Response)
|
|
2653
|
+
return responseWithProviderTelemetry(response, proxyTelemetry);
|
|
2654
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2655
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2656
|
+
return c.json(response);
|
|
2623
2657
|
} catch (error) {
|
|
2624
2658
|
const status = toStatusCode(error);
|
|
2625
2659
|
const requestId = extractRequestId(rawBody);
|
|
@@ -2632,7 +2666,11 @@ function createServerAppWithCapabilityModules(
|
|
|
2632
2666
|
error,
|
|
2633
2667
|
status,
|
|
2634
2668
|
finishRequestCost(requestCost),
|
|
2669
|
+
undefined,
|
|
2670
|
+
proxyTelemetry,
|
|
2635
2671
|
);
|
|
2672
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2673
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2636
2674
|
return responseWithErrorObservability(
|
|
2637
2675
|
c.json(toErrorResponse(error, requestId), status),
|
|
2638
2676
|
error,
|
|
@@ -2642,6 +2680,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2642
2680
|
|
|
2643
2681
|
app.post("/auth/continue", async (c) => {
|
|
2644
2682
|
let rawBody: unknown;
|
|
2683
|
+
const proxyTelemetry = new ProxyTelemetryCollector();
|
|
2645
2684
|
const requestCost = startRequestCost();
|
|
2646
2685
|
try {
|
|
2647
2686
|
rawBody = await c.req.raw
|
|
@@ -2655,6 +2694,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2655
2694
|
"continue",
|
|
2656
2695
|
options,
|
|
2657
2696
|
state,
|
|
2697
|
+
proxyTelemetry,
|
|
2658
2698
|
c.req.raw.signal,
|
|
2659
2699
|
);
|
|
2660
2700
|
logProviderSuccess(
|
|
@@ -2665,8 +2705,13 @@ function createServerAppWithCapabilityModules(
|
|
|
2665
2705
|
body.requestId,
|
|
2666
2706
|
response instanceof Response ? response.status : 200,
|
|
2667
2707
|
finishRequestCost(requestCost),
|
|
2708
|
+
proxyTelemetry,
|
|
2668
2709
|
);
|
|
2669
|
-
|
|
2710
|
+
if (response instanceof Response)
|
|
2711
|
+
return responseWithProviderTelemetry(response, proxyTelemetry);
|
|
2712
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2713
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2714
|
+
return c.json(response);
|
|
2670
2715
|
} catch (error) {
|
|
2671
2716
|
const status = toStatusCode(error);
|
|
2672
2717
|
const requestId = extractRequestId(rawBody);
|
|
@@ -2679,7 +2724,11 @@ function createServerAppWithCapabilityModules(
|
|
|
2679
2724
|
error,
|
|
2680
2725
|
status,
|
|
2681
2726
|
finishRequestCost(requestCost),
|
|
2727
|
+
undefined,
|
|
2728
|
+
proxyTelemetry,
|
|
2682
2729
|
);
|
|
2730
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2731
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2683
2732
|
return responseWithErrorObservability(
|
|
2684
2733
|
c.json(toErrorResponse(error, requestId), status),
|
|
2685
2734
|
error,
|
|
@@ -2689,6 +2738,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2689
2738
|
|
|
2690
2739
|
app.post("/auth/poll", async (c) => {
|
|
2691
2740
|
let rawBody: unknown;
|
|
2741
|
+
const proxyTelemetry = new ProxyTelemetryCollector();
|
|
2692
2742
|
const requestCost = startRequestCost();
|
|
2693
2743
|
try {
|
|
2694
2744
|
rawBody = await c.req.raw
|
|
@@ -2702,6 +2752,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2702
2752
|
"poll",
|
|
2703
2753
|
options,
|
|
2704
2754
|
state,
|
|
2755
|
+
proxyTelemetry,
|
|
2705
2756
|
c.req.raw.signal,
|
|
2706
2757
|
);
|
|
2707
2758
|
logProviderSuccess(
|
|
@@ -2712,8 +2763,13 @@ function createServerAppWithCapabilityModules(
|
|
|
2712
2763
|
body.requestId,
|
|
2713
2764
|
response instanceof Response ? response.status : 200,
|
|
2714
2765
|
finishRequestCost(requestCost),
|
|
2766
|
+
proxyTelemetry,
|
|
2715
2767
|
);
|
|
2716
|
-
|
|
2768
|
+
if (response instanceof Response)
|
|
2769
|
+
return responseWithProviderTelemetry(response, proxyTelemetry);
|
|
2770
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2771
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2772
|
+
return c.json(response);
|
|
2717
2773
|
} catch (error) {
|
|
2718
2774
|
const status = toStatusCode(error);
|
|
2719
2775
|
const requestId = extractRequestId(rawBody);
|
|
@@ -2726,7 +2782,11 @@ function createServerAppWithCapabilityModules(
|
|
|
2726
2782
|
error,
|
|
2727
2783
|
status,
|
|
2728
2784
|
finishRequestCost(requestCost),
|
|
2785
|
+
undefined,
|
|
2786
|
+
proxyTelemetry,
|
|
2729
2787
|
);
|
|
2788
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2789
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2730
2790
|
return responseWithErrorObservability(
|
|
2731
2791
|
c.json(toErrorResponse(error, requestId), status),
|
|
2732
2792
|
error,
|
|
@@ -2736,6 +2796,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2736
2796
|
|
|
2737
2797
|
app.post("/auth/refresh", async (c) => {
|
|
2738
2798
|
let rawBody: unknown;
|
|
2799
|
+
const proxyTelemetry = new ProxyTelemetryCollector();
|
|
2739
2800
|
const requestCost = startRequestCost();
|
|
2740
2801
|
try {
|
|
2741
2802
|
rawBody = await c.req.raw
|
|
@@ -2749,6 +2810,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2749
2810
|
"refresh",
|
|
2750
2811
|
options,
|
|
2751
2812
|
state,
|
|
2813
|
+
proxyTelemetry,
|
|
2752
2814
|
c.req.raw.signal,
|
|
2753
2815
|
);
|
|
2754
2816
|
logProviderSuccess(
|
|
@@ -2759,8 +2821,13 @@ function createServerAppWithCapabilityModules(
|
|
|
2759
2821
|
body.requestId,
|
|
2760
2822
|
response instanceof Response ? response.status : 200,
|
|
2761
2823
|
finishRequestCost(requestCost),
|
|
2824
|
+
proxyTelemetry,
|
|
2762
2825
|
);
|
|
2763
|
-
|
|
2826
|
+
if (response instanceof Response)
|
|
2827
|
+
return responseWithProviderTelemetry(response, proxyTelemetry);
|
|
2828
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2829
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2830
|
+
return c.json(response);
|
|
2764
2831
|
} catch (error) {
|
|
2765
2832
|
const status = toStatusCode(error);
|
|
2766
2833
|
const requestId = extractRequestId(rawBody);
|
|
@@ -2773,7 +2840,11 @@ function createServerAppWithCapabilityModules(
|
|
|
2773
2840
|
error,
|
|
2774
2841
|
status,
|
|
2775
2842
|
finishRequestCost(requestCost),
|
|
2843
|
+
undefined,
|
|
2844
|
+
proxyTelemetry,
|
|
2776
2845
|
);
|
|
2846
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2847
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2777
2848
|
return responseWithErrorObservability(
|
|
2778
2849
|
c.json(toErrorResponse(error, requestId), status),
|
|
2779
2850
|
error,
|
|
@@ -2783,6 +2854,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2783
2854
|
|
|
2784
2855
|
app.post("/auth/disconnect", async (c) => {
|
|
2785
2856
|
let rawBody: unknown;
|
|
2857
|
+
const proxyTelemetry = new ProxyTelemetryCollector();
|
|
2786
2858
|
const requestCost = startRequestCost();
|
|
2787
2859
|
try {
|
|
2788
2860
|
rawBody = await c.req.raw
|
|
@@ -2796,6 +2868,7 @@ function createServerAppWithCapabilityModules(
|
|
|
2796
2868
|
"abort",
|
|
2797
2869
|
options,
|
|
2798
2870
|
state,
|
|
2871
|
+
proxyTelemetry,
|
|
2799
2872
|
c.req.raw.signal,
|
|
2800
2873
|
);
|
|
2801
2874
|
logProviderSuccess(
|
|
@@ -2806,8 +2879,13 @@ function createServerAppWithCapabilityModules(
|
|
|
2806
2879
|
body.requestId,
|
|
2807
2880
|
response instanceof Response ? response.status : 200,
|
|
2808
2881
|
finishRequestCost(requestCost),
|
|
2882
|
+
proxyTelemetry,
|
|
2809
2883
|
);
|
|
2810
|
-
|
|
2884
|
+
if (response instanceof Response)
|
|
2885
|
+
return responseWithProviderTelemetry(response, proxyTelemetry);
|
|
2886
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2887
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2888
|
+
return c.json(response);
|
|
2811
2889
|
} catch (error) {
|
|
2812
2890
|
const status = toStatusCode(error);
|
|
2813
2891
|
const requestId = extractRequestId(rawBody);
|
|
@@ -2820,7 +2898,11 @@ function createServerAppWithCapabilityModules(
|
|
|
2820
2898
|
error,
|
|
2821
2899
|
status,
|
|
2822
2900
|
finishRequestCost(requestCost),
|
|
2901
|
+
undefined,
|
|
2902
|
+
proxyTelemetry,
|
|
2823
2903
|
);
|
|
2904
|
+
const telemetryHeader = proxyTelemetry.toHeaderValue();
|
|
2905
|
+
if (telemetryHeader) c.header(PROVIDER_TELEMETRY_HEADER, telemetryHeader);
|
|
2824
2906
|
return responseWithErrorObservability(
|
|
2825
2907
|
c.json(toErrorResponse(error, requestId), status),
|
|
2826
2908
|
error,
|