@autter/runtime-next 1.3.4 → 1.5.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/README.md CHANGED
@@ -92,3 +92,62 @@ calls with `experimental_telemetry: { isEnabled: true }` (and anything
92
92
  wrapped in `withLlmCall` or an `instrumentLlmClient` client) are recorded at
93
93
  100% — every call, with model, tokens, latency, and cost. See the
94
94
  [`@autter/runtime-node` README](../runtime-node) for the API.
95
+ ## Operation logging (1.4.0+)
96
+
97
+ Import `withRuntimeOperation`, `runtimeLogger`, `createRuntimeLogger`,
98
+ `flushRuntimeLogs`, and `runtimeLogStats` from `@autter/runtime-next/server`.
99
+ Initialize through the existing `registerAutter` call in `instrumentation.ts`.
100
+ These APIs require the Node runtime, a 1.4.0+ ingester, and matching platform
101
+ evidence support. Client components keep `@autter/runtime-next/client`.
102
+ See the [operation logging guide](../../docs/OPERATION-LOGGING.md) for measured
103
+ steps, explicit business outcomes, privacy and flushing. Ordinary error logs
104
+ are diagnostics; captured exceptions and declared failed outcomes use tracing
105
+ for issue grouping.
106
+
107
+ ## Requests, coded errors and edge middleware (1.5.0+)
108
+
109
+ Route handlers become request summaries (always kept, request id echoed in
110
+ `x-request-id`); the log flush is handed to Next's `after()` automatically
111
+ (Next 15+, `unstable_after` on 14.2):
112
+
113
+ ```ts
114
+ // app/api/checkout/route.ts
115
+ import { withRuntimeRequest, runtimeContext, defineRuntimeErrors, toClientError } from "@autter/runtime-next";
116
+
117
+ const billing = defineRuntimeErrors("billing", {
118
+ declined: { status: 402, message: "Payment declined", expected: true },
119
+ });
120
+
121
+ export const POST = withRuntimeRequest(async (request) => {
122
+ runtimeContext.set({ plan: "pro" });
123
+ const ok = await charge(await request.json());
124
+ if (!ok) {
125
+ const error = billing.declined();
126
+ return Response.json(toClientError(error, runtimeContext.requestId), { status: 402 });
127
+ }
128
+ return Response.json({ ok: true });
129
+ }, { name: "checkout" });
130
+ ```
131
+
132
+ Everything new in `@autter/runtime-node` 1.5.0 (`runtimeContext`,
133
+ `RuntimeError`, `defineRuntimeErrors`, `runInBackground`, `initAutterLogging`,
134
+ enrichers, sinks, …) is re-exported from `@autter/runtime-next` and
135
+ `/server`. `@autter/runtime-next/client` adds `autterErrorFromResponse`.
136
+
137
+ `middleware.ts` runs on the edge runtime — use `@autter/runtime-next/edge`
138
+ (re-exports [`@autter/runtime-edge`](../runtime-edge)):
139
+
140
+ ```ts
141
+ import { NextResponse } from "next/server";
142
+ import { withAutter } from "@autter/runtime-next/edge";
143
+
144
+ export default withAutter(
145
+ { apiKey: process.env.AUTTER_RUNTIME_KEY, service: "web-middleware" },
146
+ async (request, _event, _ctx, rt) => {
147
+ rt.set({ locale: request.headers.get("accept-language")?.slice(0, 2) });
148
+ return NextResponse.next();
149
+ },
150
+ );
151
+ ```
152
+
153
+ See [Requests, coded errors and background work](../../docs/REQUESTS-AND-ERRORS.md).
@@ -0,0 +1,204 @@
1
+ // src/server.ts
2
+ import {
3
+ createBrowserRelayFetchHandler,
4
+ initAutterServer,
5
+ withRuntimeRequest as nodeWithRuntimeRequest
6
+ } from "@autter/runtime-node";
7
+
8
+ // package.json
9
+ var package_default = {
10
+ name: "@autter/runtime-next",
11
+ version: "1.5.0",
12
+ 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",
13
+ license: "MIT",
14
+ type: "module",
15
+ main: "./dist/index.cjs",
16
+ module: "./dist/index.js",
17
+ types: "./dist/index.d.ts",
18
+ exports: {
19
+ ".": {
20
+ types: "./dist/index.d.ts",
21
+ import: "./dist/index.js",
22
+ require: "./dist/index.cjs"
23
+ },
24
+ "./server": {
25
+ types: "./dist/server.d.ts",
26
+ import: "./dist/server.js",
27
+ require: "./dist/server.cjs"
28
+ },
29
+ "./client": {
30
+ types: "./dist/client.d.ts",
31
+ import: "./dist/client.js",
32
+ require: "./dist/client.cjs"
33
+ },
34
+ "./edge": {
35
+ types: "./dist/edge.d.ts",
36
+ import: "./dist/edge.js",
37
+ require: "./dist/edge.cjs"
38
+ }
39
+ },
40
+ files: [
41
+ "dist"
42
+ ],
43
+ repository: {
44
+ type: "git",
45
+ url: "https://github.com/Autter-dev/autter-runtime.git",
46
+ directory: "packages/runtime-next"
47
+ },
48
+ scripts: {
49
+ build: `node ../../scripts/ensure-built.mjs runtime-node runtime-edge runtime-browser && node -e "require('node:fs').rmSync('dist',{recursive:true,force:true})" && tsup`,
50
+ 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"
51
+ },
52
+ dependencies: {
53
+ "@autter/runtime-browser": "^1.4.0",
54
+ "@autter/runtime-edge": "^1.0.0",
55
+ "@autter/runtime-node": "^1.5.0"
56
+ },
57
+ peerDependencies: {
58
+ react: ">=18"
59
+ },
60
+ devDependencies: {
61
+ "@types/react": "^18.3.0",
62
+ tsup: "^8.3.5",
63
+ typescript: "^5.7.0"
64
+ },
65
+ engines: {
66
+ node: ">=20"
67
+ },
68
+ publishConfig: {
69
+ access: "public",
70
+ provenance: true
71
+ },
72
+ homepage: "https://github.com/Autter-dev/autter-runtime#readme",
73
+ bugs: "https://github.com/Autter-dev/autter-runtime/issues",
74
+ keywords: [
75
+ "nextjs",
76
+ "error-tracking",
77
+ "telemetry",
78
+ "opentelemetry",
79
+ "react",
80
+ "error-boundary"
81
+ ]
82
+ };
83
+
84
+ // src/server.ts
85
+ import {
86
+ createRuntimeLogger,
87
+ runtimeLogger,
88
+ withRuntimeOperation,
89
+ flushRuntimeLogs,
90
+ runtimeLogStats,
91
+ captureException,
92
+ captureMessage,
93
+ reportOutcome,
94
+ withProcessSpan,
95
+ withLlmCall,
96
+ trackLlmCall,
97
+ instrumentLlmClient,
98
+ emitLlmSelftestTrace,
99
+ makeSafeCapture,
100
+ installAutterAutoFlush,
101
+ redactAttributes,
102
+ runtimeContext,
103
+ runInBackground,
104
+ autterRequests,
105
+ autterFastify,
106
+ autterErrorResponse,
107
+ RuntimeError,
108
+ defineRuntimeErrors,
109
+ isRuntimeErrorLike,
110
+ toClientError,
111
+ errorAttributes,
112
+ CODE_PATTERN,
113
+ initAutterLogging,
114
+ enrichUserAgent,
115
+ enrichRequestSize,
116
+ enrichEdgeGeo,
117
+ enrichDeployment,
118
+ otlpSink,
119
+ consoleSink,
120
+ fileSink,
121
+ redactText
122
+ } from "@autter/runtime-node";
123
+ function registerAutter(options) {
124
+ return initAutterServer({
125
+ distro: { name: "@autter/runtime-next", version: package_default.version },
126
+ ...options
127
+ });
128
+ }
129
+ function createAutterRelayRoute(options) {
130
+ return { POST: createBrowserRelayFetchHandler(options) };
131
+ }
132
+ var after;
133
+ var afterReady = (async () => {
134
+ try {
135
+ const specifier = "next/server";
136
+ const mod = await import(
137
+ /* webpackIgnore: true */
138
+ specifier
139
+ );
140
+ after = mod.after ?? mod.unstable_after ?? null;
141
+ } catch {
142
+ after = null;
143
+ }
144
+ return after;
145
+ })();
146
+ function scheduleAfter(promise) {
147
+ const run = (fn) => {
148
+ if (!fn) return;
149
+ try {
150
+ fn(promise);
151
+ } catch {
152
+ }
153
+ };
154
+ if (after !== void 0) run(after);
155
+ else void afterReady.then(run);
156
+ }
157
+ function withRuntimeRequest(handler, options = {}) {
158
+ return nodeWithRuntimeRequest(handler, {
159
+ ...options,
160
+ waitUntil: options.waitUntil ?? scheduleAfter
161
+ });
162
+ }
163
+
164
+ export {
165
+ registerAutter,
166
+ createAutterRelayRoute,
167
+ withRuntimeRequest,
168
+ createRuntimeLogger,
169
+ runtimeLogger,
170
+ withRuntimeOperation,
171
+ flushRuntimeLogs,
172
+ runtimeLogStats,
173
+ captureException,
174
+ captureMessage,
175
+ reportOutcome,
176
+ withProcessSpan,
177
+ withLlmCall,
178
+ trackLlmCall,
179
+ instrumentLlmClient,
180
+ emitLlmSelftestTrace,
181
+ makeSafeCapture,
182
+ installAutterAutoFlush,
183
+ redactAttributes,
184
+ runtimeContext,
185
+ runInBackground,
186
+ autterRequests,
187
+ autterFastify,
188
+ autterErrorResponse,
189
+ RuntimeError,
190
+ defineRuntimeErrors,
191
+ isRuntimeErrorLike,
192
+ toClientError,
193
+ errorAttributes,
194
+ CODE_PATTERN,
195
+ initAutterLogging,
196
+ enrichUserAgent,
197
+ enrichRequestSize,
198
+ enrichEdgeGeo,
199
+ enrichDeployment,
200
+ otlpSink,
201
+ consoleSink,
202
+ fileSink,
203
+ redactText
204
+ };
package/dist/client.cjs CHANGED
@@ -34,6 +34,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
34
34
  var client_exports = {};
