@autter/runtime-next 0.1.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 +66 -0
- package/dist/index.cjs +95 -0
- package/dist/index.d.cts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +63 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @autter/runtime-next
|
|
2
|
+
|
|
3
|
+
One-command Autter Runtime for Next.js: server OTel, browser tracker,
|
|
4
|
+
same-origin relay route, and a React error boundary.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @autter/runtime-next
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Set `AUTTER_RUNTIME_KEY` in your environment. Then three small files:
|
|
13
|
+
|
|
14
|
+
**1. `instrumentation.ts`** — server tracing/errors:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
export async function register() {
|
|
18
|
+
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
19
|
+
const { registerAutter } = await import("@autter/runtime-next");
|
|
20
|
+
registerAutter({
|
|
21
|
+
apiKey: process.env.AUTTER_RUNTIME_KEY!,
|
|
22
|
+
service: "web-app",
|
|
23
|
+
environment: process.env.NODE_ENV,
|
|
24
|
+
release: process.env.GIT_SHA,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**2. `app/api/autter-runtime/route.ts`** — browser relay (key stays server-side):
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createAutterRelayRoute } from "@autter/runtime-next";
|
|
34
|
+
|
|
35
|
+
export const { POST } = createAutterRelayRoute({
|
|
36
|
+
apiKey: process.env.AUTTER_RUNTIME_KEY!,
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**3. A client component** — browser tracker + render-error boundary:
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
"use client";
|
|
44
|
+
import { initAutterBrowser, AutterErrorBoundary } from "@autter/runtime-next";
|
|
45
|
+
|
|
46
|
+
initAutterBrowser({
|
|
47
|
+
endpoint: "/api/autter-runtime",
|
|
48
|
+
service: "web-app",
|
|
49
|
+
release: process.env.NEXT_PUBLIC_GIT_SHA,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
53
|
+
return (
|
|
54
|
+
<AutterErrorBoundary fallback={<p>Something went wrong.</p>}>
|
|
55
|
+
{children}
|
|
56
|
+
</AutterErrorBoundary>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
React render errors don't reach `window.onerror` — the boundary reports
|
|
62
|
+
them via `captureException` and then renders your fallback.
|
|
63
|
+
|
|
64
|
+
Also re-exported for convenience: `captureException`, `captureMessage`,
|
|
65
|
+
`trackEvent`, `setUser`, `setContext`, `flush` (browser) and
|
|
66
|
+
`captureServerException`, `captureServerMessage` (server).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
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/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AutterErrorBoundary: () => AutterErrorBoundary,
|
|
34
|
+
captureException: () => import_runtime_browser2.captureException,
|
|
35
|
+
captureMessage: () => import_runtime_browser2.captureMessage,
|
|
36
|
+
captureServerException: () => import_runtime_node2.captureException,
|
|
37
|
+
captureServerMessage: () => import_runtime_node2.captureMessage,
|
|
38
|
+
createAutterRelayRoute: () => createAutterRelayRoute,
|
|
39
|
+
flush: () => import_runtime_browser2.flush,
|
|
40
|
+
initAutterBrowser: () => import_runtime_browser2.initAutterBrowser,
|
|
41
|
+
registerAutter: () => registerAutter,
|
|
42
|
+
setContext: () => import_runtime_browser2.setContext,
|
|
43
|
+
setUser: () => import_runtime_browser2.setUser,
|
|
44
|
+
trackEvent: () => import_runtime_browser2.trackEvent
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(index_exports);
|
|
47
|
+
var import_runtime_node = require("@autter/runtime-node");
|
|
48
|
+
var import_runtime_browser2 = require("@autter/runtime-browser");
|
|
49
|
+
|
|
50
|
+
// src/error-boundary.ts
|
|
51
|
+
var React = __toESM(require("react"), 1);
|
|
52
|
+
var import_runtime_browser = require("@autter/runtime-browser");
|
|
53
|
+
var AutterErrorBoundary = class extends React.Component {
|
|
54
|
+
state = { hasError: false };
|
|
55
|
+
static getDerivedStateFromError() {
|
|
56
|
+
return { hasError: true };
|
|
57
|
+
}
|
|
58
|
+
componentDidCatch(error, info) {
|
|
59
|
+
(0, import_runtime_browser.captureException)(error, {
|
|
60
|
+
react: true,
|
|
61
|
+
...info.componentStack ? { componentStack: String(info.componentStack).slice(0, 4e3) } : {}
|
|
62
|
+
});
|
|
63
|
+
this.props.onError?.(error, info);
|
|
64
|
+
}
|
|
65
|
+
render() {
|
|
66
|
+
if (this.state.hasError) {
|
|
67
|
+
return this.props.fallback ?? null;
|
|
68
|
+
}
|
|
69
|
+
return this.props.children;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/index.ts
|
|
74
|
+
var import_runtime_node2 = require("@autter/runtime-node");
|
|
75
|
+
function registerAutter(options) {
|
|
76
|
+
return (0, import_runtime_node.initAutterServer)(options);
|
|
77
|
+
}
|
|
78
|
+
function createAutterRelayRoute(options) {
|
|
79
|
+
return { POST: (0, import_runtime_node.createBrowserRelayFetchHandler)(options) };
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
AutterErrorBoundary,
|
|
84
|
+
captureException,
|
|
85
|
+
captureMessage,
|
|
86
|
+
captureServerException,
|
|
87
|
+
captureServerMessage,
|
|
88
|
+
createAutterRelayRoute,
|
|
89
|
+
flush,
|
|
90
|
+
initAutterBrowser,
|
|
91
|
+
registerAutter,
|
|
92
|
+
setContext,
|
|
93
|
+
setUser,
|
|
94
|
+
trackEvent
|
|
95
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { RelayOptions, AutterServerOptions, AutterServer } from '@autter/runtime-node';
|
|
2
|
+
export { captureException as captureServerException, captureMessage as captureServerMessage } from '@autter/runtime-node';
|
|
3
|
+
export { AutterSeverity, captureException, captureMessage, flush, initAutterBrowser, setContext, setUser, trackEvent } from '@autter/runtime-browser';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React error boundary that reports render errors to Autter Runtime.
|
|
8
|
+
* React rendering errors do NOT hit `window.onerror`, so the browser
|
|
9
|
+
* tracker alone misses them — wrap your app:
|
|
10
|
+
*
|
|
11
|
+
* <AutterErrorBoundary fallback={<ErrorPage />}>
|
|
12
|
+
* <Application />
|
|
13
|
+
* </AutterErrorBoundary>
|
|
14
|
+
*/
|
|
15
|
+
interface AutterErrorBoundaryProps {
|
|
16
|
+
fallback?: React.ReactNode;
|
|
17
|
+
/** Called after the error is reported (e.g. to show a toast). */
|
|
18
|
+
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
interface State {
|
|
22
|
+
hasError: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare class AutterErrorBoundary extends React.Component<AutterErrorBoundaryProps, State> {
|
|
25
|
+
state: State;
|
|
26
|
+
static getDerivedStateFromError(): State;
|
|
27
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
28
|
+
render(): React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @autter/runtime-next — one-command Autter Runtime for Next.js.
|
|
33
|
+
*
|
|
34
|
+
* 1. `instrumentation.ts` (server tracing):
|
|
35
|
+
*
|
|
36
|
+
* export async function register() {
|
|
37
|
+
* if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
38
|
+
* const { registerAutter } = await import("@autter/runtime-next");
|
|
39
|
+
* registerAutter({
|
|
40
|
+
* apiKey: process.env.AUTTER_RUNTIME_KEY!,
|
|
41
|
+
* service: "web-app",
|
|
42
|
+
* release: process.env.GIT_SHA,
|
|
43
|
+
* });
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* 2. `app/api/autter-runtime/route.ts` (browser relay):
|
|
48
|
+
*
|
|
49
|
+
* import { createAutterRelayRoute } from "@autter/runtime-next";
|
|
50
|
+
* export const { POST } = createAutterRelayRoute({
|
|
51
|
+
* apiKey: process.env.AUTTER_RUNTIME_KEY!,
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* 3. A client component (browser tracker + boundary):
|
|
55
|
+
*
|
|
56
|
+
* "use client";
|
|
57
|
+
* import { initAutterBrowser, AutterErrorBoundary } from "@autter/runtime-next";
|
|
58
|
+
* initAutterBrowser({ endpoint: "/api/autter-runtime", service: "web-app" });
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/** Server OTel init for Next.js `instrumentation.ts`. */
|
|
62
|
+
declare function registerAutter(options: AutterServerOptions): AutterServer;
|
|
63
|
+
/** App Router relay route: `export const { POST } = createAutterRelayRoute({...})`. */
|
|
64
|
+
declare function createAutterRelayRoute(options: RelayOptions): {
|
|
65
|
+
POST: (request: Request) => Promise<Response>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { AutterErrorBoundary, type AutterErrorBoundaryProps, createAutterRelayRoute, registerAutter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { RelayOptions, AutterServerOptions, AutterServer } from '@autter/runtime-node';
|
|
2
|
+
export { captureException as captureServerException, captureMessage as captureServerMessage } from '@autter/runtime-node';
|
|
3
|
+
export { AutterSeverity, captureException, captureMessage, flush, initAutterBrowser, setContext, setUser, trackEvent } from '@autter/runtime-browser';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React error boundary that reports render errors to Autter Runtime.
|
|
8
|
+
* React rendering errors do NOT hit `window.onerror`, so the browser
|
|
9
|
+
* tracker alone misses them — wrap your app:
|
|
10
|
+
*
|
|
11
|
+
* <AutterErrorBoundary fallback={<ErrorPage />}>
|
|
12
|
+
* <Application />
|
|
13
|
+
* </AutterErrorBoundary>
|
|
14
|
+
*/
|
|
15
|
+
interface AutterErrorBoundaryProps {
|
|
16
|
+
fallback?: React.ReactNode;
|
|
17
|
+
/** Called after the error is reported (e.g. to show a toast). */
|
|
18
|
+
onError?: (error: Error, info: React.ErrorInfo) => void;
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
}
|
|
21
|
+
interface State {
|
|
22
|
+
hasError: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare class AutterErrorBoundary extends React.Component<AutterErrorBoundaryProps, State> {
|
|
25
|
+
state: State;
|
|
26
|
+
static getDerivedStateFromError(): State;
|
|
27
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
28
|
+
render(): React.ReactNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @autter/runtime-next — one-command Autter Runtime for Next.js.
|
|
33
|
+
*
|
|
34
|
+
* 1. `instrumentation.ts` (server tracing):
|
|
35
|
+
*
|
|
36
|
+
* export async function register() {
|
|
37
|
+
* if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
38
|
+
* const { registerAutter } = await import("@autter/runtime-next");
|
|
39
|
+
* registerAutter({
|
|
40
|
+
* apiKey: process.env.AUTTER_RUNTIME_KEY!,
|
|
41
|
+
* service: "web-app",
|
|
42
|
+
* release: process.env.GIT_SHA,
|
|
43
|
+
* });
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* 2. `app/api/autter-runtime/route.ts` (browser relay):
|
|
48
|
+
*
|
|
49
|
+
* import { createAutterRelayRoute } from "@autter/runtime-next";
|
|
50
|
+
* export const { POST } = createAutterRelayRoute({
|
|
51
|
+
* apiKey: process.env.AUTTER_RUNTIME_KEY!,
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* 3. A client component (browser tracker + boundary):
|
|
55
|
+
*
|
|
56
|
+
* "use client";
|
|
57
|
+
* import { initAutterBrowser, AutterErrorBoundary } from "@autter/runtime-next";
|
|
58
|
+
* initAutterBrowser({ endpoint: "/api/autter-runtime", service: "web-app" });
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/** Server OTel init for Next.js `instrumentation.ts`. */
|
|
62
|
+
declare function registerAutter(options: AutterServerOptions): AutterServer;
|
|
63
|
+
/** App Router relay route: `export const { POST } = createAutterRelayRoute({...})`. */
|
|
64
|
+
declare function createAutterRelayRoute(options: RelayOptions): {
|
|
65
|
+
POST: (request: Request) => Promise<Response>;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { AutterErrorBoundary, type AutterErrorBoundaryProps, createAutterRelayRoute, registerAutter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createBrowserRelayFetchHandler,
|
|
4
|
+
initAutterServer
|
|
5
|
+
} from "@autter/runtime-node";
|
|
6
|
+
import {
|
|
7
|
+
initAutterBrowser,
|
|
8
|
+
captureException as captureException2,
|
|
9
|
+
captureMessage,
|
|
10
|
+
trackEvent,
|
|
11
|
+
setUser,
|
|
12
|
+
setContext,
|
|
13
|
+
flush
|
|
14
|
+
} from "@autter/runtime-browser";
|
|
15
|
+
|
|
16
|
+
// src/error-boundary.ts
|
|
17
|
+
import * as React from "react";
|
|
18
|
+
import { captureException } from "@autter/runtime-browser";
|
|
19
|
+
var AutterErrorBoundary = class extends React.Component {
|
|
20
|
+
state = { hasError: false };
|
|
21
|
+
static getDerivedStateFromError() {
|
|
22
|
+
return { hasError: true };
|
|
23
|
+
}
|
|
24
|
+
componentDidCatch(error, info) {
|
|
25
|
+
captureException(error, {
|
|
26
|
+
react: true,
|
|
27
|
+
...info.componentStack ? { componentStack: String(info.componentStack).slice(0, 4e3) } : {}
|
|
28
|
+
});
|
|
29
|
+
this.props.onError?.(error, info);
|
|
30
|
+
}
|
|
31
|
+
render() {
|
|
32
|
+
if (this.state.hasError) {
|
|
33
|
+
return this.props.fallback ?? null;
|
|
34
|
+
}
|
|
35
|
+
return this.props.children;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
import {
|
|
41
|
+
captureException as captureException3,
|
|
42
|
+
captureMessage as captureMessage2
|
|
43
|
+
} from "@autter/runtime-node";
|
|
44
|
+
function registerAutter(options) {
|
|
45
|
+
return initAutterServer(options);
|
|
46
|
+
}
|
|
47
|
+
function createAutterRelayRoute(options) {
|
|
48
|
+
return { POST: createBrowserRelayFetchHandler(options) };
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
AutterErrorBoundary,
|
|
52
|
+
captureException2 as captureException,
|
|
53
|
+
captureMessage,
|
|
54
|
+
captureException3 as captureServerException,
|
|
55
|
+
captureMessage2 as captureServerMessage,
|
|
56
|
+
createAutterRelayRoute,
|
|
57
|
+
flush,
|
|
58
|
+
initAutterBrowser,
|
|
59
|
+
registerAutter,
|
|
60
|
+
setContext,
|
|
61
|
+
setUser,
|
|
62
|
+
trackEvent
|
|
63
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autter/runtime-next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One-command Autter Runtime for Next.js: server OTel, browser tracker, relay route, and React error boundary",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/Autter-dev/autter-runtime.git",
|
|
23
|
+
"directory": "packages/runtime-next"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --target node20 --external react --clean"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@autter/runtime-browser": "0.1.0",
|
|
30
|
+
"@autter/runtime-node": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^18.3.0",
|
|
37
|
+
"tsup": "^8.3.5",
|
|
38
|
+
"typescript": "^5.7.0"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"provenance": true
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/Autter-dev/autter-runtime#readme",
|
|
48
|
+
"bugs": "https://github.com/Autter-dev/autter-runtime/issues",
|
|
49
|
+
"keywords": [
|
|
50
|
+
"nextjs",
|
|
51
|
+
"error-tracking",
|
|
52
|
+
"telemetry",
|
|
53
|
+
"opentelemetry",
|
|
54
|
+
"react",
|
|
55
|
+
"error-boundary"
|
|
56
|
+
]
|
|
57
|
+
}
|