@autter/runtime-next 1.5.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/README.md CHANGED
@@ -9,7 +9,8 @@ same-origin relay route, and a React error boundary.
9
9
  npm install @autter/runtime-next
10
10
  ```
11
11
 
12
- Set `AUTTER_RUNTIME_KEY` in your environment. Then three small files.
12
+ Set `AUTTER_RUNTIME_KEY` in your environment. Then one line of
13
+ `next.config` and three small files.
13
14
 
14
15
  The package has two entry points — this split is what keeps the Node
15
16
  OpenTelemetry SDK out of your browser bundle:
@@ -18,10 +19,33 @@ OpenTelemetry SDK out of your browser bundle:
18
19
  `instrumentation.ts`, route handlers, server components.
19
20
  - `@autter/runtime-next/client` — client components: browser tracker +
20
21
  error boundary. Never imports Node code.
22
+ - `@autter/runtime-next/instrumentation` — `onRequestError` for
23
+ `instrumentation.ts`; safe on both the Node and edge runtimes.
24
+
25
+ **`next.config`** — one copy of the Node SDK for `instrumentation.ts` and
26
+ your routes:
27
+
28
+ ```js
29
+ // next.config.mjs
30
+ export default {
31
+ serverExternalPackages: ["@autter/runtime-node"],
32
+ };
33
+ ```
34
+
35
+ Next bundles server dependencies separately into `instrumentation.ts` and
36
+ into each route. Without this line, code in routes, server components and
37
+ server actions (`withRuntimeRequest`, `captureServerException`,
38
+ `runtimeLogger`, `runtimeContext`, …) reaches a copy of the SDK that
39
+ `registerAutter` never started: request summaries are printed to the
40
+ console instead of being exported, and an error `withRuntimeRequest`
41
+ reports is reported a second time by `onRequestError`. Next 14.2:
42
+ `experimental: { serverComponentsExternalPackages: ["@autter/runtime-node"] }`.
21
43
 
22
44
  **1. `instrumentation.ts`** — server tracing/errors:
23
45
 
24
46
  ```ts
47
+ import { autterOnRequestError } from "@autter/runtime-next/instrumentation";
48
+
25
49
  export async function register() {
26
50
  if (process.env.NEXT_RUNTIME === "nodejs") {
27
51
  const { registerAutter } = await import("@autter/runtime-next");
@@ -33,8 +57,49 @@ export async function register() {
33
57
  });
34
58
  }
35
59
  }