35
35
  __export(client_exports, {
36
36
  AutterErrorBoundary: () => AutterErrorBoundary,
37
+ autterErrorFromResponse: () => import_runtime_browser2.autterErrorFromResponse,
37
38
  captureException: () => import_runtime_browser2.captureException,
38
39
  captureMessage: () => import_runtime_browser2.captureMessage,
39
40
  captureOutcome: () => import_runtime_browser2.captureOutcome,
@@ -76,6 +77,7 @@ var AutterErrorBoundary = class extends React.Component {
76
77
  // Annotate the CommonJS export names for ESM import in node:
77
78
  0 && (module.exports = {
78
79
  AutterErrorBoundary,
80
+ autterErrorFromResponse,
79
81
  captureException,
80
82
  captureMessage,
81
83
  captureOutcome,
@@ -0,0 +1,29 @@
1
+ export { AutterSeverity, autterErrorFromResponse, captureException, captureMessage, captureOutcome, flush, initAutterBrowser, setContext, setUser, trackEvent } from '@autter/runtime-browser';
2
+ import * as React from 'react';
3
+
4
+ /**
5
+ * React error boundary that reports render errors to Autter Runtime.
6
+ * React rendering errors do NOT hit `window.onerror`, so the browser
7
+ * tracker alone misses them — wrap your app:
8
+ *
9
+ * <AutterErrorBoundary fallback={<ErrorPage />}>
10
+ * <Application />
11
+ * </AutterErrorBoundary>
12
+ */
13
+ interface AutterErrorBoundaryProps {
14
+ fallback?: React.ReactNode;
15
+ /** Called after the error is reported (e.g. to show a toast). */
16
+ onError?: (error: Error, info: React.ErrorInfo) => void;
17
+ children?: React.ReactNode;
18
+ }
19
+ interface State {
20
+ hasError: boolean;
21
+ }
22
+ declare class AutterErrorBoundary extends React.Component<AutterErrorBoundaryProps, State> {
23
+ state: State;
24
+ static getDerivedStateFromError(): State;
25
+ componentDidCatch(error: Error, info: React.ErrorInfo): void;
26
+ render(): React.ReactNode;
27
+ }
28
+
29
+ export { AutterErrorBoundary, type AutterErrorBoundaryProps };
@@ -0,0 +1,29 @@
1
+ export { AutterSeverity, autterErrorFromResponse, captureException, captureMessage, captureOutcome, flush, initAutterBrowser, setContext, setUser, trackEvent } from '@autter/runtime-browser';
2
+ import * as React from 'react';
3
+
4
+ /**
5
+ * React error boundary that reports render errors to Autter Runtime.
6
+ * React rendering errors do NOT hit `window.onerror`, so the browser
7
+ * tracker alone misses them — wrap your app:
8
+ *
9
+ * <AutterErrorBoundary fallback={<ErrorPage />}>
10
+ * <Application />
11
+ * </AutterErrorBoundary>
12
+ */
13
+ interface AutterErrorBoundaryProps {
14
+ fallback?: React.ReactNode;
15
+ /** Called after the error is reported (e.g. to show a toast). */
16
+ onError?: (error: Error, info: React.ErrorInfo) => void;
17
+ children?: React.ReactNode;
18
+ }
19
+ interface State {
20
+ hasError: boolean;
21
+ }
22
+ declare class AutterErrorBoundary extends React.Component<AutterErrorBoundaryProps, State> {
23
+ state: State;
24
+ static getDerivedStateFromError(): State;
25
+ componentDidCatch(error: Error, info: React.ErrorInfo): void;
26
+ render(): React.ReactNode;
27
+ }
28
+
29
+ export { AutterErrorBoundary, type AutterErrorBoundaryProps };
package/dist/client.js CHANGED
@@ -12,7 +12,8 @@ import {
12
12
  trackEvent,
13
13
  setUser,
14
14
  setContext,
15
- flush
15
+ flush,
16
+ autterErrorFromResponse
16
17
  } from "@autter/runtime-browser";
17
18
 
18
19
  // src/error-boundary.ts
@@ -44,6 +45,7 @@ var AutterErrorBoundary = class extends React.Component {
44
45
  };
45
46
  export {
46
47
  AutterErrorBoundary,
48
+ autterErrorFromResponse,
47
49
  captureException2 as captureException,
48
50
  captureMessage,
49
51
  captureOutcome,
package/dist/edge.cjs ADDED
@@ -0,0 +1,20 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/edge.ts
18
+ var edge_exports = {};
19
+ module.exports = __toCommonJS(edge_exports);
20
+ __reExport(edge_exports, require("@autter/runtime-edge"), module.exports);
@@ -0,0 +1 @@
1
+ export * from '@autter/runtime-edge';
package/dist/edge.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@autter/runtime-edge';
package/dist/edge.js ADDED
@@ -0,0 +1,2 @@
1
+ // src/edge.ts
2
+ export * from "@autter/runtime-edge";
package/dist/index.cjs CHANGED
@@ -20,44 +20,208 @@ 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
+ autterErrorResponse: () => import_runtime_node2.autterErrorResponse,
26
+ autterFastify: () => import_runtime_node2.autterFastify,
27
+ autterRequests: () => import_runtime_node2.autterRequests,
23
28
  captureServerException: () => import_runtime_node2.captureException,
24
29
  captureServerMessage: () => import_runtime_node2.captureMessage,
30
+ consoleSink: () => import_runtime_node2.consoleSink,
25
31
  createAutterRelayRoute: () => createAutterRelayRoute,
32
+ createRuntimeLogger: () => import_runtime_node2.createRuntimeLogger,
33
+ defineRuntimeErrors: () => import_runtime_node2.defineRuntimeErrors,
26
34
  emitLlmSelftestTrace: () => import_runtime_node2.emitLlmSelftestTrace,
35
+ enrichDeployment: () => import_runtime_node2.enrichDeployment,
36
+ enrichEdgeGeo: () => import_runtime_node2.enrichEdgeGeo,
37
+ enrichRequestSize: () => import_runtime_node2.enrichRequestSize,
38
+ enrichUserAgent: () => import_runtime_node2.enrichUserAgent,
39
+ errorAttributes: () => import_runtime_node2.errorAttributes,
40
+ fileSink: () => import_runtime_node2.fileSink,
41
+ flushRuntimeLogs: () => import_runtime_node2.flushRuntimeLogs,
42
+ initAutterLogging: () => import_runtime_node2.initAutterLogging,
27
43
  installAutterAutoFlush: () => import_runtime_node2.installAutterAutoFlush,
28
44
  instrumentLlmClient: () => import_runtime_node2.instrumentLlmClient,
45
+ isRuntimeErrorLike: () => import_runtime_node2.isRuntimeErrorLike,
29
46
  makeSafeCapture: () => import_runtime_node2.makeSafeCapture,
47
+ otlpSink: () => import_runtime_node2.otlpSink,
30
48
  redactAttributes: () => import_runtime_node2.redactAttributes,
49
+ redactText: () => import_runtime_node2.redactText,
31
50
  registerAutter: () => registerAutter,
32
51
  reportServerOutcome: () => import_runtime_node2.reportOutcome,
52
+ runInBackground: () => import_runtime_node2.runInBackground,
53
+ runtimeContext: () => import_runtime_node2.runtimeContext,
54
+ runtimeLogStats: () => import_runtime_node2.runtimeLogStats,
55
+ runtimeLogger: () => import_runtime_node2.runtimeLogger,
56
+ toClientError: () => import_runtime_node2.toClientError,
33
57
  trackLlmCall: () => import_runtime_node2.trackLlmCall,
34
58
  withLlmCall: () => import_runtime_node2.withLlmCall,
35
- withProcessSpan: () => import_runtime_node2.withProcessSpan
59
+ withProcessSpan: () => import_runtime_node2.withProcessSpan,
60
+ withRuntimeOperation: () => import_runtime_node2.withRuntimeOperation,
61
+ withRuntimeRequest: () => withRuntimeRequest
36
62
  });
37
63
  module.exports = __toCommonJS(src_exports);
38
64
 
39
65
  // src/server.ts
40
66
  var import_runtime_node = require("@autter/runtime-node");
67
+
68
+ // package.json
69
+ var package_default = {
70
+ name: "@autter/runtime-next",
71
+ version: "1.5.0",
72
+ 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",
73
+ license: "MIT",
74
+ type: "module",
75
+ main: "./dist/index.cjs",
76
+ module: "./dist/index.js",
77
+ types: "./dist/index.d.ts",
78
+ exports: {
79
+ ".": {
80
+ types: "./dist/index.d.ts",
81
+ import: "./dist/index.js",
82
+ require: "./dist/index.cjs"
83
+ },
84
+ "./server": {
85
+ types: "./dist/server.d.ts",
86
+ import: "./dist/server.js",
87
+ require: "./dist/server.cjs"
88
+ },
89
+ "./client": {
90
+ types: "./dist/client.d.ts",
91
+ import: "./dist/client.js",
92
+ require: "./dist/client.cjs"
93
+ },
94
+ "./edge": {
95
+ types: "./dist/edge.d.ts",
96
+ import: "./dist/edge.js",
97
+ require: "./dist/edge.cjs"
98
+ }
99
+ },
100
+ files: [
101
+ "dist"
102
+ ],
103
+ repository: {
104
+ type: "git",
105
+ url: "https://github.com/Autter-dev/autter-runtime.git",
106
+ directory: "packages/runtime-next"
107
+ },
108
+ scripts: {
109
+ build: `node ../../scripts/ensure-built.mjs runtime-node runtime-edge runtime-browser && node -e "require('node:fs').rmSync('dist',{recursive:true,force:true})" && tsup`,
110
+ 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"
111
+ },
112
+ dependencies: {
113
+ "@autter/runtime-browser": "^1.4.0",
114
+ "@autter/runtime-edge": "^1.0.0",
115
+ "@autter/runtime-node": "^1.5.0"
116
+ },
117
+ peerDependencies: {
118
+ react: ">=18"
119
+ },
120
+ devDependencies: {
121
+ "@types/react": "^18.3.0",
122
+ tsup: "^8.3.5",
123
+ typescript: "^5.7.0"
124
+ },
125
+ engines: {
126
+ node: ">=20"
127
+ },
128
+ publishConfig: {
129
+ access: "public",
130
+ provenance: true
131
+ },
132
+ homepage: "https://github.com/Autter-dev/autter-runtime#readme",
133
+ bugs: "https://github.com/Autter-dev/autter-runtime/issues",
134
+ keywords: [
135
+ "nextjs",
136
+ "error-tracking",
137
+ "telemetry",
138
+ "opentelemetry",
139
+ "react",
140
+ "error-boundary"
141
+ ]
142
+ };
143
+
144
+ // src/server.ts
41
145
  var import_runtime_node2 = require("@autter/runtime-node");
42
146
  function registerAutter(options) {
43
- return (0, import_runtime_node.initAutterServer)(options);
147
+ return (0, import_runtime_node.initAutterServer)({
148
+ distro: { name: "@autter/runtime-next", version: package_default.version },
149
+ ...options
150
+ });
44
151
  }
45
152
  function createAutterRelayRoute(options) {
46
153
  return { POST: (0, import_runtime_node.createBrowserRelayFetchHandler)(options) };
47
154
  }
155
+ var after;
156
+ var afterReady = (async () => {
157
+ try {
158
+ const specifier = "next/server";
159
+ const mod = await import(
160
+ /* webpackIgnore: true */
161
+ specifier
162
+ );
163
+ after = mod.after ?? mod.unstable_after ?? null;
164
+ } catch {
165
+ after = null;
166
+ }
167
+ return after;
168
+ })();
169
+ function scheduleAfter(promise) {
170
+ const run = (fn) => {
171
+ if (!fn) return;
172
+ try {
173
+ fn(promise);
174
+ } catch {
175
+ }
176
+ };
177
+ if (after !== void 0) run(after);
178
+ else void afterReady.then(run);
179
+ }
180
+ function withRuntimeRequest(handler, options = {}) {
181
+ return (0, import_runtime_node.withRuntimeRequest)(handler, {
182
+ ...options,
183
+ waitUntil: options.waitUntil ?? scheduleAfter
184
+ });
185
+ }
48
186
  // Annotate the CommonJS export names for ESM import in node:
49
187
  0 && (module.exports = {
188
+ CODE_PATTERN,
189
+ RuntimeError,
190
+ autterErrorResponse,
191
+ autterFastify,
192
+ autterRequests,
50
193
  captureServerException,
51
194
  captureServerMessage,
195
+ consoleSink,
52
196
  createAutterRelayRoute,
197
+ createRuntimeLogger,
198
+ defineRuntimeErrors,
53
199
  emitLlmSelftestTrace,
200
+ enrichDeployment,
201
+ enrichEdgeGeo,
202
+ enrichRequestSize,
203
+ enrichUserAgent,
204
+ errorAttributes,
205
+ fileSink,
206
+ flushRuntimeLogs,
207
+ initAutterLogging,
54
208
  installAutterAutoFlush,
55
209
  instrumentLlmClient,
210
+ isRuntimeErrorLike,
56
211
  makeSafeCapture,
212
+ otlpSink,
57
213
  redactAttributes,
214
+ redactText,
58
215
  registerAutter,
59
216
  reportServerOutcome,
217
+ runInBackground,
218
+ runtimeContext,
219
+ runtimeLogStats,
220
+ runtimeLogger,
221
+ toClientError,
60
222
  trackLlmCall,
61
223
  withLlmCall,
62
- withProcessSpan
224
+ withProcessSpan,
225
+ withRuntimeOperation,
226
+ withRuntimeRequest
63
227
  });
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, SafeCapture, TrackedLlmCall, captureException as captureServerException, captureMessage as captureServerMessage, emitLlmSelftestTrace, installAutterAutoFlush, instrumentLlmClient, makeSafeCapture, redactAttributes, reportOutcome as reportServerOutcome, trackLlmCall, withLlmCall, withProcessSpan } from '@autter/runtime-node';
1
+ export { createAutterRelayRoute, registerAutter, withRuntimeRequest } from './server.cjs';
2
+ export { AutoFlushHandle, AutoFlushOptions, AutterErrorResponseOptions, AutterLogging, AutterLoggingOptions, AutterRequestsOptions, AutterServer, AutterServerOptions, 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, autterErrorResponse, autterFastify, autterRequests, 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, SafeCapture, TrackedLlmCall, captureException as captureServerException, captureMessage as captureServerMessage, emitLlmSelftestTrace, installAutterAutoFlush, instrumentLlmClient, makeSafeCapture, redactAttributes, reportOutcome as reportServerOutcome, trackLlmCall, withLlmCall, withProcessSpan } from '@autter/runtime-node';
1
+ export { createAutterRelayRoute, registerAutter, withRuntimeRequest } from './server.js';
2
+ export { AutoFlushHandle, AutoFlushOptions, AutterErrorResponseOptions, AutterLogging, AutterLoggingOptions, AutterRequestsOptions, AutterServer, AutterServerOptions, 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, autterErrorResponse, autterFastify, autterRequests, 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,30 +1,82 @@
1
1
  import {
2
+ CODE_PATTERN,
3
+ RuntimeError,
4
+ autterErrorResponse,
5
+ autterFastify,
6
+ autterRequests,
2
7
  captureException,
3
8
  captureMessage,
9
+ consoleSink,
4
10
  createAutterRelayRoute,
11
+ createRuntimeLogger,
12
+ defineRuntimeErrors,
5
13
  emitLlmSelftestTrace,
14
+ enrichDeployment,
15
+ enrichEdgeGeo,
16
+ enrichRequestSize,
17
+ enrichUserAgent,
18
+ errorAttributes,
19
+ fileSink,
20
+ flushRuntimeLogs,
21
+ initAutterLogging,
6
22
  installAutterAutoFlush,
7
23
  instrumentLlmClient,
24
+ isRuntimeErrorLike,
8
25
  makeSafeCapture,
26
+ otlpSink,
9
27
  redactAttributes,
28
+ redactText,
10
29
  registerAutter,
11
30
  reportOutcome,
31
+ runInBackground,
32
+ runtimeContext,
33
+ runtimeLogStats,
34
+ runtimeLogger,
35
+ toClientError,
12
36
  trackLlmCall,
13
37
  withLlmCall,
14
- withProcessSpan
15
- } from "./chunk-4RSUUUZJ.js";
38
+ withProcessSpan,
39
+ withRuntimeOperation,
40
+ withRuntimeRequest
41
+ } from "./chunk-CXHBXTTB.js";
16
42
  export {
43
+ CODE_PATTERN,
44
+ RuntimeError,
45
+ autterErrorResponse,
46
+ autterFastify,
47
+ autterRequests,
17
48
  captureException as captureServerException,
18
49
  captureMessage as captureServerMessage,
50
+ consoleSink,
19
51
  createAutterRelayRoute,
52
+ createRuntimeLogger,
53
+ defineRuntimeErrors,
20
54
  emitLlmSelftestTrace,
55
+ enrichDeployment,
56
+ enrichEdgeGeo,
57
+ enrichRequestSize,
58
+ enrichUserAgent,
59
+ errorAttributes,
60
+ fileSink,
61
+ flushRuntimeLogs,
62
+ initAutterLogging,
21
63
  installAutterAutoFlush,
22
64
  instrumentLlmClient,
65
+ isRuntimeErrorLike,
23
66
  makeSafeCapture,
67
+ otlpSink,
24
68
  redactAttributes,
69
+ redactText,
25
70
  registerAutter,
26
71
  reportOutcome as reportServerOutcome,
72
+ runInBackground,
73
+ runtimeContext,
74
+ runtimeLogStats,
75
+ runtimeLogger,
76
+ toClientError,
27
77
  trackLlmCall,
28
78
  withLlmCall,
29
- withProcessSpan
79
+ withProcessSpan,
80
+ withRuntimeOperation,
81
+ withRuntimeRequest
30
82
  };
package/dist/server.cjs CHANGED
@@ -20,42 +20,206 @@ 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
+ autterErrorResponse: () => import_runtime_node2.autterErrorResponse,
26
+ autterFastify: () => import_runtime_node2.autterFastify,
27
+ autterRequests: () => import_runtime_node2.autterRequests,
23
28
  captureServerException: () => import_runtime_node2.captureException,
24
29
  captureServerMessage: () => import_runtime_node2.captureMessage,
30
+ consoleSink: () => import_runtime_node2.consoleSink,
25
31
  createAutterRelayRoute: () => createAutterRelayRoute,
32
+ createRuntimeLogger: () => import_runtime_node2.createRuntimeLogger,
33
+ defineRuntimeErrors: () => import_runtime_node2.defineRuntimeErrors,
26
34
  emitLlmSelftestTrace: () => import_runtime_node2.emitLlmSelftestTrace,
35
+ enrichDeployment: () => import_runtime_node2.enrichDeployment,
36
+ enrichEdgeGeo: () => import_runtime_node2.enrichEdgeGeo,
37
+ enrichRequestSize: () => import_runtime_node2.enrichRequestSize,
38
+ enrichUserAgent: () => import_runtime_node2.enrichUserAgent,
39
+ errorAttributes: () => import_runtime_node2.errorAttributes,
40
+ fileSink: () => import_runtime_node2.fileSink,
41
+ flushRuntimeLogs: () => import_runtime_node2.flushRuntimeLogs,
42
+ initAutterLogging: () => import_runtime_node2.initAutterLogging,
27
43
  installAutterAutoFlush: () => import_runtime_node2.installAutterAutoFlush,
28
44
  instrumentLlmClient: () => import_runtime_node2.instrumentLlmClient,
45
+ isRuntimeErrorLike: () => import_runtime_node2.isRuntimeErrorLike,
29
46
  makeSafeCapture: () => import_runtime_node2.makeSafeCapture,
47
+ otlpSink: () => import_runtime_node2.otlpSink,
30
48
  redactAttributes: () => import_runtime_node2.redactAttributes,
49
+ redactText: () => import_runtime_node2.redactText,
31
50
  registerAutter: () => registerAutter,
32
51
  reportServerOutcome: () => import_runtime_node2.reportOutcome,
52
+ runInBackground: () => import_runtime_node2.runInBackground,
53
+ runtimeContext: () => import_runtime_node2.runtimeContext,
54
+ runtimeLogStats: () => import_runtime_node2.runtimeLogStats,
55
+ runtimeLogger: () => import_runtime_node2.runtimeLogger,
56
+ toClientError: () => import_runtime_node2.toClientError,
33
57
  trackLlmCall: () => import_runtime_node2.trackLlmCall,
34
58
  withLlmCall: () => import_runtime_node2.withLlmCall,
35
- withProcessSpan: () => import_runtime_node2.withProcessSpan
59
+ withProcessSpan: () => import_runtime_node2.withProcessSpan,
60
+ withRuntimeOperation: () => import_runtime_node2.withRuntimeOperation,
61
+ withRuntimeRequest: () => withRuntimeRequest
36
62
  });
37
63
  module.exports = __toCommonJS(server_exports);
38
64
  var import_runtime_node = require("@autter/runtime-node");
65
+
66
+ // package.json
67
+ var package_default = {
68
+ name: "@autter/runtime-next",
69
+ version: "1.5.0",
70
+ 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",
71
+ license: "MIT",
72
+ type: "module",
73
+ main: "./dist/index.cjs",
74
+ module: "./dist/index.js",
75
+ types: "./dist/index.d.ts",
76
+ exports: {
77
+ ".": {
78
+ types: "./dist/index.d.ts",
79
+ import: "./dist/index.js",
80
+ require: "./dist/index.cjs"
81
+ },
82
+ "./server": {
83
+ types: "./dist/server.d.ts",
84
+ import: "./dist/server.js",
85
+ require: "./dist/server.cjs"
86
+ },
87
+ "./client": {
88
+ types: "./dist/client.d.ts",
89
+ import: "./dist/client.js",
90
+ require: "./dist/client.cjs"
91
+ },
92
+ "./edge": {
93
+ types: "./dist/edge.d.ts",
94
+ import: "./dist/edge.js",
95
+ require: "./dist/edge.cjs"
96
+ }
97
+ },
98
+ files: [
99
+ "dist"
100
+ ],
101
+ repository: {
102
+ type: "git",
103
+ url: "https://github.com/Autter-dev/autter-runtime.git",
104
+ directory: "packages/runtime-next"
105
+ },
106
+ scripts: {
107
+ build: `node ../../scripts/ensure-built.mjs runtime-node runtime-edge runtime-browser && node -e "require('node:fs').rmSync('dist',{recursive:true,force:true})" && tsup`,
108
+ 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"
109
+ },
110
+ dependencies: {
111
+ "@autter/runtime-browser": "^1.4.0",
112
+ "@autter/runtime-edge": "^1.0.0",
113
+ "@autter/runtime-node": "^1.5.0"
114
+ },
115
+ peerDependencies: {
116
+ react: ">=18"
117
+ },
118
+ devDependencies: {
119
+ "@types/react": "^18.3.0",
120
+ tsup: "^8.3.5",
121
+ typescript: "^5.7.0"
122
+ },
123
+ engines: {
124
+ node: ">=20"
125
+ },
126
+ publishConfig: {
127
+ access: "public",
128
+ provenance: true
129
+ },
130
+ homepage: "https://github.com/Autter-dev/autter-runtime#readme",
131
+ bugs: "https://github.com/Autter-dev/autter-runtime/issues",
132
+ keywords: [
133
+ "nextjs",
134
+ "error-tracking",
135
+ "telemetry",
136
+ "opentelemetry",
137
+ "react",
138
+ "error-boundary"
139
+ ]
140
+ };
141
+
142
+ // src/server.ts
39
143
  var import_runtime_node2 = require("@autter/runtime-node");
40
144
  function registerAutter(options) {
41
- return (0, import_runtime_node.initAutterServer)(options);
145
+ return (0, import_runtime_node.initAutterServer)({
146
+ distro: { name: "@autter/runtime-next", version: package_default.version },
147
+ ...options
148
+ });
42
149
  }
43
150
  function createAutterRelayRoute(options) {
44
151
  return { POST: (0, import_runtime_node.createBrowserRelayFetchHandler)(options) };
45
152
  }
153
+ var after;
154
+ var afterReady = (async () => {
155
+ try {
156
+ const specifier = "next/server";
157
+ const mod = await import(
158
+ /* webpackIgnore: true */
159
+ specifier
160
+ );
161
+ after = mod.after ?? mod.unstable_after ?? null;
162
+ } catch {
163
+ after = null;
164
+ }
165
+ return after;
166
+ })();
167
+ function scheduleAfter(promise) {
168
+ const run = (fn) => {
169
+ if (!fn) return;
170
+ try {
171
+ fn(promise);
172
+ } catch {
173
+ }
174
+ };
175
+ if (after !== void 0) run(after);
176
+ else void afterReady.then(run);
177
+ }
178
+ function withRuntimeRequest(handler, options = {}) {
179
+ return (0, import_runtime_node.withRuntimeRequest)(handler, {
180
+ ...options,
181
+ waitUntil: options.waitUntil ?? scheduleAfter
182
+ });
183
+ }
46
184
  // Annotate the CommonJS export names for ESM import in node:
47
185
  0 && (module.exports = {
186
+ CODE_PATTERN,
187
+ RuntimeError,
188
+ autterErrorResponse,
189
+ autterFastify,
190
+ autterRequests,
48
191
  captureServerException,
49
192
  captureServerMessage,
193
+ consoleSink,
50
194
  createAutterRelayRoute,
195
+ createRuntimeLogger,
196
+ defineRuntimeErrors,
51
197
  emitLlmSelftestTrace,
198
+ enrichDeployment,
199
+ enrichEdgeGeo,
200
+ enrichRequestSize,
201
+ enrichUserAgent,
202
+ errorAttributes,
203
+ fileSink,
204
+ flushRuntimeLogs,
205
+ initAutterLogging,
52
206
  installAutterAutoFlush,
53
207
  instrumentLlmClient,
208
+ isRuntimeErrorLike,
54
209
  makeSafeCapture,
210
+ otlpSink,
55
211
  redactAttributes,
212
+ redactText,
56
213
  registerAutter,
57
214
  reportServerOutcome,
215
+ runInBackground,
216
+ runtimeContext,
217
+ runtimeLogStats,
218
+ runtimeLogger,
219
+ toClientError,
58
220
  trackLlmCall,
59
221
  withLlmCall,
60
- withProcessSpan
222
+ withProcessSpan,
223
+ withRuntimeOperation,
224
+ withRuntimeRequest
61
225
  });
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, SafeCapture, TrackedLlmCall, captureException as captureServerException, captureMessage as captureServerMessage, emitLlmSelftestTrace, installAutterAutoFlush, instrumentLlmClient, makeSafeCapture, redactAttributes, reportOutcome as reportServerOutcome, trackLlmCall, withLlmCall, withProcessSpan } from '@autter/runtime-node';
1
+ import { RelayOptions, AutterServerOptions, AutterServer, RuntimeRequestOptions } from '@autter/runtime-node';
2
+ export { AutoFlushHandle, AutoFlushOptions, AutterErrorResponseOptions, AutterLogging, AutterLoggingOptions, AutterRequestsOptions, AutterServer, AutterServerOptions, 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, autterErrorResponse, autterFastify, autterRequests, 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, SafeCapture, TrackedLlmCall, captureException as captureServerException, captureMessage as captureServerMessage, emitLlmSelftestTrace, installAutterAutoFlush, instrumentLlmClient, makeSafeCapture, redactAttributes, reportOutcome as reportServerOutcome, trackLlmCall, withLlmCall, withProcessSpan } from '@autter/runtime-node';
1
+ import { RelayOptions, AutterServerOptions, AutterServer, RuntimeRequestOptions } from '@autter/runtime-node';
2
+ export { AutoFlushHandle, AutoFlushOptions, AutterErrorResponseOptions, AutterLogging, AutterLoggingOptions, AutterRequestsOptions, AutterServer, AutterServerOptions, 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, autterErrorResponse, autterFastify, autterRequests, 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,30 +1,82 @@
1
1
  import {
2
+ CODE_PATTERN,
3
+ RuntimeError,
4
+ autterErrorResponse,
5
+ autterFastify,
6
+ autterRequests,
2
7
  captureException,
3
8
  captureMessage,
9
+ consoleSink,
4
10
  createAutterRelayRoute,
11
+ createRuntimeLogger,
12
+ defineRuntimeErrors,
5
13
  emitLlmSelftestTrace,
14
+ enrichDeployment,
15
+ enrichEdgeGeo,
16
+ enrichRequestSize,
17
+ enrichUserAgent,
18
+ errorAttributes,
19
+ fileSink,
20
+ flushRuntimeLogs,
21
+ initAutterLogging,
6
22
  installAutterAutoFlush,
7
23
  instrumentLlmClient,
24
+ isRuntimeErrorLike,
8
25
  makeSafeCapture,
26
+ otlpSink,
9
27
  redactAttributes,
28
+ redactText,
10
29
  registerAutter,
11
30
  reportOutcome,
31
+ runInBackground,
32
+ runtimeContext,
33
+ runtimeLogStats,
34
+ runtimeLogger,
35
+ toClientError,
12
36
  trackLlmCall,
13
37
  withLlmCall,
14
- withProcessSpan
15
- } from "./chunk-4RSUUUZJ.js";
38
+ withProcessSpan,
39
+ withRuntimeOperation,
40
+ withRuntimeRequest
41
+ } from "./chunk-CXHBXTTB.js";
16
42
  export {
43
+ CODE_PATTERN,
44
+ RuntimeError,
45
+ autterErrorResponse,
46
+ autterFastify,
47
+ autterRequests,
17
48
  captureException as captureServerException,
18
49
  captureMessage as captureServerMessage,
50
+ consoleSink,
19
51
  createAutterRelayRoute,
52
+ createRuntimeLogger,
53
+ defineRuntimeErrors,
20
54
  emitLlmSelftestTrace,
55
+ enrichDeployment,
56
+ enrichEdgeGeo,
57
+ enrichRequestSize,
58
+ enrichUserAgent,
59
+ errorAttributes,
60
+ fileSink,
61
+ flushRuntimeLogs,
62
+ initAutterLogging,
21
63
  installAutterAutoFlush,
22
64
  instrumentLlmClient,
65
+ isRuntimeErrorLike,
23
66
  makeSafeCapture,
67
+ otlpSink,
24
68
  redactAttributes,
69
+ redactText,
25
70
  registerAutter,
26
71
  reportOutcome as reportServerOutcome,
72
+ runInBackground,
73
+ runtimeContext,
74
+ runtimeLogStats,
75
+ runtimeLogger,
76
+ toClientError,
27
77
  trackLlmCall,
28
78
  withLlmCall,
29
- withProcessSpan
79
+ withProcessSpan,
80
+ withRuntimeOperation,
81
+ withRuntimeRequest
30
82
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@autter/runtime-next",
3
- "version": "1.3.4",
4
- "description": "One-command Autter Runtime for Next.js: server OTel, browser tracker, relay route, and React error boundary",
3
+ "version": "1.5.0",
4
+ "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",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -22,6 +22,11 @@
22
22
  "types": "./dist/client.d.ts",
23
23
  "import": "./dist/client.js",
24
24
  "require": "./dist/client.cjs"
25
+ },
26
+ "./edge": {
27
+ "types": "./dist/edge.d.ts",
28
+ "import": "./dist/edge.js",
29
+ "require": "./dist/edge.cjs"
25
30
  }
