@autter/runtime-next 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -20,54 +20,231 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ CODE_PATTERN: () => import_runtime_node2.CODE_PATTERN,
24
+ RuntimeError: () => import_runtime_node2.RuntimeError,
25
+ addBreadcrumb: () => import_runtime_node2.addBreadcrumb,
26
+ autterErrorHandler: () => import_runtime_node2.autterErrorHandler,
27
+ autterErrorResponse: () => import_runtime_node2.autterErrorResponse,
28
+ autterFastify: () => import_runtime_node2.autterFastify,
29
+ autterFastifyErrors: () => import_runtime_node2.autterFastifyErrors,
30
+ autterKoa: () => import_runtime_node2.autterKoa,
31
+ autterRequests: () => import_runtime_node2.autterRequests,
32
+ captureRequestError: () => import_runtime_node2.captureRequestError,
23
33
  captureServerException: () => import_runtime_node2.captureException,
24
34
  captureServerMessage: () => import_runtime_node2.captureMessage,
35
+ consoleSink: () => import_runtime_node2.consoleSink,
25
36
  createAutterRelayRoute: () => createAutterRelayRoute,
26
37
  createRuntimeLogger: () => import_runtime_node2.createRuntimeLogger,
38
+ defineRuntimeErrors: () => import_runtime_node2.defineRuntimeErrors,
27
39
  emitLlmSelftestTrace: () => import_runtime_node2.emitLlmSelftestTrace,
40
+ enrichDeployment: () => import_runtime_node2.enrichDeployment,
41
+ enrichEdgeGeo: () => import_runtime_node2.enrichEdgeGeo,
42
+ enrichRequestSize: () => import_runtime_node2.enrichRequestSize,
43
+ enrichUserAgent: () => import_runtime_node2.enrichUserAgent,
44
+ errorAttributes: () => import_runtime_node2.errorAttributes,
45
+ fileSink: () => import_runtime_node2.fileSink,
28
46
  flushRuntimeLogs: () => import_runtime_node2.flushRuntimeLogs,
47
+ initAutterLogging: () => import_runtime_node2.initAutterLogging,
29
48
  installAutterAutoFlush: () => import_runtime_node2.installAutterAutoFlush,
30
49
  instrumentLlmClient: () => import_runtime_node2.instrumentLlmClient,
50
+ isRuntimeErrorLike: () => import_runtime_node2.isRuntimeErrorLike,
31
51
  makeSafeCapture: () => import_runtime_node2.makeSafeCapture,
52
+ otlpSink: () => import_runtime_node2.otlpSink,
32
53
  redactAttributes: () => import_runtime_node2.redactAttributes,
54
+ redactText: () => import_runtime_node2.redactText,
33
55
  registerAutter: () => registerAutter,
34
56
  reportServerOutcome: () => import_runtime_node2.reportOutcome,
57
+ runInBackground: () => import_runtime_node2.runInBackground,
58
+ runtimeContext: () => import_runtime_node2.runtimeContext,
35
59
  runtimeLogStats: () => import_runtime_node2.runtimeLogStats,
36
60
  runtimeLogger: () => import_runtime_node2.runtimeLogger,
61
+ toClientError: () => import_runtime_node2.toClientError,
37
62
  trackLlmCall: () => import_runtime_node2.trackLlmCall,
38
63
  withLlmCall: () => import_runtime_node2.withLlmCall,
39
64
  withProcessSpan: () => import_runtime_node2.withProcessSpan,
40
- withRuntimeOperation: () => import_runtime_node2.withRuntimeOperation
65
+ withRuntimeOperation: () => import_runtime_node2.withRuntimeOperation,
66
+ withRuntimeRequest: () => withRuntimeRequest
41
67
  });
42
68
  module.exports = __toCommonJS(src_exports);
43
69
 
44
70
  // src/server.ts
45
71
  var import_runtime_node = require("@autter/runtime-node");