60
+
61
+ // Next 15+: errors Next catches in server components, server actions, route
62
+ // handlers and middleware, with their stack (otherwise: stackless 500s).
63
+ export const onRequestError = autterOnRequestError({
64
+ // Edge runtime only (middleware, edge routes): no tracker runs there, so
65
+ // errors go straight to /v1/logs with these options.
66
+ edge: { apiKey: process.env.AUTTER_RUNTIME_KEY, service: "web-app" },
67
+ });
36
68
  ```
37
69
 
70
+ `@autter/runtime-next/instrumentation` is safe to import at the top of
71
+ `instrumentation.ts`, which Next compiles for both runtimes: on the edge,
72
+ bundlers resolve it (through the `edge-light`/`worker` export conditions) to a
73
+ build with no Node imports, and the Node build loads `@autter/runtime-node`
74
+ only inside a `process.env.NEXT_RUNTIME` branch Next removes from edge
75
+ bundles. Without edge errors to report, `export { onRequestError } from
76
+ "@autter/runtime-next/instrumentation"` is enough.
77
+
78
+ On Node the error is recorded on the request span through the
79
+ `registerAutter` tracker — once, even when `withRuntimeRequest` already
80
+ reported it (Next's context is then added to that report). Recorded with
81
+ it: `next.route_path` (the route template: `/blog/[slug]`, `/api/orders`;
82
+ middleware is `/middleware` on Next 15 and `/proxy` on Next 16),
83
+ `next.router_kind`, `next.route_type` (`render`, `route`, `action`,
84
+ `middleware` on Next 15, `proxy` on Next 16), `next.render_source`
85
+ (`react-server-components`, `react-server-components-payload`,
86
+ `server-rendering`), `next.render_type`, `next.revalidate_reason`,
87
+ `next.digest` (matches the `digest` your error boundary sees),
88
+ `http.request.method` and `url.path` without its query string. Headers and
89
+ cookies are never read. Next's control-flow signals (`redirect()`,
90
+ `notFound()`, `forbidden()`, `unauthorized()`, dynamic bailouts) are
91
+ skipped; `capture: true` or a predicate changes that.
92
+
93
+ On the edge runtime, Next calls `onRequestError` inside the function for
94
+ middleware and edge pages; the record goes out with the `edge` options and
95
+ is also handed to the request's `waitUntil`, since Next does not await the
96
+ hook for errors raised while rendering. Edge route handlers
97
+ (`export const runtime = "edge"` in `route.ts`) are the exception: Next
98
+ never calls the hook inside them. Self-hosted (`next start`), the Node
99
+ server reports them instead, so the Node tracker records them with their
100
+ own stack, `next.router_kind` `Pages Router` and `next.route_path` such as
101
+ `/api/orders/route`.
102
+
38
103
  `registerAutter` passes options straight to `initAutterServer`, so the
39
104
  server SDK's defaults apply out of the box: exporters are flushed on
40
105
  process exit (`autoFlush`) and custom attributes are scrubbed for PII
@@ -81,7 +146,9 @@ Also re-exported for convenience: `captureException`, `captureMessage`,
81
146
  `@autter/runtime-next/client`) and `captureServerException`,
82
147
  `captureServerMessage`, `withProcessSpan`, `withLlmCall`, `trackLlmCall`,
83
148
  `instrumentLlmClient`, `emitLlmSelftestTrace` (from the root /
84
- `@autter/runtime-next/server`).
149
+ `@autter/runtime-next/server`), plus the server error hooks for custom
150
+ servers: `autterErrorHandler`, `autterFastifyErrors`, `autterKoa` and
151
+ `captureRequestError`.
85
152
 
86
153
  > Importing the root entry from a client component pulls the Node OTel SDK
87
154
  > into the browser bundle and fails the build (`fs` cannot be resolved).
@@ -0,0 +1,85 @@
1
+ // src/request-error.ts
2
+ import { captureEdgeException } from "@autter/runtime-edge";
3
+ var CONTROL_FLOW_DIGEST = /^(?:NEXT_REDIRECT|NEXT_NOT_FOUND|NEXT_HTTP_ERROR_FALLBACK|DYNAMIC_SERVER_USAGE|BAILOUT_TO_CLIENT_SIDE_RENDERING)\b/;
4
+ function digestOf(error) {
5
+ try {
6
+ const digest = error?.digest;
7
+ return typeof digest === "string" ? digest : "";
8
+ } catch {
9
+ return "";
10
+ }
11
+ }
12
+ function shouldReport(error, rule) {
13
+ if (rule === true) return true;
14
+ if (rule === false) return false;
15
+ if (typeof rule === "function") {
16
+ try {
17
+ return rule(error) === true;
18
+ } catch {
19
+ return false;
20
+ }
21
+ }
22
+ return !CONTROL_FLOW_DIGEST.test(digestOf(error));
23
+ }
24
+ function requestErrorAttributes(error, request, context) {
25
+ const out = {};
26
+ const put = (key, read, max) => {
27
+ try {
28
+ const value = read();
29
+ if (typeof value === "string" && value) out[key] = value.slice(0, max);
30
+ } catch {
31
+ }
32
+ };
33
+ put("next.route_path", () => context?.routePath, 500);
34
+ put("next.router_kind", () => context?.routerKind, 40);
35
+ put("next.route_type", () => context?.routeType, 40);
36
+ put("next.render_source", () => context?.renderSource, 80);
37
+ put("next.render_type", () => context?.renderType, 40);
38
+ put("next.revalidate_reason", () => context?.revalidateReason, 40);
39
+ put("next.digest", () => digestOf(error), 100);
40
+ put("http.request.method", () => {
41
+ const method = request?.method;
42
+ return typeof method === "string" ? method.toUpperCase() : void 0;
43
+ }, 16);
44
+ put("url.path", () => {
45
+ const path = request?.path;
46
+ return typeof path === "string" ? path.split(/[?#]/)[0] ?? "" : void 0;
47
+ }, 1e3);
48
+ return out;
49
+ }
50
+ var warnedNoEdgeOptions = false;
51
+ function nextWaitUntil() {
52
+ try {
53
+ const store = globalThis[/* @__PURE__ */ Symbol.for("@next/request-context")];
54
+ const context = typeof store?.get === "function" ? store.get() : void 0;
55
+ const waitUntil = context?.waitUntil;
56
+ if (typeof waitUntil !== "function") return void 0;
57
+ return (promise) => waitUntil.call(context, promise);
58
+ } catch {
59
+ return void 0;
60
+ }
61
+ }
62
+ async function reportOnEdge(edge, error, attributes) {
63
+ const options = typeof edge === "function" ? edge() : edge;
64
+ if (!options) {
65
+ if (!warnedNoEdgeOptions) {
66
+ warnedNoEdgeOptions = true;
67
+ console.warn(
68
+ "[autter-runtime] onRequestError ran on the edge runtime without edge options; use autterOnRequestError({ edge: { apiKey, service } }) to report edge errors"
69
+ );
70
+ }
71
+ return;
72
+ }
73
+ const delivery = captureEdgeException(options, error, attributes);
74
+ try {
75
+ nextWaitUntil()?.(delivery);
76
+ } catch {
77
+ }
78
+ await delivery;
79
+ }
80
+
81
+ export {
82
+ shouldReport,
83
+ requestErrorAttributes,
84
+ reportOnEdge
85
+ };
@@ -8,7 +8,7 @@ import {
8
8
  // package.json
9
9
  var package_default = {
10
10
  name: "@autter/runtime-next",
11
- version: "1.5.0",
11
+ version: "1.6.0",
12
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
13
  license: "MIT",
14
14
  type: "module",
@@ -35,6 +35,19 @@ var package_default = {
35
35
  types: "./dist/edge.d.ts",
36
36
  import: "./dist/edge.js",
37
37
  require: "./dist/edge.cjs"
38
+ },
39
+ "./instrumentation": {
40
+ types: "./dist/instrumentation.d.ts",
41
+ "edge-light": {
42
+ import: "./dist/instrumentation-edge.js",
43
+ require: "./dist/instrumentation-edge.cjs"
44
+ },
45
+ worker: {
46
+ import: "./dist/instrumentation-edge.js",
47
+ require: "./dist/instrumentation-edge.cjs"
48
+ },
49
+ import: "./dist/instrumentation.js",
50
+ require: "./dist/instrumentation.cjs"
38
51
  }
39
52
  },
40
53
  files: [
@@ -50,9 +63,9 @@ var package_default = {
50
63
  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
64
  },
52
65
  dependencies: {
53
- "@autter/runtime-browser": "^1.4.0",
54
- "@autter/runtime-edge": "^1.0.0",
55
- "@autter/runtime-node": "^1.5.0"
66
+ "@autter/runtime-browser": "^1.6.0",
67
+ "@autter/runtime-edge": "^1.1.0",
68
+ "@autter/runtime-node": "^1.6.0"
56
69
  },
57
70
  peerDependencies: {
58
71
  react: ">=18"
@@ -104,6 +117,10 @@ import {
104
117
  autterRequests,
105
118
  autterFastify,
106
119
  autterErrorResponse,
120
+ autterErrorHandler,
121
+ autterFastifyErrors,
122
+ autterKoa,
123
+ captureRequestError,
107
124
  RuntimeError,
108
125
  defineRuntimeErrors,
109
126
  isRuntimeErrorLike,
@@ -118,7 +135,8 @@ import {
118
135
  otlpSink,
119
136
  consoleSink,
120
137
  fileSink,
121
- redactText
138
+ redactText,
139
+ addBreadcrumb
122
140
  } from "@autter/runtime-node";
123
141
  function registerAutter(options) {
124
142
  return initAutterServer({
@@ -186,6 +204,10 @@ export {
186
204
  autterRequests,
187
205
  autterFastify,
188
206
  autterErrorResponse,
207
+ autterErrorHandler,
208
+ autterFastifyErrors,
209
+ autterKoa,
210
+ captureRequestError,
189
211
  RuntimeError,
190
212
  defineRuntimeErrors,
191
213
  isRuntimeErrorLike,
@@ -200,5 +222,6 @@ export {
200
222
  otlpSink,
201
223
  consoleSink,
202
224
  fileSink,
203
- redactText
225
+ redactText,
226
+ addBreadcrumb
204
227
  };
package/dist/client.cjs CHANGED
@@ -34,10 +34,13 @@ 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
+ addBreadcrumb: () => import_breadcrumbs.addBreadcrumb,
37
38
  autterErrorFromResponse: () => import_runtime_browser2.autterErrorFromResponse,
38
39
  captureException: () => import_runtime_browser2.captureException,
39
40
  captureMessage: () => import_runtime_browser2.captureMessage,
40
41
  captureOutcome: () => import_runtime_browser2.captureOutcome,
42
+ clearBreadcrumbs: () => import_breadcrumbs.clearBreadcrumbs,
43
+ enableBreadcrumbs: () => import_breadcrumbs.enableBreadcrumbs,
41
44
  flush: () => import_runtime_browser2.flush,
42
45
  initAutterBrowser: () => import_runtime_browser2.initAutterBrowser,
43
46
  setContext: () => import_runtime_browser2.setContext,
@@ -46,6 +49,7 @@ __export(client_exports, {
46
49
  });
47
50
  module.exports = __toCommonJS(client_exports);
48
51
  var import_runtime_browser2 = require("@autter/runtime-browser");
52
+ var import_breadcrumbs = require("@autter/runtime-browser/breadcrumbs");
49
53
 
50
54
  // src/error-boundary.ts
51
55
  var React = __toESM(require("react"), 1);
@@ -77,10 +81,13 @@ var AutterErrorBoundary = class extends React.Component {
77
81
  // Annotate the CommonJS export names for ESM import in node:
78
82
  0 && (module.exports = {
79
83
  AutterErrorBoundary,
84
+ addBreadcrumb,
80
85
  autterErrorFromResponse,
81
86
  captureException,
82
87
  captureMessage,
83
88
  captureOutcome,
89
+ clearBreadcrumbs,
90
+ enableBreadcrumbs,
84
91
  flush,
85
92
  initAutterBrowser,
86
93
  setContext,
package/dist/client.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AutterSeverity, autterErrorFromResponse, captureException, captureMessage, captureOutcome, flush, initAutterBrowser, setContext, setUser, trackEvent } from '@autter/runtime-browser';
2
+ export { Breadcrumb, BreadcrumbInput, BreadcrumbOptions, addBreadcrumb, clearBreadcrumbs, enableBreadcrumbs } from '@autter/runtime-browser/breadcrumbs';
2
3
  import * as React from 'react';
3
4
 
4
5
  /**
package/dist/client.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AutterSeverity, autterErrorFromResponse, captureException, captureMessage, captureOutcome, flush, initAutterBrowser, setContext, setUser, trackEvent } from '@autter/runtime-browser';
2
+ export { Breadcrumb, BreadcrumbInput, BreadcrumbOptions, addBreadcrumb, clearBreadcrumbs, enableBreadcrumbs } from '@autter/runtime-browser/breadcrumbs';
2
3
  import * as React from 'react';
3
4
 
4
5
  /**
package/dist/client.js CHANGED
@@ -15,6 +15,11 @@ import {
15
15
  flush,
16
16
  autterErrorFromResponse
17
17
  } from "@autter/runtime-browser";
18
+ import {
19
+ enableBreadcrumbs,
20
+ addBreadcrumb,
21
+ clearBreadcrumbs
22
+ } from "@autter/runtime-browser/breadcrumbs";
18
23
 
19
24
  // src/error-boundary.ts
20
25
  import * as React from "react";
@@ -45,10 +50,13 @@ var AutterErrorBoundary = class extends React.Component {
45
50
  };
46
51
  export {
47
52
  AutterErrorBoundary,
53
+ addBreadcrumb,
48
54
  autterErrorFromResponse,
49
55
  captureException2 as captureException,
50
56
  captureMessage,
51
57
  captureOutcome,
58
+ clearBreadcrumbs,
59
+ enableBreadcrumbs,
52
60
  flush,
53
61
  initAutterBrowser,
54
62
  setContext,
package/dist/index.cjs CHANGED
@@ -22,9 +22,14 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  CODE_PATTERN: () => import_runtime_node2.CODE_PATTERN,
24
24
  RuntimeError: () => import_runtime_node2.RuntimeError,
25
+ addBreadcrumb: () => import_runtime_node2.addBreadcrumb,
26
+ autterErrorHandler: () => import_runtime_node2.autterErrorHandler,
25
27
  autterErrorResponse: () => import_runtime_node2.autterErrorResponse,
26
28
  autterFastify: () => import_runtime_node2.autterFastify,
29
+ autterFastifyErrors: () => import_runtime_node2.autterFastifyErrors,
30
+ autterKoa: () => import_runtime_node2.autterKoa,
27
31
  autterRequests: () => import_runtime_node2.autterRequests,
32
+ captureRequestError: () => import_runtime_node2.captureRequestError,
28
33
  captureServerException: () => import_runtime_node2.captureException,
29
34
  captureServerMessage: () => import_runtime_node2.captureMessage,
30
35
  consoleSink: () => import_runtime_node2.consoleSink,
@@ -68,7 +73,7 @@ var import_runtime_node = require("@autter/runtime-node");
68
73
  // package.json
69
74
  var package_default = {
70
75
  name: "@autter/runtime-next",
71
- version: "1.5.0",
76
+ version: "1.6.0",
72
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",
73
78
  license: "MIT",
74
79
  type: "module",
@@ -95,6 +100,19 @@ var package_default = {
95
100
  types: "./dist/edge.d.ts",
96
101
  import: "./dist/edge.js",
97
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"
98
116
  }
99
117
  },
100
118
  files: [
@@ -110,9 +128,9 @@ var package_default = {
110
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"
111
129
  },
112
130
  dependencies: {
113
- "@autter/runtime-browser": "^1.4.0",
114
- "@autter/runtime-edge": "^1.0.0",
115
- "@autter/runtime-node": "^1.5.0"
131
+ "@autter/runtime-browser": "^1.6.0",
132
+ "@autter/runtime-edge": "^1.1.0",
133
+ "@autter/runtime-node": "^1.6.0"
116
134
  },
117
135
  peerDependencies: {
118
136
  react: ">=18"
@@ -187,9 +205,14 @@ function withRuntimeRequest(handler, options = {}) {
187
205
  0 && (module.exports = {
188
206
  CODE_PATTERN,
189
207
  RuntimeError,
208
+ addBreadcrumb,
209
+ autterErrorHandler,
190
210
  autterErrorResponse,
191
211
  autterFastify,
212
+ autterFastifyErrors,
213
+ autterKoa,
192
214
  autterRequests,
215
+ captureRequestError,
193
216
  captureServerException,
194
217
  captureServerMessage,
195
218
  consoleSink,
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
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';
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
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';
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,11 +1,16 @@
1
1
  import {
2
2
  CODE_PATTERN,
3
3
  RuntimeError,
4
+ addBreadcrumb,
5
+ autterErrorHandler,
4
6
  autterErrorResponse,
5
7
  autterFastify,
8
+ autterFastifyErrors,
9
+ autterKoa,
6
10
  autterRequests,
7
11
  captureException,
8
12
  captureMessage,
13
+ captureRequestError,
9
14
  consoleSink,
10
15
  createAutterRelayRoute,
11
16
  createRuntimeLogger,
@@ -38,13 +43,18 @@ import {
38
43
  withProcessSpan,
39
44
  withRuntimeOperation,
40
45
  withRuntimeRequest
41
- } from "./chunk-CXHBXTTB.js";
46
+ } from "./chunk-QFEFRAVO.js";
42
47
  export {
43
48
  CODE_PATTERN,
44
49
  RuntimeError,
50
+ addBreadcrumb,
51
+ autterErrorHandler,
45
52
  autterErrorResponse,
46
53
  autterFastify,
54
+ autterFastifyErrors,
55
+ autterKoa,
47
56
  autterRequests,
57
+ captureRequestError,
48
58
  captureException as captureServerException,
49
59
  captureMessage as captureServerMessage,
50
60
  consoleSink,
@@ -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();
@@ -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
@@ -22,9 +22,14 @@ var server_exports = {};
22
22
  __export(server_exports, {
23
23
  CODE_PATTERN: () => import_runtime_node2.CODE_PATTERN,
24
24
  RuntimeError: () => import_runtime_node2.RuntimeError,
25
+ addBreadcrumb: () => import_runtime_node2.addBreadcrumb,
26
+ autterErrorHandler: () => import_runtime_node2.autterErrorHandler,
25
27
  autterErrorResponse: () => import_runtime_node2.autterErrorResponse,
26
28
  autterFastify: () => import_runtime_node2.autterFastify,
29
+ autterFastifyErrors: () => import_runtime_node2.autterFastifyErrors,
30
+ autterKoa: () => import_runtime_node2.autterKoa,
27
31
  autterRequests: () => import_runtime_node2.autterRequests,
32
+ captureRequestError: () => import_runtime_node2.captureRequestError,
28
33
  captureServerException: () => import_runtime_node2.captureException,
29
34
  captureServerMessage: () => import_runtime_node2.captureMessage,
30
35
  consoleSink: () => import_runtime_node2.consoleSink,
@@ -66,7 +71,7 @@ var import_runtime_node = require("@autter/runtime-node");
66
71
  // package.json
67
72
  var package_default = {
68
73
  name: "@autter/runtime-next",
69
- version: "1.5.0",
74
+ version: "1.6.0",
70
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",
71
76
  license: "MIT",
72
77
  type: "module",
@@ -93,6 +98,19 @@ var package_default = {
93
98
  types: "./dist/edge.d.ts",
94
99
  import: "./dist/edge.js",
95
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"
96
114
  }
97
115
  },
98
116
  files: [
@@ -108,9 +126,9 @@ var package_default = {
108
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"
109
127
  },
110
128
  dependencies: {
111
- "@autter/runtime-browser": "^1.4.0",
112
- "@autter/runtime-edge": "^1.0.0",
113
- "@autter/runtime-node": "^1.5.0"
129
+ "@autter/runtime-browser": "^1.6.0",
130
+ "@autter/runtime-edge": "^1.1.0",
131
+ "@autter/runtime-node": "^1.6.0"
114
132
  },
115
133
  peerDependencies: {
116
134
  react: ">=18"
@@ -185,9 +203,14 @@ function withRuntimeRequest(handler, options = {}) {
185
203
  0 && (module.exports = {
186
204
  CODE_PATTERN,
187
205
  RuntimeError,
206
+ addBreadcrumb,
207
+ autterErrorHandler,
188
208
  autterErrorResponse,
189
209
  autterFastify,
210
+ autterFastifyErrors,
211
+ autterKoa,
190
212
  autterRequests,
213
+ captureRequestError,
191
214
  captureServerException,
192
215
  captureServerMessage,
193
216
  consoleSink,
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
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';
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:
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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';
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:
package/dist/server.js CHANGED
@@ -1,11 +1,16 @@
1
1
  import {
2
2
  CODE_PATTERN,
3
3
  RuntimeError,
4
+ addBreadcrumb,
5
+ autterErrorHandler,
4
6
  autterErrorResponse,
5
7
  autterFastify,
8
+ autterFastifyErrors,
9
+ autterKoa,
6
10
  autterRequests,
7
11
  captureException,
8
12
  captureMessage,
13
+ captureRequestError,
9
14
  consoleSink,
10
15
  createAutterRelayRoute,
11
16
  createRuntimeLogger,
@@ -38,13 +43,18 @@ import {
38
43
  withProcessSpan,
39
44
  withRuntimeOperation,
40
45
  withRuntimeRequest
41
- } from "./chunk-CXHBXTTB.js";
46
+ } from "./chunk-QFEFRAVO.js";
42
47
  export {
43
48
  CODE_PATTERN,
44
49
  RuntimeError,
50
+ addBreadcrumb,
51
+ autterErrorHandler,
45
52
  autterErrorResponse,
46
53
  autterFastify,
54
+ autterFastifyErrors,
55
+ autterKoa,
47
56
  autterRequests,
57
+ captureRequestError,
48
58
  captureException as captureServerException,
49
59
  captureMessage as captureServerMessage,
50
60
  consoleSink,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autter/runtime-next",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
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",
@@ -27,6 +27,19 @@
27
27
  "types": "./dist/edge.d.ts",
28
28
  "import": "./dist/edge.js",
29
29
  "require": "./dist/edge.cjs"
30
+ },
31
+ "./instrumentation": {
32
+ "types": "./dist/instrumentation.d.ts",
33
+ "edge-light": {
34
+ "import": "./dist/instrumentation-edge.js",
35
+ "require": "./dist/instrumentation-edge.cjs"
36
+ },
37
+ "worker": {
38
+ "import": "./dist/instrumentation-edge.js",
39
+ "require": "./dist/instrumentation-edge.cjs"
40
+ },
41
+ "import": "./dist/instrumentation.js",
42
+ "require": "./dist/instrumentation.cjs"
30
43
  }
31
44
  },
32
45
  "files": [
@@ -42,9 +55,9 @@
42
55
  "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"
43
56
  },
44
57
  "dependencies": {
45
- "@autter/runtime-browser": "^1.4.0",
46
- "@autter/runtime-edge": "^1.0.0",
47
- "@autter/runtime-node": "^1.5.0"
58
+ "@autter/runtime-browser": "^1.6.0",
59
+ "@autter/runtime-edge": "^1.1.0",
60
+ "@autter/runtime-node": "^1.6.0"
48
61
  },
49
62
  "peerDependencies": {
50
63
  "react": ">=18"