kmind-apm-web-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/dist/index.d.ts +22 -0
- package/dist/index.js +44 -0
- package/package.json +12 -0
- package/src/index.tsx +17 -0
- package/tsconfig.json +1 -0
- package/tsup.config.ts +2 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Component, ReactNode, ErrorInfo } from 'react';
|
|
2
|
+
import { KmindConfig } from 'kmind-apm-web';
|
|
3
|
+
|
|
4
|
+
declare function initKmindNext(config?: Partial<KmindConfig>): void;
|
|
5
|
+
declare function KmindNextNavigation(): null;
|
|
6
|
+
declare class KmindNextErrorBoundary extends Component<{
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
fallback?: ReactNode;
|
|
9
|
+
}, {
|
|
10
|
+
failed: boolean;
|
|
11
|
+
}> {
|
|
12
|
+
state: {
|
|
13
|
+
failed: boolean;
|
|
14
|
+
};
|
|
15
|
+
static getDerivedStateFromError(): {
|
|
16
|
+
failed: boolean;
|
|
17
|
+
};
|
|
18
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
19
|
+
render(): ReactNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { KmindNextErrorBoundary, KmindNextNavigation, initKmindNext };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/index.tsx
|
|
4
|
+
import { Component, useEffect } from "react";
|
|
5
|
+
import { init, logger, recordMetric } from "kmind-apm-web";
|
|
6
|
+
function initKmindNext(config = {}) {
|
|
7
|
+
init({ serviceName: config.serviceName ?? process.env.NEXT_PUBLIC_KMIND_SERVICE_NAME ?? "next-app", clientKey: config.clientKey ?? process.env.NEXT_PUBLIC_KMIND_CLIENT_KEY ?? "", endpoint: config.endpoint ?? process.env.NEXT_PUBLIC_KMIND_ENDPOINT, statusEndpoint: config.statusEndpoint ?? process.env.NEXT_PUBLIC_KMIND_STATUS_ENDPOINT, ...config });
|
|
8
|
+
}
|
|
9
|
+
function KmindNextNavigation() {
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const notify = () => recordMetric("navigation.route_change", 1, { route: location.pathname });
|
|
12
|
+
const original = history.pushState;
|
|
13
|
+
history.pushState = function(...args) {
|
|
14
|
+
original.apply(this, args);
|
|
15
|
+
notify();
|
|
16
|
+
};
|
|
17
|
+
addEventListener("popstate", notify);
|
|
18
|
+
return () => {
|
|
19
|
+
history.pushState = original;
|
|
20
|
+
removeEventListener("popstate", notify);
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
var KmindNextErrorBoundary = class extends Component {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.state = { failed: false };
|
|
29
|
+
}
|
|
30
|
+
static getDerivedStateFromError() {
|
|
31
|
+
return { failed: true };
|
|
32
|
+
}
|
|
33
|
+
componentDidCatch(error, info) {
|
|
34
|
+
logger.error(error.message, { "exception.stacktrace": error.stack ?? "", "next.component_stack": info.componentStack });
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
return this.state.failed ? this.props.fallback ?? null : this.props.children;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
KmindNextErrorBoundary,
|
|
42
|
+
KmindNextNavigation,
|
|
43
|
+
initKmindNext
|
|
44
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kmind-apm-web-next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
|
8
|
+
"scripts": { "build": "tsup" },
|
|
9
|
+
"dependencies": { "kmind-apm-web": "*" },
|
|
10
|
+
"peerDependencies": { "next": ">=13", "react": ">=18" },
|
|
11
|
+
"devDependencies": { "@types/node": "^22.15.3", "@types/react": "^19.1.2", "react": "^19.1.0", "tsup": "^8.5.0", "typescript": "^5.8.3" }
|
|
12
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Component, type ErrorInfo, type ReactNode, useEffect } from "react";
|
|
3
|
+
import { init, logger, recordMetric, type KmindConfig } from "kmind-apm-web";
|
|
4
|
+
|
|
5
|
+
export function initKmindNext(config: Partial<KmindConfig> = {}): void {
|
|
6
|
+
init({ serviceName: config.serviceName ?? process.env.NEXT_PUBLIC_KMIND_SERVICE_NAME ?? "next-app", clientKey: config.clientKey ?? process.env.NEXT_PUBLIC_KMIND_CLIENT_KEY ?? "", endpoint: config.endpoint ?? process.env.NEXT_PUBLIC_KMIND_ENDPOINT, statusEndpoint: config.statusEndpoint ?? process.env.NEXT_PUBLIC_KMIND_STATUS_ENDPOINT, ...config });
|
|
7
|
+
}
|
|
8
|
+
export function KmindNextNavigation(): null {
|
|
9
|
+
useEffect(() => { const notify = () => recordMetric("navigation.route_change", 1, { route: location.pathname }); const original = history.pushState; history.pushState = function(...args) { original.apply(this, args); notify(); }; addEventListener("popstate", notify); return () => { history.pushState = original; removeEventListener("popstate", notify); }; }, []);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
export class KmindNextErrorBoundary extends Component<{ children: ReactNode; fallback?: ReactNode }, { failed: boolean }> {
|
|
13
|
+
state = { failed: false };
|
|
14
|
+
static getDerivedStateFromError() { return { failed: true }; }
|
|
15
|
+
componentDidCatch(error: Error, info: ErrorInfo) { logger.error(error.message, { "exception.stacktrace": error.stack ?? "", "next.component_stack": info.componentStack }); }
|
|
16
|
+
render() { return this.state.failed ? this.props.fallback ?? null : this.props.children; }
|
|
17
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "compilerOptions": { "target": "ES2020", "module": "ESNext", "moduleResolution": "Bundler", "strict": true, "jsx": "react-jsx", "declaration": true, "lib": ["DOM", "ES2020"], "types": ["node"], "skipLibCheck": true }, "include": ["src"] }
|
package/tsup.config.ts
ADDED