72
+
73
+ // package.json
74
+ var package_default = {
75
+ name: "@autter/runtime-next",
76
+ version: "1.6.0",
77
+ description: "One-command Autter Runtime for Next.js: server OTel, request wide events, coded errors, browser tracker, relay route, edge middleware and React error boundary",
78
+ license: "MIT",
79
+ type: "module",
80
+ main: "./dist/index.cjs",
81
+ module: "./dist/index.js",
82
+ types: "./dist/index.d.ts",
83
+ exports: {
84
+ ".": {
85
+ types: "./dist/index.d.ts",
86
+ import: "./dist/index.js",
87
+ require: "./dist/index.cjs"
88
+ },
89
+ "./server": {
90
+ types: "./dist/server.d.ts",
91
+ import: "./dist/server.js",
92
+ require: "./dist/server.cjs"
93
+ },
94
+ "./client": {
95
+ types: "./dist/client.d.ts",
96
+ import: "./dist/client.js",
97
+ require: "./dist/client.cjs"
98
+ },
99
+ "./edge": {
100
+ types: "./dist/edge.d.ts",
101
+ import: "./dist/edge.js",
102
+ require: "./dist/edge.cjs"
103
+ },
104
+ "./instrumentation": {
105
+ types: "./dist/instrumentation.d.ts",
106
+ "edge-light": {
107
+ import: "./dist/instrumentation-edge.js",
108
+ require: "./dist/instrumentation-edge.cjs"
109
+ },
110
+ worker: {
111
+ import: "./dist/instrumentation-edge.js",
112
+ require: "./dist/instrumentation-edge.cjs"
113
+ },
114
+ import: "./dist/instrumentation.js",
115
+ require: "./dist/instrumentation.cjs"
116
+ }
117
+ },
118
+ files: [
119
+ "dist"
120
+ ],
121
+ repository: {
122
+ type: "git",
123
+ url: "https://github.com/Autter-dev/autter-runtime.git",
124
+ directory: "packages/runtime-next"
125
+ },
126
+ scripts: {
127
+ build: `node ../../scripts/ensure-built.mjs runtime-node runtime-edge runtime-browser && node -e "require('node:fs').rmSync('dist',{recursive:true,force:true})" && tsup`,
128
+ test: "npm run build -w @autter/runtime-core && npm run build -w @autter/runtime-node && npm run build -w @autter/runtime-edge && npm run build -w @autter/runtime-browser && npm run build && node --test test/*.test.mjs"
129
+ },
130
+ dependencies: {
131
+ "@autter/runtime-browser": "^1.6.0",
132
+ "@autter/runtime-edge": "^1.1.0",
133
+ "@autter/runtime-node": "^1.6.0"
134
+ },
135
+ peerDependencies: {
136
+ react: ">=18"
137
+ },
138
+ devDependencies: {
139
+ "@types/react": "^18.3.0",
140
+ tsup: "^8.3.5",
141
+ typescript: "^5.7.0"
142
+ },
143
+ engines: {
144
+ node: ">=20"
145
+ },
146
+ publishConfig: {
147
+ access: "public",
148
+ provenance: true
149
+ },
150
+ homepage: "https://github.com/Autter-dev/autter-runtime#readme",
151
+ bugs: "https://github.com/Autter-dev/autter-runtime/issues",
152
+ keywords: [
153
+ "nextjs",
154
+ "error-tracking",
155
+ "telemetry",
156
+ "opentelemetry",
157
+ "react",
158
+ "error-boundary"
159
+ ]
160
+ };
161
+
162
+ // src/server.ts
46
163
  var import_runtime_node2 = require("@autter/runtime-node");
47
164
  function registerAutter(options) {
48
- return (0, import_runtime_node.initAutterServer)(options);
165
+ return (0, import_runtime_node.initAutterServer)({
166
+ distro: { name: "@autter/runtime-next", version: package_default.version },
167
+ ...options
168
+ });
49
169
  }
50
170
  function createAutterRelayRoute(options) {
51
171
  return { POST: (0, import_runtime_node.createBrowserRelayFetchHandler)(options) };
52
172
  }
