@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.
@@ -0,0 +1,39 @@
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
+ * `@autter/runtime-next/instrumentation` — Next.js `onRequestError` (Next 15+).
7
+ * Errors Next catches in server components, server actions, route handlers
8
+ * and middleware are reported with their stack and Next's context, instead
9
+ * of arriving as stackless 500s:
10
+ *
11
+ * // instrumentation.ts
12
+ * export { onRequestError } from "@autter/runtime-next/instrumentation";
13
+ *
14
+ * Safe for both runtimes Next compiles `instrumentation.ts` for:
15
+ *
16
+ * - Node: records the error on the request's span through the tracker that
17
+ * `registerAutter` started (`captureRequestError`). @autter/runtime-node is
18
+ * imported lazily, inside a `process.env.NEXT_RUNTIME` branch Next removes
19
+ * from edge bundles.
20
+ * - Edge: the package's `edge-light`/`worker` export condition resolves to an
21
+ * edge-only build that never references Node code; errors go to `/v1/logs`
22
+ * with the `edge` options (see `autterOnRequestError`).
23
+ */
24
+
25
+ /**
26
+ * Build an `onRequestError` with options:
27
+ *
28
+ * export const onRequestError = autterOnRequestError({
29
+ * edge: { apiKey: process.env.AUTTER_RUNTIME_KEY, service: "web-app" },
30
+ * });
31
+ *
32
+ * Never throws into Next.
33
+ */
34
+ declare function autterOnRequestError(options?: AutterOnRequestErrorOptions): NextOnRequestError;
35
+ /** Ready-made `onRequestError`: Node errors go to the `registerAutter`
36
+ * tracker; on the edge it needs `autterOnRequestError({ edge })`. */
37
+ declare const onRequestError: NextOnRequestError;
38
+
39
+ export { AutterOnRequestErrorOptions, NextOnRequestError, autterOnRequestError, onRequestError };
@@ -0,0 +1,39 @@
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
+ * `@autter/runtime-next/instrumentation` — Next.js `onRequestError` (Next 15+).
7
+ * Errors Next catches in server components, server actions, route handlers
8
+ * and middleware are reported with their stack and Next's context, instead
9
+ * of arriving as stackless 500s:
10
+ *
11
+ * // instrumentation.ts
12
+ * export { onRequestError } from "@autter/runtime-next/instrumentation";
13
+ *
14
+ * Safe for both runtimes Next compiles `instrumentation.ts` for:
15
+ *
16
+ * - Node: records the error on the request's span through the tracker that
17
+ * `registerAutter` started (`captureRequestError`). @autter/runtime-node is
18
+ * imported lazily, inside a `process.env.NEXT_RUNTIME` branch Next removes
19
+ * from edge bundles.
20
+ * - Edge: the package's `edge-light`/`worker` export condition resolves to an
21
+ * edge-only build that never references Node code; errors go to `/v1/logs`
22
+ * with the `edge` options (see `autterOnRequestError`).
23
+ */
24
+
25
+ /**
26
+ * Build an `onRequestError` with options:
27
+ *
28
+ * export const onRequestError = autterOnRequestError({
29
+ * edge: { apiKey: process.env.AUTTER_RUNTIME_KEY, service: "web-app" },
30
+ * });
31
+ *
32
+ * Never throws into Next.
33
+ */
34
+ declare function autterOnRequestError(options?: AutterOnRequestErrorOptions): NextOnRequestError;
35
+ /** Ready-made `onRequestError`: Node errors go to the `registerAutter`
36
+ * tracker; on the edge it needs `autterOnRequestError({ edge })`. */
37
+ declare const onRequestError: NextOnRequestError;
38
+
39
+ export { AutterOnRequestErrorOptions, NextOnRequestError, autterOnRequestError, onRequestError };
@@ -0,0 +1,31 @@
1
+ import {
2
+ reportOnEdge,
3
+ requestErrorAttributes,
4
+ shouldReport
5
+ } from "./chunk-CL2ENM4A.js";
6
+
7
+ // src/instrumentation.ts
8
+ function autterOnRequestError(options = {}) {
9
+ return async function onRequestError2(error, request, context) {
10
+ try {
11
+ if (!shouldReport(error, options.capture)) return;
12
+ const attributes = requestErrorAttributes(error, request, context);
13
+ if (typeof process === "undefined") {
14
+ await reportOnEdge(options.edge, error, attributes);
15
+ return;
16
+ }
17
+ if (process.env.NEXT_RUNTIME === "edge") {
18
+ await reportOnEdge(options.edge, error, attributes);
19
+ } else {
20
+ const node = await import("@autter/runtime-node");
21
+ (node.captureRequestError ?? node.captureException)(error, attributes);
22
+ }
23
+ } catch {
24
+ }
25
+ };
26
+ }
27
+ var onRequestError = autterOnRequestError();
28
+ export {
29
+ autterOnRequestError,
30
+ onRequestError
31
+ };
@@ -0,0 +1,55 @@
1
+ import { AutterEdgeOptions } from '@autter/runtime-edge';
2
+
3
+ /**
4
+ * Shared, runtime-neutral half of Next.js `onRequestError` support. Imports
5
+ * only @autter/runtime-edge (no Node modules), so it is safe in the edge
6
+ * bundle; the Node half lives behind a dynamic import in instrumentation.ts.
7
+ */
8
+
9
+ /** Next.js `onRequestError` request argument (typed structurally; no `next` dependency). */
10
+ interface NextRequestErrorRequest {
11
+ /** Resource path, e.g. `/blog?name=foo` — recorded without the query string. */
12
+ path?: string;
13
+ method?: string;
14
+ /** Never read: cookies and auth headers stay out of telemetry. */
15
+ headers?: unknown;
16
+ }
17
+ /** Next.js `onRequestError` context argument. */
18
+ interface NextRequestErrorContext {
19
+ /** `"App Router"` or `"Pages Router"` (also what Next passes for middleware and edge route handlers). */
20
+ routerKind?: string;
21
+ /**
22
+ * The route template, e.g. `/blog/[slug]` or `/api/orders`. Middleware:
23
+ * `/middleware` (Next 15) or `/proxy` (Next 16). An edge route handler
24
+ * reported by `next start`: the page, e.g. `/api/orders/route`.
25
+ */
26
+ routePath?: string;
27
+ /** `"render"`, `"route"`, `"action"`, `"middleware"` (Next 15) or `"proxy"` (Next 16). */
28
+ routeType?: string;
29
+ /** `"react-server-components"`, `"react-server-components-payload"` or `"server-rendering"`. */
30
+ renderSource?: string;
31
+ /** `"on-demand"`, `"stale"` or undefined (a normal request). */
32
+ revalidateReason?: string;
33
+ /** `"dynamic"` or `"dynamic-resume"` (PPR). */
34
+ renderType?: string;
35
+ }
36
+ /** The function Next.js calls from `instrumentation.ts`. */
37
+ type NextOnRequestError = (error: unknown, request: NextRequestErrorRequest, context: NextRequestErrorContext) => Promise<void>;
38
+ interface AutterOnRequestErrorOptions {
39
+ /**
40
+ * Which errors to report. Default: every error except Next's control-flow
41
+ * signals (`redirect()`, `notFound()`, `forbidden()`, `unauthorized()`,
42
+ * dynamic-rendering bailouts). `true` reports everything; a predicate
43
+ * decides per error.
44
+ */
45
+ capture?: boolean | ((error: unknown) => boolean);
46
+ /**
47
+ * Edge runtime only (middleware, `export const runtime = "edge"`): the
48
+ * Node tracker does not run there, so errors are sent straight to the
49
+ * ingester's `/v1/logs` with these options — a SERVER key. A function is
50
+ * called per error. Without it, edge errors are skipped (one warning).
51
+ */
52
+ edge?: AutterEdgeOptions | (() => AutterEdgeOptions | undefined);
53
+ }
54
+
55
+ export type { AutterOnRequestErrorOptions as A, NextOnRequestError as N, NextRequestErrorContext as a, NextRequestErrorRequest as b };
@@ -0,0 +1,55 @@
1
+ import { AutterEdgeOptions } from '@autter/runtime-edge';
2
+
3
+ /**
4
+ * Shared, runtime-neutral half of Next.js `onRequestError` support. Imports
5
+ * only @autter/runtime-edge (no Node modules), so it is safe in the edge
6
+ * bundle; the Node half lives behind a dynamic import in instrumentation.ts.
7
+ */
8
+
9
+ /** Next.js `onRequestError` request argument (typed structurally; no `next` dependency). */
10
+ interface NextRequestErrorRequest {
11
+ /** Resource path, e.g. `/blog?name=foo` — recorded without the query string. */
12
+ path?: string;
13
+ method?: string;
14
+ /** Never read: cookies and auth headers stay out of telemetry. */
15
+ headers?: unknown;
16
+ }
17
+ /** Next.js `onRequestError` context argument. */
18
+ interface NextRequestErrorContext {
19
+ /** `"App Router"` or `"Pages Router"` (also what Next passes for middleware and edge route handlers). */
20
+ routerKind?: string;
21
+ /**
22
+ * The route template, e.g. `/blog/[slug]` or `/api/orders`. Middleware:
23
+ * `/middleware` (Next 15) or `/proxy` (Next 16). An edge route handler
24
+ * reported by `next start`: the page, e.g. `/api/orders/route`.
25
+ */
26
+ routePath?: string;
27
+ /** `"render"`, `"route"`, `"action"`, `"middleware"` (Next 15) or `"proxy"` (Next 16). */
28
+ routeType?: string;
29
+ /** `"react-server-components"`, `"react-server-components-payload"` or `"server-rendering"`. */
30
+ renderSource?: string;
31
+ /** `"on-demand"`, `"stale"` or undefined (a normal request). */
32
+ revalidateReason?: string;
33
+ /** `"dynamic"` or `"dynamic-resume"` (PPR). */
34
+ renderType?: string;
35
+ }
36
+ /** The function Next.js calls from `instrumentation.ts`. */
37
+ type NextOnRequestError = (error: unknown, request: NextRequestErrorRequest, context: NextRequestErrorContext) => Promise<void>;
38
+ interface AutterOnRequestErrorOptions {
39
+ /**
40
+ * Which errors to report. Default: every error except Next's control-flow
41
+ * signals (`redirect()`, `notFound()`, `forbidden()`, `unauthorized()`,
42
+ * dynamic-rendering bailouts). `true` reports everything; a predicate
43
+ * decides per error.
44
+ */
45
+ capture?: boolean | ((error: unknown) => boolean);
46
+ /**
47
+ * Edge runtime only (middleware, `export const runtime = "edge"`): the
48
+ * Node tracker does not run there, so errors are sent straight to the
49
+ * ingester's `/v1/logs` with these options — a SERVER key. A function is
50
+ * called per error. Without it, edge errors are skipped (one warning).
51
+ */
52
+ edge?: AutterEdgeOptions | (() => AutterEdgeOptions | undefined);
53
+ }
54
+
55
+ export type { AutterOnRequestErrorOptions as A, NextOnRequestError as N, NextRequestErrorContext as a, NextRequestErrorRequest as b };
package/dist/server.cjs CHANGED
@@ -20,52 +20,229 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/server.ts
21
21
  var server_exports = {};
