deepline 0.3.89 → 0.3.90
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/contracts/install-commands.json +29 -0
- package/dist/bundling-sources/sdk/src/client.ts +120 -37
- package/dist/bundling-sources/sdk/src/index.ts +4 -0
- package/dist/bundling-sources/sdk/src/pagination.ts +25 -0
- package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +1 -1
- package/dist/bundling-sources/sdk/src/release.ts +16 -9
- package/dist/bundling-sources/sdk/src/types.ts +23 -0
- package/dist/bundling-sources/shared_libs/monitors/analytics-public.ts +10 -0
- package/dist/bundling-sources/shared_libs/monitors/http-error-response.ts +3 -0
- package/dist/bundling-sources/shared_libs/monitors/inbound-queue.ts +4 -4
- package/dist/bundling-sources/shared_libs/monitors/inventory-reconciliation.ts +59 -0
- package/dist/bundling-sources/shared_libs/monitors/lifecycle-notifications.ts +7 -9
- package/dist/bundling-sources/shared_libs/monitors/package.json +7 -0
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-batch-operation.ts +44 -2
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-consumer-health.ts +2 -2
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-identity-claims.ts +2 -2
- package/dist/bundling-sources/shared_libs/monitors/provider-monitor-public-aliases.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-dead-letter.ts +245 -0
- package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-message.ts +38 -0
- package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-ack-probe.ts +94 -0
- package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue-delivery.ts +60 -0
- package/dist/bundling-sources/shared_libs/monitors/signal-radars/inbound-queue.ts +60 -0
- package/dist/bundling-sources/shared_libs/monitors/snitcher-install-validation.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/snitcher-ip2company.ts +2 -2
- package/dist/bundling-sources/shared_libs/monitors/snitcher-radar.ts +1 -1
- package/dist/bundling-sources/shared_libs/monitors/tracking-provider-integrations.ts +1 -1
- package/dist/bundling-sources/shared_libs/observability/build-context.ts +13 -0
- package/dist/bundling-sources/shared_libs/observability/log-metadata.ts +160 -0
- package/dist/bundling-sources/shared_libs/observability/request-context.ts +68 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-jobs.json +654 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-work-manual.ts +35 -0
- package/dist/bundling-sources/shared_libs/observability/scheduled-work.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/neon-constants.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-data-plane/r2.ts +272 -0
- package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +45 -0
- package/dist/bundling-sources/shared_libs/play-runtime/async-operation.ts +66 -1
- package/dist/bundling-sources/shared_libs/play-runtime/async-play-invocation.ts +0 -1
- package/dist/bundling-sources/shared_libs/play-runtime/bounceban-batching.ts +137 -0
- package/dist/bundling-sources/shared_libs/play-runtime/context.ts +779 -140
- package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +46 -0
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-payload-contract.ts +68 -0
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-janitor.ts +103 -0
- package/dist/bundling-sources/shared_libs/play-runtime/daytona-sandbox-reaper.ts +725 -0
- package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +29 -0
- package/dist/bundling-sources/shared_libs/play-runtime/execution-capabilities.ts +23 -0
- package/dist/bundling-sources/shared_libs/play-runtime/execution-gateway-invocation-fence.ts +442 -0
- package/dist/bundling-sources/shared_libs/play-runtime/execution-protocol.ts +3 -3
- package/dist/bundling-sources/shared_libs/play-runtime/fixture-behavior.ts +18 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/app-runtime-rate-state-backend.ts +9 -0
- package/dist/bundling-sources/shared_libs/play-runtime/governor/policy.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/governor/rate-state-backend.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/contracts.ts +66 -0
- package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/job.ts +145 -0
- package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/ports.ts +21 -0
- package/dist/bundling-sources/shared_libs/play-runtime/integration-operation-reader-fence/postgres-store.ts +170 -0
- package/dist/bundling-sources/shared_libs/play-runtime/internal-bootstrap-token.ts +1322 -0
- package/dist/bundling-sources/shared_libs/play-runtime/internal-step-ids.ts +2 -2
- package/dist/bundling-sources/shared_libs/play-runtime/lane-retirement-gate.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/launch-source-policy.ts +112 -0
- package/dist/bundling-sources/shared_libs/play-runtime/map-execution-frame.ts +8 -0
- package/dist/bundling-sources/shared_libs/play-runtime/perf-trace.ts +127 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-artifact-runtime-contract.ts +5 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-run-recovery-policy.ts +24 -1
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/contracts.ts +56 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/index.ts +13 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/job.ts +41 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/ports.ts +17 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/admission/postgres-adapter.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/contracts.ts +114 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/engine-suspension.ts +108 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/index.ts +36 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/job.ts +97 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/ports.ts +104 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/postgres-fence-adapter.ts +263 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/attempts/worker-terminal-projection.ts +64 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/contracts.ts +29 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/gateway-adapter.ts +56 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/index.ts +15 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/job.ts +65 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/projection/ports.ts +17 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/contracts.ts +42 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/index.ts +17 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/job.ts +142 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/ports.ts +42 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/sandbox-cleanup/postgres-adapter.ts +102 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/contracts.ts +60 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/index.ts +16 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/job.ts +78 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/ports.ts +54 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runs/terminal/postgres-adapter.ts +71 -0
- package/dist/bundling-sources/shared_libs/play-runtime/play-runtime-batching-registry.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/receipt-status.ts +5 -8
- package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +3 -5
- package/dist/bundling-sources/shared_libs/play-runtime/run-identity.ts +168 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +72 -9
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +6 -12
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +19 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/bundle.ts +0 -1
- package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +14 -44
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +57 -205
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-authority.ts +201 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-env.ts +6 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-operation-contract.ts +67 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-release-environment.ts +2 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-sandbox-contract.ts +68 -0
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-scheduler-topology.ts +14 -2
- package/dist/bundling-sources/shared_libs/play-runtime/runtime-telemetry.ts +108 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +4 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +3 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backend.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-deadline-reconciliation.ts +88 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-deploy-task.ts +124 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-play-run-task.ts +68 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-pool.ts +193 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-queue-lifecycle.ts +269 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-queue-suffix.ts +73 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-runtime-worker.ts +6642 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +897 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-metrics.ts +120 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-worker-required-env.ts +76 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd.ts +476 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-heavy-request-admission.ts +47 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/gateway-progress-registry.ts +147 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/index.ts +27 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/lazy.ts +50 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/play-run-recovery.ts +98 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-budget-state.ts +260 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-pool.ts +1416 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-progress.ts +1255 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres-rate-state.ts +942 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +14636 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/receipt-gateway.ts +888 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-ledger-outbox-recovery.ts +355 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/run-terminal-transition.ts +46 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runner-push.ts +60 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-api-origin.ts +33 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-receipt-gateway-health.ts +64 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-capacity.ts +835 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-ledger-reconciliation.ts +1218 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-sandbox-operation.ts +207 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-scheduler-schema.ts +10 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/scheduler-capacity.ts +123 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/scheduler-launch-read-observability.ts +78 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/submit-admission.ts +169 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/terminal-contract.ts +20 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/worker-queue-metrics.ts +34 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/worker-resource-metrics.ts +249 -0
- package/dist/bundling-sources/shared_libs/play-runtime/sheet-attempt-sql.ts +7 -0
- package/dist/bundling-sources/shared_libs/play-runtime/step-progress.ts +296 -0
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call/native-batch.ts +3 -3
- package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +20 -1
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +60 -15
- package/dist/bundling-sources/shared_libs/play-runtime/tool-execution-outcome.ts +20 -0
- package/dist/bundling-sources/shared_libs/play-runtime/transient-service-error.ts +12 -0
- package/dist/bundling-sources/shared_libs/play-runtime/vercel-protection.ts +14 -1
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipt-storage-contract.ts +165 -0
- package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +15 -23
- package/dist/bundling-sources/shared_libs/play-runtime/workflow-executor-auth.ts +169 -0
- package/dist/bundling-sources/shared_libs/play-runtime/zerobounce-batching.ts +122 -0
- package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +2 -0
- package/dist/bundling-sources/shared_libs/plays/contracts.ts +2 -0
- package/dist/bundling-sources/shared_libs/plays/deployment-status.ts +1 -1
- package/dist/bundling-sources/shared_libs/plays/docflow.ts +1 -1
- package/dist/bundling-sources/shared_libs/plays/play-grep-search.ts +39 -0
- package/dist/bundling-sources/shared_libs/plays/share/copy.ts +271 -0
- package/dist/bundling-sources/shared_libs/plays/share/metrics.ts +140 -0
- package/dist/bundling-sources/shared_libs/plays/share/public-read-model.ts +86 -0
- package/dist/bundling-sources/shared_libs/plays/share/seo-quality.ts +181 -0
- package/dist/bundling-sources/shared_libs/plays/share/static-pipeline-summary.ts +658 -0
- package/dist/bundling-sources/shared_libs/plays/share/types.ts +197 -0
- package/dist/bundling-sources/shared_libs/plays/slack-hitl-timeout-error.ts +37 -0
- package/dist/bundling-sources/shared_libs/plays/static-pipeline.ts +6 -1
- package/dist/bundling-sources/shared_libs/plays/tool-result-types.ts +1 -1
- package/dist/bundling-sources/shared_libs/product-notifications/configuration.ts +7 -1
- package/dist/bundling-sources/shared_libs/product-notifications/default-policy.ts +3 -2
- package/dist/bundling-sources/shared_libs/product-notifications/overflow.ts +18 -0
- package/dist/bundling-sources/shared_libs/product-notifications/rolling-limit.ts +24 -0
- package/dist/bundling-sources/shared_libs/product-notifications/slack-delivery.ts +624 -0
- package/dist/bundling-sources/shared_libs/product-notifications/slack-payload.ts +140 -0
- package/dist/bundling-sources/shared_libs/product-notifications/slack-transport.ts +75 -0
- package/dist/bundling-sources/shared_libs/runtime-env.ts +6 -0
- package/dist/bundling-sources/shared_libs/security/email-blacklist.ts +42 -0
- package/dist/bundling-sources/shared_libs/security/header-safe-env.ts +10 -3
- package/dist/bundling-sources/shared_libs/security/slack-sanitize.ts +133 -0
- package/dist/cli/getting-started.d.mts +52 -0
- package/dist/cli/getting-started.d.ts +52 -0
- package/dist/cli/getting-started.js +65 -0
- package/dist/cli/getting-started.mjs +36 -0
- package/dist/cli/index.d.mts +9 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +545 -264
- package/dist/cli/index.mjs +543 -271
- package/dist/{compiler-manifest-DsLbQaew.d.mts → compiler-manifest-BaJfE-5H.d.mts} +5 -3
- package/dist/{compiler-manifest-DsLbQaew.d.ts → compiler-manifest-BaJfE-5H.d.ts} +5 -3
- package/dist/index.d.mts +81 -148
- package/dist/index.d.ts +81 -148
- package/dist/index.js +83 -26
- package/dist/index.mjs +83 -26
- package/dist/install-integrity.json +130 -2
- package/dist/monitor-fleet-contract.d.mts +138 -0
- package/dist/monitor-fleet-contract.d.ts +138 -0
- package/dist/monitor-fleet-contract.js +404 -0
- package/dist/monitor-fleet-contract.mjs +367 -0
- package/dist/plays/bundle-play-file.d.mts +2 -2
- package/dist/plays/bundle-play-file.d.ts +2 -2
- package/dist/release.d.mts +255 -0
- package/dist/release.d.ts +255 -0
- package/dist/release.js +215 -0
- package/dist/release.mjs +188 -0
- package/package.json +21 -4
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { workUnitAsyncStorage } from 'next/dist/server/app-render/work-unit-async-storage.external';
|
|
4
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
|
+
|
|
6
|
+
export type LogMetadata = Record<string, unknown>;
|
|
7
|
+
|
|
8
|
+
type RequestStoreLike = {
|
|
9
|
+
headers?: unknown;
|
|
10
|
+
url?: { pathname?: string; search?: string };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const storage = new AsyncLocalStorage<LogMetadata>();
|
|
14
|
+
const CONSOLE_METHODS = ['log', 'info', 'warn', 'error', 'debug'] as const;
|
|
15
|
+
const LOG_REQUEST_ID_HEADER = 'x-deepline-request-id';
|
|
16
|
+
const LOG_REQUEST_PATH_HEADER = 'x-deepline-request-path';
|
|
17
|
+
const LOG_REQUEST_METHOD_HEADER = 'x-deepline-request-method';
|
|
18
|
+
|
|
19
|
+
let isPatched = false;
|
|
20
|
+
|
|
21
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
22
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
23
|
+
const prototype = Object.getPrototypeOf(value);
|
|
24
|
+
return prototype === Object.prototype || prototype === null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function normalizeText(value: string | null | undefined): string | null {
|
|
28
|
+
if (!value) return null;
|
|
29
|
+
const trimmed = String(value).trim();
|
|
30
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function safeHeaderValue(container: unknown, key: string): string | null {
|
|
34
|
+
if (!container || typeof container !== 'object') return null;
|
|
35
|
+
if (
|
|
36
|
+
'then' in (container as Record<string, unknown>) &&
|
|
37
|
+
typeof (container as { then: unknown }).then === 'function'
|
|
38
|
+
) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const getter = (container as { get?: (name: string) => unknown }).get;
|
|
42
|
+
if (typeof getter !== 'function') return null;
|
|
43
|
+
try {
|
|
44
|
+
const value = getter.call(container, key);
|
|
45
|
+
return normalizeText(typeof value === 'string' ? value : null);
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getRequestStoreFromNext(): unknown {
|
|
52
|
+
try {
|
|
53
|
+
return workUnitAsyncStorage.getStore?.() as unknown;
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getRequestMetadataFromHeaders(): Record<string, string> | null {
|
|
60
|
+
const requestStore = getRequestStoreFromNext() as RequestStoreLike | null;
|
|
61
|
+
if (!requestStore?.headers) return null;
|
|
62
|
+
|
|
63
|
+
const requestHeaders = requestStore.headers;
|
|
64
|
+
const requestId = normalizeText(
|
|
65
|
+
safeHeaderValue(requestHeaders, LOG_REQUEST_ID_HEADER) ??
|
|
66
|
+
safeHeaderValue(requestHeaders, 'x-vercel-id') ??
|
|
67
|
+
safeHeaderValue(requestHeaders, 'x-request-id'),
|
|
68
|
+
);
|
|
69
|
+
const requestPath =
|
|
70
|
+
normalizeText(safeHeaderValue(requestHeaders, LOG_REQUEST_PATH_HEADER)) ??
|
|
71
|
+
((): string | null => {
|
|
72
|
+
const pathFromStore =
|
|
73
|
+
requestStore.url &&
|
|
74
|
+
typeof requestStore.url === 'object' &&
|
|
75
|
+
'pathname' in requestStore.url
|
|
76
|
+
? String(requestStore.url.pathname ?? '').trim()
|
|
77
|
+
: '';
|
|
78
|
+
return normalizeText(pathFromStore);
|
|
79
|
+
})();
|
|
80
|
+
const requestMethod =
|
|
81
|
+
normalizeText(safeHeaderValue(requestHeaders, LOG_REQUEST_METHOD_HEADER)) ??
|
|
82
|
+
null;
|
|
83
|
+
const vercelRequestId = normalizeText(
|
|
84
|
+
safeHeaderValue(requestHeaders, 'x-vercel-id'),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (!requestId && !requestPath && !requestMethod && !vercelRequestId) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const metadata: Record<string, string> = {};
|
|
92
|
+
if (requestId) {
|
|
93
|
+
metadata.request_id = requestId;
|
|
94
|
+
metadata.requestId = requestId;
|
|
95
|
+
}
|
|
96
|
+
if (requestPath) metadata.request_path = requestPath;
|
|
97
|
+
if (requestMethod) metadata.request_method = requestMethod;
|
|
98
|
+
if (vercelRequestId) {
|
|
99
|
+
metadata.vercel_request_id = vercelRequestId;
|
|
100
|
+
metadata.vercelRequestId = vercelRequestId;
|
|
101
|
+
}
|
|
102
|
+
return metadata;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getActiveLogMetadata(): LogMetadata {
|
|
106
|
+
const contextMetadata = storage.getStore();
|
|
107
|
+
const requestMetadata = getRequestMetadataFromHeaders();
|
|
108
|
+
|
|
109
|
+
if (!contextMetadata && requestMetadata) return requestMetadata;
|
|
110
|
+
if (!requestMetadata) return contextMetadata ?? {};
|
|
111
|
+
return { ...requestMetadata, ...contextMetadata };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function mergeLogArgs(args: unknown[], metadata: LogMetadata): unknown[] {
|
|
115
|
+
if (args.length === 0) return [metadata];
|
|
116
|
+
const last = args[args.length - 1];
|
|
117
|
+
if (isPlainRecord(last)) {
|
|
118
|
+
return [...args.slice(0, -1), { ...metadata, ...last }];
|
|
119
|
+
}
|
|
120
|
+
return [...args, metadata];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function patchConsoleWithMetadata(): void {
|
|
124
|
+
if (isPatched) return;
|
|
125
|
+
isPatched = true;
|
|
126
|
+
const consoleRef = console as unknown as Record<
|
|
127
|
+
(typeof CONSOLE_METHODS)[number],
|
|
128
|
+
(...args: unknown[]) => void
|
|
129
|
+
>;
|
|
130
|
+
|
|
131
|
+
for (const method of CONSOLE_METHODS) {
|
|
132
|
+
const original = consoleRef[method].bind(console);
|
|
133
|
+
consoleRef[method] = ((...args: unknown[]) => {
|
|
134
|
+
const metadata = getActiveLogMetadata();
|
|
135
|
+
if (!metadata || Object.keys(metadata).length === 0) {
|
|
136
|
+
original(...args);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
original(...mergeLogArgs(args, metadata));
|
|
140
|
+
}) as (...args: unknown[]) => void;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function setLogMetadata(metadata: LogMetadata): void {
|
|
145
|
+
patchConsoleWithMetadata();
|
|
146
|
+
const current = storage.getStore() ?? {};
|
|
147
|
+
storage.enterWith({ ...current, ...metadata });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function withLogMetadata<T>(metadata: LogMetadata, fn: () => T): T {
|
|
151
|
+
patchConsoleWithMetadata();
|
|
152
|
+
const current = storage.getStore() ?? {};
|
|
153
|
+
return storage.run({ ...current, ...metadata }, fn);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function getCurrentRequestMetadata(): LogMetadata {
|
|
157
|
+
return getActiveLogMetadata();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
patchConsoleWithMetadata();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const REQUEST_ID_PREFIX = 'req_';
|
|
4
|
+
|
|
5
|
+
export type RequestLogMetadata = Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
export type RequestLike = {
|
|
8
|
+
method: string;
|
|
9
|
+
headers: { get(name: string): string | null };
|
|
10
|
+
nextUrl?: { pathname: string };
|
|
11
|
+
url?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function normalizeText(value: string | null | undefined): string | null {
|
|
15
|
+
if (!value) return null;
|
|
16
|
+
const trimmed = String(value).trim();
|
|
17
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function resolveRequestPath(req: RequestLike): string {
|
|
21
|
+
if (req.nextUrl?.pathname) return req.nextUrl.pathname;
|
|
22
|
+
if (req.url) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(req.url).pathname;
|
|
25
|
+
} catch {
|
|
26
|
+
return String(req.url);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return '(unknown)';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function resolveRequestId(
|
|
33
|
+
req: RequestLike,
|
|
34
|
+
requestId: string | null | undefined,
|
|
35
|
+
): string {
|
|
36
|
+
const explicit = normalizeText(requestId);
|
|
37
|
+
if (explicit) return explicit;
|
|
38
|
+
const vercelRequestId = normalizeText(req.headers.get('x-vercel-id'));
|
|
39
|
+
if (vercelRequestId) return vercelRequestId;
|
|
40
|
+
return `${REQUEST_ID_PREFIX}${randomUUID().replace(/-/g, '').slice(0, 12)}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function buildRequestLogMetadata(
|
|
44
|
+
req: RequestLike,
|
|
45
|
+
input: {
|
|
46
|
+
requestId?: string | null;
|
|
47
|
+
requestPath?: string | null;
|
|
48
|
+
requestMethod?: string | null;
|
|
49
|
+
extraMetadata?: RequestLogMetadata;
|
|
50
|
+
} = {},
|
|
51
|
+
): RequestLogMetadata {
|
|
52
|
+
const resolvedRequestId = resolveRequestId(req, input.requestId);
|
|
53
|
+
const vercelRequestId = normalizeText(req.headers.get('x-vercel-id'));
|
|
54
|
+
const resolvedRequestPath =
|
|
55
|
+
normalizeText(input.requestPath) ?? resolveRequestPath(req);
|
|
56
|
+
const resolvedRequestMethod =
|
|
57
|
+
normalizeText(input.requestMethod) ?? req.method.toUpperCase();
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
request_id: resolvedRequestId,
|
|
61
|
+
requestId: resolvedRequestId,
|
|
62
|
+
request_path: resolvedRequestPath,
|
|
63
|
+
request_method: resolvedRequestMethod,
|
|
64
|
+
...(vercelRequestId ? { vercel_request_id: vercelRequestId } : {}),
|
|
65
|
+
...(vercelRequestId ? { vercelRequestId } : {}),
|
|
66
|
+
...(input.extraMetadata ?? {}),
|
|
67
|
+
};
|
|
68
|
+
}
|