173
+ var after;
174
+ var afterReady = (async () => {
175
+ try {
176
+ const specifier = "next/server";
177
+ const mod = await import(
178
+ /* webpackIgnore: true */
179
+ specifier
180
+ );
181
+ after = mod.after ?? mod.unstable_after ?? null;
182
+ } catch {
183
+ after = null;
184
+ }
185
+ return after;
186
+ })();
187
+ function scheduleAfter(promise) {
188
+ const run = (fn) => {
189
+ if (!fn) return;
190
+ try {
191
+ fn(promise);
192
+ } catch {
193
+ }
194
+ };
195
+ if (after !== void 0) run(after);
196
+ else void afterReady.then(run);
197
+ }
198
+ function withRuntimeRequest(handler, options = {}) {
199
+ return (0, import_runtime_node.withRuntimeRequest)(handler, {
200
+ ...options,
201
+ waitUntil: options.waitUntil ?? scheduleAfter
202
+ });
203
+ }
53
204
  // Annotate the CommonJS export names for ESM import in node:
54
205
  0 && (module.exports = {
206
+ CODE_PATTERN,
207
+ RuntimeError,
208
+ addBreadcrumb,
209
+ autterErrorHandler,
210
+ autterErrorResponse,
211
+ autterFastify,
212
+ autterFastifyErrors,
213
+ autterKoa,
214
+ autterRequests,
215
+ captureRequestError,
55
216
  captureServerException,
56
217
  captureServerMessage,
218
+ consoleSink,
57
219
  createAutterRelayRoute,
58
220
  createRuntimeLogger,
221
+ defineRuntimeErrors,
59
222
  emitLlmSelftestTrace,
223
+ enrichDeployment,
224
+ enrichEdgeGeo,
225
+ enrichRequestSize,
226
+ enrichUserAgent,
227
+ errorAttributes,
228
+ fileSink,
60
229
  flushRuntimeLogs,
230
+ initAutterLogging,
61
231
  installAutterAutoFlush,
62
232
  instrumentLlmClient,
233
+ isRuntimeErrorLike,
63
234
  makeSafeCapture,
235
+ otlpSink,
64
236
  redactAttributes,
237
+ redactText,
65
238
  registerAutter,
66
239
  reportServerOutcome,
240
+ runInBackground,
241
+ runtimeContext,
67
242
  runtimeLogStats,
68
243
  runtimeLogger,
244
+ toClientError,
69
245
  trackLlmCall,
70
246
  withLlmCall,
71
247
  withProcessSpan,
72
- withRuntimeOperation
248
+ withRuntimeOperation,
249
+ withRuntimeRequest
73
250
  });
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- export { createAutterRelayRoute, registerAutter } from './server.cjs';
2
- export { AutoFlushHandle, AutoFlushOptions, AutterServer, AutterServerOptions, FlushTarget, InstrumentLlmOptions, LlmCallHandle, LlmCallInfo, LlmUsage, RedactOptions, RelayOptions, RuntimeLogContext, RuntimeLogContextValue, RuntimeLogLevel, RuntimeLoggingOptions, RuntimeOperation, RuntimeOutcome, SafeCapture, TrackedLlmCall, captureException as captureServerException, captureMessage as captureServerMessage, createRuntimeLogger, emitLlmSelftestTrace, flushRuntimeLogs, installAutterAutoFlush, instrumentLlmClient, makeSafeCapture, redactAttributes, reportOutcome as reportServerOutcome, runtimeLogStats, runtimeLogger, trackLlmCall, withLlmCall, withProcessSpan, withRuntimeOperation } from '@autter/runtime-node';
1
+ export { createAutterRelayRoute, registerAutter, withRuntimeRequest } from './server.cjs';
2
+ export { AutoFlushHandle, AutoFlushOptions, AutterErrorHandlerOptions, AutterErrorResponseOptions, AutterLogging, AutterLoggingOptions, AutterRequestsOptions, AutterServer, AutterServerOptions, Breadcrumb, BreadcrumbInput, CODE_PATTERN, ClientErrorBody, ConsoleSinkOptions, FileSinkOptions, FlushTarget, InstrumentLlmOptions, LlmCallHandle, LlmCallInfo, LlmUsage, OtlpSinkOptions, RedactOptions, RelayOptions, RuntimeCarrier, RuntimeContextHandle, RuntimeEnrichContext, RuntimeEnrichEvent, RuntimeEnricher, RuntimeError, RuntimeErrorCatalog, RuntimeErrorDefinition, RuntimeErrorExtras, RuntimeErrorFactory, RuntimeErrorLike, RuntimeErrorOptions, RuntimeEvent, RuntimeLogContext, RuntimeLogContextValue, RuntimeLogLevel, RuntimeLoggingOptions, RuntimeOperation, RuntimeOperationKind, RuntimeOperationOptions, RuntimeOutcome, RuntimeRequestOptions, RuntimeSink, RuntimeSinkContext, SafeCapture, TrackedLlmCall, addBreadcrumb, autterErrorHandler, autterErrorResponse, autterFastify, autterFastifyErrors, autterKoa, autterRequests, captureRequestError, captureException as captureServerException, captureMessage as captureServerMessage, consoleSink, createRuntimeLogger, defineRuntimeErrors, emitLlmSelftestTrace, enrichDeployment, enrichEdgeGeo, enrichRequestSize, enrichUserAgent, errorAttributes, fileSink, flushRuntimeLogs, initAutterLogging, installAutterAutoFlush, instrumentLlmClient, isRuntimeErrorLike, makeSafeCapture, otlpSink, redactAttributes, redactText, reportOutcome as reportServerOutcome, runInBackground, runtimeContext, runtimeLogStats, runtimeLogger, toClientError, trackLlmCall, withLlmCall, withProcessSpan, withRuntimeOperation } from '@autter/runtime-node';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { createAutterRelayRoute, registerAutter } from './server.js';
2
- export { AutoFlushHandle, AutoFlushOptions, AutterServer, AutterServerOptions, FlushTarget, InstrumentLlmOptions, LlmCallHandle, LlmCallInfo, LlmUsage, RedactOptions, RelayOptions, RuntimeLogContext, RuntimeLogContextValue, RuntimeLogLevel, RuntimeLoggingOptions, RuntimeOperation, RuntimeOutcome, SafeCapture, TrackedLlmCall, captureException as captureServerException, captureMessage as captureServerMessage, createRuntimeLogger, emitLlmSelftestTrace, flushRuntimeLogs, installAutterAutoFlush, instrumentLlmClient, makeSafeCapture, redactAttributes, reportOutcome as reportServerOutcome, runtimeLogStats, runtimeLogger, trackLlmCall, withLlmCall, withProcessSpan, withRuntimeOperation } from '@autter/runtime-node';
1
+ export { createAutterRelayRoute, registerAutter, withRuntimeRequest } from './server.js';
2
+ export { AutoFlushHandle, AutoFlushOptions, AutterErrorHandlerOptions, AutterErrorResponseOptions, AutterLogging, AutterLoggingOptions, AutterRequestsOptions, AutterServer, AutterServerOptions, Breadcrumb, BreadcrumbInput, CODE_PATTERN, ClientErrorBody, ConsoleSinkOptions, FileSinkOptions, FlushTarget, InstrumentLlmOptions, LlmCallHandle, LlmCallInfo, LlmUsage, OtlpSinkOptions, RedactOptions, RelayOptions, RuntimeCarrier, RuntimeContextHandle, RuntimeEnrichContext, RuntimeEnrichEvent, RuntimeEnricher, RuntimeError, RuntimeErrorCatalog, RuntimeErrorDefinition, RuntimeErrorExtras, RuntimeErrorFactory, RuntimeErrorLike, RuntimeErrorOptions, RuntimeEvent, RuntimeLogContext, RuntimeLogContextValue, RuntimeLogLevel, RuntimeLoggingOptions, RuntimeOperation, RuntimeOperationKind, RuntimeOperationOptions, RuntimeOutcome, RuntimeRequestOptions, RuntimeSink, RuntimeSinkContext, SafeCapture, TrackedLlmCall, addBreadcrumb, autterErrorHandler, autterErrorResponse, autterFastify, autterFastifyErrors, autterKoa, autterRequests, captureRequestError, captureException as captureServerException, captureMessage as captureServerMessage, consoleSink, createRuntimeLogger, defineRuntimeErrors, emitLlmSelftestTrace, enrichDeployment, enrichEdgeGeo, enrichRequestSize, enrichUserAgent, errorAttributes, fileSink, flushRuntimeLogs, initAutterLogging, installAutterAutoFlush, instrumentLlmClient, isRuntimeErrorLike, makeSafeCapture, otlpSink, redactAttributes, redactText, reportOutcome as reportServerOutcome, runInBackground, runtimeContext, runtimeLogStats, runtimeLogger, toClientError, trackLlmCall, withLlmCall, withProcessSpan, withRuntimeOperation } from '@autter/runtime-node';
package/dist/index.js CHANGED
@@ -1,40 +1,92 @@
1
1
  import {
2
+ CODE_PATTERN,
3
+ RuntimeError,
4
+ addBreadcrumb,
5
+ autterErrorHandler,
6
+ autterErrorResponse,
7
+ autterFastify,
8
+ autterFastifyErrors,
9
+ autterKoa,
10
+ autterRequests,
2
11
  captureException,
3
12
  captureMessage,
13
+ captureRequestError,
14
+ consoleSink,
4
15
  createAutterRelayRoute,
5
16
  createRuntimeLogger,
17
+ defineRuntimeErrors,
6
18
  emitLlmSelftestTrace,
19
+ enrichDeployment,
20
+ enrichEdgeGeo,
21
+ enrichRequestSize,
22
+ enrichUserAgent,
23
+ errorAttributes,
24
+ fileSink,
7
25
  flushRuntimeLogs,
26
+ initAutterLogging,
8
27
  installAutterAutoFlush,
9
28
  instrumentLlmClient,
29
+ isRuntimeErrorLike,
10
30
  makeSafeCapture,
31
+ otlpSink,
11
32
  redactAttributes,
33
+ redactText,
12
34
  registerAutter,
13
35
  reportOutcome,
36
+ runInBackground,
37
+ runtimeContext,
14
38
  runtimeLogStats,
15
39
  runtimeLogger,
40
+ toClientError,
16
41
  trackLlmCall,
17
42
  withLlmCall,
18
43
  withProcessSpan,
19
- withRuntimeOperation
20
- } from "./chunk-NZPBSB6B.js";
44
+ withRuntimeOperation,
45
+ withRuntimeRequest
46
+ } from "./chunk-QFEFRAVO.js";
21
47
  export {
48
+ CODE_PATTERN,
49
+ RuntimeError,
50
+ addBreadcrumb,
51
+ autterErrorHandler,
52
+ autterErrorResponse,
53
+ autterFastify,
54
+ autterFastifyErrors,
55
+ autterKoa,
56
+ autterRequests,
57
+ captureRequestError,
22
58
  captureException as captureServerException,
23
59
  captureMessage as captureServerMessage,
60
+ consoleSink,
24
61
  createAutterRelayRoute,
25
62
  createRuntimeLogger,
63
+ defineRuntimeErrors,
26
64
  emitLlmSelftestTrace,
65
+ enrichDeployment,
66
+ enrichEdgeGeo,
67
+ enrichRequestSize,
68
+ enrichUserAgent,
69
+ errorAttributes,
70
+ fileSink,
27
71
  flushRuntimeLogs,
72
+ initAutterLogging,
28
73
  installAutterAutoFlush,
29
74
  instrumentLlmClient,
75
+ isRuntimeErrorLike,
30
76
  makeSafeCapture,
77
+ otlpSink,
31
78
  redactAttributes,
79
+ redactText,
32
80
  registerAutter,
33
81
  reportOutcome as reportServerOutcome,
82
+ runInBackground,
83
+ runtimeContext,
34
84
  runtimeLogStats,
35
85
  runtimeLogger,
86
+ toClientError,
36
87
  trackLlmCall,
37
88
  withLlmCall,
38
89
  withProcessSpan,
39
- withRuntimeOperation
90
+ withRuntimeOperation,
91
+ withRuntimeRequest
40
92
  };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/instrumentation-edge.ts