22
22
  __export(server_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(server_exports);
43
69
  var import_runtime_node = require("@autter/runtime-node");
70
+
71
+ // package.json
72
+ var package_default = {
73
+ name: "@autter/runtime-next",
74
+ version: "1.6.0",
75
+ 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",
76
+ license: "MIT",
77
+ type: "module",
78
+ main: "./dist/index.cjs",
79
+ module: "./dist/index.js",
80
+ types: "./dist/index.d.ts",
81
+ exports: {
82
+ ".": {
83
+ types: "./dist/index.d.ts",
84
+ import: "./dist/index.js",
85
+ require: "./dist/index.cjs"
86
+ },
87
+ "./server": {
88
+ types: "./dist/server.d.ts",
89
+ import: "./dist/server.js",
90
+ require: "./dist/server.cjs"
91
+ },
92
+ "./client": {
93
+ types: "./dist/client.d.ts",
94
+ import: "./dist/client.js",
95
+ require: "./dist/client.cjs"
96
+ },
97
+ "./edge": {
98
+ types: "./dist/edge.d.ts",
99
+ import: "./dist/edge.js",
100
+ require: "./dist/edge.cjs"
101
+ },
102
+ "./instrumentation": {
103
+ types: "./dist/instrumentation.d.ts",
104
+ "edge-light": {
105
+ import: "./dist/instrumentation-edge.js",
106
+ require: "./dist/instrumentation-edge.cjs"
107
+ },
108
+ worker: {
109
+ import: "./dist/instrumentation-edge.js",
110
+ require: "./dist/instrumentation-edge.cjs"
111
+ },
112
+ import: "./dist/instrumentation.js",
113
+ require: "./dist/instrumentation.cjs"
114
+ }
115
+ },
116
+ files: [
117
+ "dist"
118
+ ],
119
+ repository: {
120
+ type: "git",
121
+ url: "https://github.com/Autter-dev/autter-runtime.git",
122
+ directory: "packages/runtime-next"
123
+ },
124
+ scripts: {
125
+ build: `node ../../scripts/ensure-built.mjs runtime-node runtime-edge runtime-browser && node -e "require('node:fs').rmSync('dist',{recursive:true,force:true})" && tsup`,
126
+ 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"
127
+ },
128
+ dependencies: {
129
+ "@autter/runtime-browser": "^1.6.0",
130
+ "@autter/runtime-edge": "^1.1.0",
131
+ "@autter/runtime-node": "^1.6.0"
132
+ },
133
+ peerDependencies: {
134
+ react: ">=18"
135
+ },
136
+ devDependencies: {
137
+ "@types/react": "^18.3.0",
138
+ tsup: "^8.3.5",
139
+ typescript: "^5.7.0"
140
+ },
141
+ engines: {
142
+ node: ">=20"
143
+ },
144
+ publishConfig: {
145
+ access: "public",
146
+ provenance: true
147
+ },
148
+ homepage: "https://github.com/Autter-dev/autter-runtime#readme",
149
+ bugs: "https://github.com/Autter-dev/autter-runtime/issues",
150
+ keywords: [
151
+ "nextjs",
152
+ "error-tracking",
153
+ "telemetry",
154
+ "opentelemetry",
155
+ "react",
156
+ "error-boundary"
157
+ ]
158
+ };
159
+
160
+ // src/server.ts
44
161
  var import_runtime_node2 = require("@autter/runtime-node");
45
162
  function registerAutter(options) {
46
- return (0, import_runtime_node.initAutterServer)(options);
163
+ return (0, import_runtime_node.initAutterServer)({
164
+ distro: { name: "@autter/runtime-next", version: package_default.version },
165
+ ...options
166
+ });
47
167
  }
48
168
  function createAutterRelayRoute(options) {
49
169
  return { POST: (0, import_runtime_node.createBrowserRelayFetchHandler)(options) };
50
170
  }
171
+ var after;
172
+ var afterReady = (async () => {
173
+ try {
174
+ const specifier = "next/server";
175
+ const mod = await import(
176
+ /* webpackIgnore: true */
177
+ specifier
178
+ );
179
+ after = mod.after ?? mod.unstable_after ?? null;
180
+ } catch {
181
+ after = null;
182
+ }
183
+ return after;
184
+ })();
185
+ function scheduleAfter(promise) {
186
+ const run = (fn) => {
187
+ if (!fn) return;
188
+ try {
189
+ fn(promise);
190
+ } catch {
191
+ }
192
+ };
193
+ if (after !== void 0) run(after);
194
+ else void afterReady.then(run);
195
+ }
196
+ function withRuntimeRequest(handler, options = {}) {
197
+ return (0, import_runtime_node.withRuntimeRequest)(handler, {
198
+ ...options,
199
+ waitUntil: options.waitUntil ?? scheduleAfter
200
+ });
201
+ }
51
202
  // Annotate the CommonJS export names for ESM import in node:
52
203
  0 && (module.exports = {
204
+ CODE_PATTERN,
205
+ RuntimeError,
206
+ addBreadcrumb,
207
+ autterErrorHandler,
208
+ autterErrorResponse,
209
+ autterFastify,
210
+ autterFastifyErrors,
211
+ autterKoa,
212
+ autterRequests,
213
+ captureRequestError,
53
214
  captureServerException,
54
215
  captureServerMessage,
216
+ consoleSink,
55
217
  createAutterRelayRoute,
56
218
  createRuntimeLogger,
219
+ defineRuntimeErrors,
57
220
  emitLlmSelftestTrace,
221
+ enrichDeployment,
222
+ enrichEdgeGeo,
223
+ enrichRequestSize,
224
+ enrichUserAgent,
225
+ errorAttributes,
226
+ fileSink,
58
227
  flushRuntimeLogs,
228
+ initAutterLogging,
59
229
  installAutterAutoFlush,
60
230
  instrumentLlmClient,
231
+ isRuntimeErrorLike,
61
232
  makeSafeCapture,
233
+ otlpSink,
62
234
  redactAttributes,
235
+ redactText,
63
236
  registerAutter,
64
237
  reportServerOutcome,
238
+ runInBackground,
239
+ runtimeContext,
65
240
  runtimeLogStats,
66
241
  runtimeLogger,
242
+ toClientError,
67
243
  trackLlmCall,
68
244
  withLlmCall,
69
245
  withProcessSpan,
70
- withRuntimeOperation
246
+ withRuntimeOperation,
247
+ withRuntimeRequest
71
248
  });
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { RelayOptions, AutterServerOptions, AutterServer } from '@autter/runtime-node';
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
+ import { RelayOptions, AutterServerOptions, AutterServer, RuntimeRequestOptions } from '@autter/runtime-node';
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';
3
3
 
4
4
  /**
5
5
  * Server half of @autter/runtime-next. Safe to import anywhere Node runs:
@@ -25,7 +25,18 @@ export { AutoFlushHandle, AutoFlushOptions, AutterServer, AutterServerOptions, F
25
25
  * apiKey: process.env.AUTTER_RUNTIME_KEY!,
26
26
  * });
27
27
  *
28
- * Browser tracker + error boundary live in `@autter/runtime-next/client`.
28
+ * 3. Route handlers as request wide events (1.5.0):
29
+ *
30
+ * import { withRuntimeRequest, runtimeContext } from "@autter/runtime-next";
31
+ * export const POST = withRuntimeRequest(async (request) => {
32
+ * runtimeContext.set({ cart: { items: 3 } });
33
+ * return Response.json({ ok: true });
34
+ * }, { name: "checkout" });
35
+ *
36
+ * The log flush is handed to Next's `after()` automatically.
37
+ *
38
+ * Browser tracker + error boundary live in `@autter/runtime-next/client`;
39
+ * `middleware.ts` (edge runtime) uses `@autter/runtime-next/edge`.
29
40
  */
30
41
 
31
42
  /** Server OTel init for Next.js `instrumentation.ts`. */
@@ -34,5 +45,11 @@ declare function registerAutter(options: AutterServerOptions): AutterServer;
34
45
  declare function createAutterRelayRoute(options: RelayOptions): {
35
46
  POST: (request: Request) => Promise<Response>;
36
47
  };
48
+ /**
49
+ * Next.js-aware `withRuntimeRequest`: identical to the runtime-node wrapper,
50
+ * but the log flush is handed to `after()` from `next/server` (Next 15+;
51
+ * `unstable_after` on 14.2) unless you pass your own `waitUntil`.
52
+ */
53
+ declare function withRuntimeRequest<A extends unknown[]>(handler: (request: Request, ...rest: A) => Response | Promise<Response>, options?: RuntimeRequestOptions): (request: Request, ...rest: A) => Promise<Response>;
37
54
 
38
- export { createAutterRelayRoute, registerAutter };
55
+ export { createAutterRelayRoute, registerAutter, withRuntimeRequest };
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { RelayOptions, AutterServerOptions, AutterServer } from '@autter/runtime-node';
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
+ import { RelayOptions, AutterServerOptions, AutterServer, RuntimeRequestOptions } from '@autter/runtime-node';
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';
3
3
 
4
4
  /**
5
5
  * Server half of @autter/runtime-next. Safe to import anywhere Node runs:
@@ -25,7 +25,18 @@ export { AutoFlushHandle, AutoFlushOptions, AutterServer, AutterServerOptions, F
25
25
  * apiKey: process.env.AUTTER_RUNTIME_KEY!,
26
26
  * });
27
27
  *
28
- * Browser tracker + error boundary live in `@autter/runtime-next/client`.
28
+ * 3. Route handlers as request wide events (1.5.0):
29
+ *
30
+ * import { withRuntimeRequest, runtimeContext } from "@autter/runtime-next";
31
+ * export const POST = withRuntimeRequest(async (request) => {
32
+ * runtimeContext.set({ cart: { items: 3 } });
33
+ * return Response.json({ ok: true });
34
+ * }, { name: "checkout" });
35
+ *
36
+ * The log flush is handed to Next's `after()` automatically.
37
+ *
38
+ * Browser tracker + error boundary live in `@autter/runtime-next/client`;
39
+ * `middleware.ts` (edge runtime) uses `@autter/runtime-next/edge`.
29
40
  */
30
41
 
31
42
  /** Server OTel init for Next.js `instrumentation.ts`. */
@@ -34,5 +45,11 @@ declare function registerAutter(options: AutterServerOptions): AutterServer;
34
45
  declare function createAutterRelayRoute(options: RelayOptions): {
35
46
  POST: (request: Request) => Promise<Response>;
36
47
  };
48
+ /**
49
+ * Next.js-aware `withRuntimeRequest`: identical to the runtime-node wrapper,
50
+ * but the log flush is handed to `after()` from `next/server` (Next 15+;
51
+ * `unstable_after` on 14.2) unless you pass your own `waitUntil`.
52
+ */
53
+ declare function withRuntimeRequest<A extends unknown[]>(handler: (request: Request, ...rest: A) => Response | Promise<Response>, options?: RuntimeRequestOptions): (request: Request, ...rest: A) => Promise<Response>;
37
54
 
38
- export { createAutterRelayRoute, registerAutter };
55
+ export { createAutterRelayRoute, registerAutter, withRuntimeRequest };
package/dist/server.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
  };