26
31
  },
27
32
  "files": [
@@ -33,11 +38,13 @@
33
38
  "directory": "packages/runtime-next"
34
39
  },
35
40
  "scripts": {
36
- "build": "tsup"
41
+ "build": "node ../../scripts/ensure-built.mjs runtime-node runtime-edge runtime-browser && node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
42
+ "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"
37
43
  },
38
44
  "dependencies": {
39
- "@autter/runtime-browser": "^1.3.3",
40
- "@autter/runtime-node": "^1.3.4"
45
+ "@autter/runtime-browser": "^1.4.0",
46
+ "@autter/runtime-edge": "^1.0.0",
47
+ "@autter/runtime-node": "^1.5.0"
41
48
  },
42
49
  "peerDependencies": {
43
50
  "react": ">=18"
@@ -1,40 +0,0 @@
1
- // src/server.ts
2
- import {
3
- createBrowserRelayFetchHandler,
4
- initAutterServer
5
- } from "@autter/runtime-node";
6
- import {
7
- captureException,
8
- captureMessage,
9
- reportOutcome,
10
- withProcessSpan,
11
- withLlmCall,
12
- trackLlmCall,
13
- instrumentLlmClient,
14
- emitLlmSelftestTrace,
15
- makeSafeCapture,
16
- installAutterAutoFlush,
17
- redactAttributes
18
- } from "@autter/runtime-node";
19
- function registerAutter(options) {
20
- return initAutterServer(options);
21
- }
22
- function createAutterRelayRoute(options) {
23
- return { POST: createBrowserRelayFetchHandler(options) };
24
- }
25
-
26
- export {
27
- registerAutter,
28
- createAutterRelayRoute,
29
- captureException,
30
- captureMessage,
31
- reportOutcome,
32
- withProcessSpan,
33
- withLlmCall,
34
- trackLlmCall,
35
- instrumentLlmClient,
36
- emitLlmSelftestTrace,
37
- makeSafeCapture,
38
- installAutterAutoFlush,
39
- redactAttributes
40
- };