21
+ var instrumentation_edge_exports = {};
22
+ __export(instrumentation_edge_exports, {
23
+ autterOnRequestError: () => autterOnRequestError,
24
+ onRequestError: () => onRequestError
25
+ });
26
+ module.exports = __toCommonJS(instrumentation_edge_exports);
27
+
28
+ // src/request-error.ts
29
+ var import_runtime_edge = require("@autter/runtime-edge");
30
+ var CONTROL_FLOW_DIGEST = /^(?:NEXT_REDIRECT|NEXT_NOT_FOUND|NEXT_HTTP_ERROR_FALLBACK|DYNAMIC_SERVER_USAGE|BAILOUT_TO_CLIENT_SIDE_RENDERING)\b/;
31
+ function digestOf(error) {
32
+ try {
33
+ const digest = error?.digest;
34
+ return typeof digest === "string" ? digest : "";
35
+ } catch {
36
+ return "";
37
+ }
38
+ }
39
+ function shouldReport(error, rule) {
40
+ if (rule === true) return true;
41
+ if (rule === false) return false;
42
+ if (typeof rule === "function") {
43
+ try {
44
+ return rule(error) === true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+ return !CONTROL_FLOW_DIGEST.test(digestOf(error));
50
+ }
51
+ function requestErrorAttributes(error, request, context) {
52
+ const out = {};
53
+ const put = (key, read, max) => {
54
+ try {
55
+ const value = read();
56
+ if (typeof value === "string" && value) out[key] = value.slice(0, max);
57
+ } catch {
58
+ }
59
+ };
60
+ put("next.route_path", () => context?.routePath, 500);
61
+ put("next.router_kind", () => context?.routerKind, 40);
62
+ put("next.route_type", () => context?.routeType, 40);
63
+ put("next.render_source", () => context?.renderSource, 80);
64
+ put("next.render_type", () => context?.renderType, 40);
65
+ put("next.revalidate_reason", () => context?.revalidateReason, 40);
66
+ put("next.digest", () => digestOf(error), 100);
67
+ put("http.request.method", () => {
68
+ const method = request?.method;
69
+ return typeof method === "string" ? method.toUpperCase() : void 0;
70
+ }, 16);
71
+ put("url.path", () => {
72
+ const path = request?.path;
73
+ return typeof path === "string" ? path.split(/[?#]/)[0] ?? "" : void 0;
74
+ }, 1e3);
75
+ return out;
76
+ }
77
+ var warnedNoEdgeOptions = false;
78
+ function nextWaitUntil() {
79
+ try {
80
+ const store = globalThis[/* @__PURE__ */ Symbol.for("@next/request-context")];
81
+ const context = typeof store?.get === "function" ? store.get() : void 0;
82
+ const waitUntil = context?.waitUntil;
83
+ if (typeof waitUntil !== "function") return void 0;
84
+ return (promise) => waitUntil.call(context, promise);
85
+ } catch {
86
+ return void 0;
87
+ }
88
+ }
89
+ async function reportOnEdge(edge, error, attributes) {
90
+ const options = typeof edge === "function" ? edge() : edge;
91
+ if (!options) {
92
+ if (!warnedNoEdgeOptions) {
93
+ warnedNoEdgeOptions = true;
94
+ console.warn(
95
+ "[autter-runtime] onRequestError ran on the edge runtime without edge options; use autterOnRequestError({ edge: { apiKey, service } }) to report edge errors"
96
+ );
97
+ }
98
+ return;
99
+ }
100
+ const delivery = (0, import_runtime_edge.captureEdgeException)(options, error, attributes);
101
+ try {
102
+ nextWaitUntil()?.(delivery);
103
+ } catch {
104
+ }
105
+ await delivery;
106
+ }
107
+
108
+ // src/instrumentation-edge.ts
109
+ function autterOnRequestError(options = {}) {
110
+ return async function onRequestError2(error, request, context) {
111
+ try {
112
+ if (!shouldReport(error, options.capture)) return;
113
+ await reportOnEdge(options.edge, error, requestErrorAttributes(error, request, context));
114
+ } catch {
115
+ }
116
+ };
117
+ }
118
+ var onRequestError = autterOnRequestError();
@@ -0,0 +1,16 @@
1
+ import { A as AutterOnRequestErrorOptions, N as NextOnRequestError } from './request-error-DzJdPaVe.cjs';
2
+ export { a as NextRequestErrorContext, b as NextRequestErrorRequest } from './request-error-DzJdPaVe.cjs';
3
+ import '@autter/runtime-edge';
4
+
5
+ /**
6
+ * Edge build of `@autter/runtime-next/instrumentation`, picked by bundlers
7
+ * through the `edge-light` / `worker` export conditions (Next.js edge
8
+ * runtime). Same API as the default build, but it never references
9
+ * @autter/runtime-node or any Node module: errors are always sent over
10
+ * `/v1/logs` with the `edge` options.
11
+ */
12
+
13
+ declare function autterOnRequestError(options?: AutterOnRequestErrorOptions): NextOnRequestError;
14
+ declare const onRequestError: NextOnRequestError;
15
+
16
+ export { AutterOnRequestErrorOptions, NextOnRequestError, autterOnRequestError, onRequestError };
@@ -0,0 +1,16 @@
1
+ import { A as AutterOnRequestErrorOptions, N as NextOnRequestError } from './request-error-DzJdPaVe.js';
2
+ export { a as NextRequestErrorContext, b as NextRequestErrorRequest } from './request-error-DzJdPaVe.js';
3
+ import '@autter/runtime-edge';
4
+
5
+ /**
6
+ * Edge build of `@autter/runtime-next/instrumentation`, picked by bundlers
7
+ * through the `edge-light` / `worker` export conditions (Next.js edge
8
+ * runtime). Same API as the default build, but it never references
9
+ * @autter/runtime-node or any Node module: errors are always sent over
10
+ * `/v1/logs` with the `edge` options.
11
+ */
12
+
13
+ declare function autterOnRequestError(options?: AutterOnRequestErrorOptions): NextOnRequestError;
14
+ declare const onRequestError: NextOnRequestError;
15
+
16
+ export { AutterOnRequestErrorOptions, NextOnRequestError, autterOnRequestError, onRequestError };
@@ -0,0 +1,21 @@
1
+ import {
2
+ reportOnEdge,
3
+ requestErrorAttributes,
4
+ shouldReport
5
+ } from "./chunk-CL2ENM4A.js";
6
+
7
+ // src/instrumentation-edge.ts
8
+ function autterOnRequestError(options = {}) {
9
+ return async function onRequestError2(error, request, context) {
10
+ try {
11
+ if (!shouldReport(error, options.capture)) return;
12
+ await reportOnEdge(options.edge, error, requestErrorAttributes(error, request, context));
13
+ } catch {
14
+ }
15
+ };
16
+ }
17
+ var onRequestError = autterOnRequestError();
18
+ export {
19
+ autterOnRequestError,
20
+ onRequestError
21
+ };
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/instrumentation.ts
31
+ var instrumentation_exports = {};
32
+ __export(instrumentation_exports, {
33
+ autterOnRequestError: () => autterOnRequestError,
34
+ onRequestError: () => onRequestError
35
+ });
36
+ module.exports = __toCommonJS(instrumentation_exports);
37
+
38
+ // src/request-error.ts
39
+ var import_runtime_edge = require("@autter/runtime-edge");
40
+ var CONTROL_FLOW_DIGEST = /^(?:NEXT_REDIRECT|NEXT_NOT_FOUND|NEXT_HTTP_ERROR_FALLBACK|DYNAMIC_SERVER_USAGE|BAILOUT_TO_CLIENT_SIDE_RENDERING)\b/;
41
+ function digestOf(error) {
42
+ try {
43
+ const digest = error?.digest;
44
+ return typeof digest === "string" ? digest : "";
45
+ } catch {
46
+ return "";
47
+ }
48
+ }
49
+ function shouldReport(error, rule) {
50
+ if (rule === true) return true;
51
+ if (rule === false) return false;
52
+ if (typeof rule === "function") {
53
+ try {
54
+ return rule(error) === true;
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
59
+ return !CONTROL_FLOW_DIGEST.test(digestOf(error));
60
+ }
61
+ function requestErrorAttributes(error, request, context) {
62
+ const out = {};
63
+ const put = (key, read, max) => {
64
+ try {
65
+ const value = read();
66
+ if (typeof value === "string" && value) out[key] = value.slice(0, max);
67
+ } catch {
68
+ }
69
+ };
70
+ put("next.route_path", () => context?.routePath, 500);
71
+ put("next.router_kind", () => context?.routerKind, 40);
72
+ put("next.route_type", () => context?.routeType, 40);
73
+ put("next.render_source", () => context?.renderSource, 80);
74
+ put("next.render_type", () => context?.renderType, 40);
75
+ put("next.revalidate_reason", () => context?.revalidateReason, 40);
76
+ put("next.digest", () => digestOf(error), 100);
77
+ put("http.request.method", () => {
78
+ const method = request?.method;
79
+ return typeof method === "string" ? method.toUpperCase() : void 0;
80
+ }, 16);
81
+ put("url.path", () => {
82
+ const path = request?.path;
83
+ return typeof path === "string" ? path.split(/[?#]/)[0] ?? "" : void 0;
84
+ }, 1e3);
85
+ return out;
86
+ }
87
+ var warnedNoEdgeOptions = false;
88
+ function nextWaitUntil() {
89
+ try {
90
+ const store = globalThis[/* @__PURE__ */ Symbol.for("@next/request-context")];
91
+ const context = typeof store?.get === "function" ? store.get() : void 0;
92
+ const waitUntil = context?.waitUntil;
93
+ if (typeof waitUntil !== "function") return void 0;
94
+ return (promise) => waitUntil.call(context, promise);
95
+ } catch {
96
+ return void 0;
97
+ }
98
+ }
99
+ async function reportOnEdge(edge, error, attributes) {
100
+ const options = typeof edge === "function" ? edge() : edge;
101
+ if (!options) {
102
+ if (!warnedNoEdgeOptions) {
103
+ warnedNoEdgeOptions = true;
104
+ console.warn(
105
+ "[autter-runtime] onRequestError ran on the edge runtime without edge options; use autterOnRequestError({ edge: { apiKey, service } }) to report edge errors"
106
+ );
107
+ }
108
+ return;
109
+ }
110
+ const delivery = (0, import_runtime_edge.captureEdgeException)(options, error, attributes);
111
+ try {
112
+ nextWaitUntil()?.(delivery);
113
+ } catch {
114
+ }
115
+ await delivery;
116
+ }
117
+
118
+ // src/instrumentation.ts
119
+ function autterOnRequestError(options = {}) {
120
+ return async function onRequestError2(error, request, context) {
121
+ try {
122
+ if (!shouldReport(error, options.capture)) return;
123
+ const attributes = requestErrorAttributes(error, request, context);
124
+ if (typeof process === "undefined") {
125
+ await reportOnEdge(options.edge, error, attributes);
126
+ return;
127
+ }
128
+ if (process.env.NEXT_RUNTIME === "edge") {
129
+ await reportOnEdge(options.edge, error, attributes);
130
+ } else {
131
+ const node = await Promise.resolve().then(() => __toESM(require("@autter/runtime-node"), 1));
132
+ (node.captureRequestError ?? node.captureException)(error, attributes);
133
+ }
134
+ } catch {
135
+ }
136
+ };
137
+ }
138
+ var onRequestError = autterOnRequestError();