reroute-js 0.25.2 → 0.26.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 +150 -52
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +446 -150
- package/cli/bin.js.map +13 -9
- package/cli/index.d.ts +1 -1
- package/cli/index.js +4 -4
- package/cli/index.js.map +1 -1
- package/cli/src/cli.d.ts +1 -1
- package/cli/src/commands/analyze.d.ts +1 -1
- package/cli/src/commands/build.d.ts +1 -1
- package/cli/src/commands/dev.d.ts +1 -1
- package/cli/src/commands/gen.d.ts +1 -1
- package/cli/src/commands/gen.d.ts.map +1 -1
- package/cli/src/commands/index.d.ts +1 -1
- package/cli/src/commands/init.d.ts +1 -1
- package/cli/src/commands/lib/assets.d.ts +1 -1
- package/cli/src/commands/lib/bundler.d.ts +1 -1
- package/cli/src/commands/lib/command.d.ts +1 -1
- package/cli/src/commands/lib/env.d.ts +1 -1
- package/cli/src/commands/lib/index.d.ts +1 -1
- package/cli/src/commands/lib/log.d.ts +1 -1
- package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
- package/cli/src/commands/lib/markdown/index.d.ts +1 -1
- package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
- package/cli/src/commands/lib/production.d.ts +1 -1
- package/cli/src/commands/lib/server.d.ts +1 -1
- package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
- package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
- package/cli/src/commands/lib/tailwind.d.ts +1 -1
- package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
- package/cli/src/commands/lib/version.d.ts +1 -1
- package/cli/src/commands/og.d.ts +1 -1
- package/cli/src/commands/start.d.ts +1 -1
- package/cli/src/index.d.ts +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +912 -589
- package/core/index.js.map +22 -14
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/config.d.ts +243 -2
- package/core/src/config.d.ts.map +1 -1
- package/core/src/content/discovery.d.ts +1 -1
- package/core/src/content/index.d.ts +1 -1
- package/core/src/content/metadata.d.ts +1 -1
- package/core/src/index.d.ts +1 -1
- package/core/src/llms/extractor.d.ts +1 -1
- package/core/src/llms/formatter.d.ts +1 -1
- package/core/src/llms/full-generator.d.ts +1 -1
- package/core/src/llms/index-generator.d.ts +1 -1
- package/core/src/llms/index.d.ts +1 -1
- package/core/src/og/discovery.d.ts +1 -1
- package/core/src/og/index.d.ts +1 -1
- package/core/src/og/meta.d.ts +1 -1
- package/core/src/og/render.d.ts +1 -1
- package/core/src/og/types.d.ts +1 -1
- package/core/src/robots/discovery.d.ts +1 -1
- package/core/src/robots/generator.d.ts +1 -1
- package/core/src/robots/index.d.ts +1 -1
- package/core/src/robots/policies.d.ts +1 -1
- package/core/src/rss/discovery.d.ts +1 -1
- package/core/src/rss/generator.d.ts +1 -1
- package/core/src/rss/index.d.ts +1 -1
- package/core/src/sitemap/discovery.d.ts +1 -1
- package/core/src/sitemap/generator.d.ts +1 -1
- package/core/src/sitemap/index.d.ts +1 -1
- package/core/src/ssr/index.d.ts +1 -1
- package/core/src/ssr/lib/cache.d.ts +1 -1
- package/core/src/ssr/lib/collections.d.ts +1 -1
- package/core/src/ssr/lib/compression.d.ts +1 -1
- package/core/src/ssr/lib/compute/content.d.ts +1 -1
- package/core/src/ssr/lib/compute/index.d.ts +1 -1
- package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
- package/core/src/ssr/lib/compute/routes.d.ts +1 -1
- package/core/src/ssr/lib/data.d.ts +1 -1
- package/core/src/ssr/lib/html.d.ts +1 -1
- package/core/src/ssr/lib/imports.d.ts +1 -1
- package/core/src/ssr/lib/index.d.ts +1 -1
- package/core/src/ssr/lib/layouts.d.ts +1 -1
- package/core/src/ssr/lib/metadata.d.ts +1 -1
- package/core/src/ssr/lib/mime.d.ts +1 -1
- package/core/src/ssr/lib/modules.d.ts +1 -1
- package/core/src/ssr/lib/path.d.ts +1 -1
- package/core/src/ssr/lib/preload.d.ts +1 -1
- package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
- package/core/src/ssr/lib/scripts/data.d.ts +2 -2
- package/core/src/ssr/lib/scripts/data.d.ts.map +1 -1
- package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
- package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
- package/core/src/ssr/lib/scripts/index.d.ts +1 -1
- package/core/src/ssr/lib/seed.d.ts +1 -1
- package/core/src/ssr/lib/setup.d.ts +4 -2
- package/core/src/ssr/lib/setup.d.ts.map +1 -1
- package/core/src/ssr/lib/styles.d.ts +1 -1
- package/core/src/ssr/lib/template.d.ts +1 -1
- package/core/src/ssr/lib/types.d.ts +1 -1
- package/core/src/ssr/render.d.ts +4 -2
- package/core/src/ssr/render.d.ts.map +1 -1
- package/core/src/ssr/stream.d.ts +4 -2
- package/core/src/ssr/stream.d.ts.map +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +715 -468
- package/elysia/index.js.map +15 -11
- package/elysia/src/index.d.ts +1 -1
- package/elysia/src/libs/assets.d.ts +1 -1
- package/elysia/src/libs/cache.d.ts +1 -1
- package/elysia/src/libs/caching.d.ts +1 -1
- package/elysia/src/libs/http.d.ts +1 -1
- package/elysia/src/libs/image.d.ts +1 -1
- package/elysia/src/libs/index.d.ts +1 -1
- package/elysia/src/libs/llms.d.ts +1 -1
- package/elysia/src/libs/response.d.ts +1 -1
- package/elysia/src/libs/serving.d.ts +1 -1
- package/elysia/src/plugin.d.ts +1 -1
- package/elysia/src/routes/artifacts.d.ts +1 -1
- package/elysia/src/routes/content.d.ts +1 -1
- package/elysia/src/routes/content.d.ts.map +1 -1
- package/elysia/src/routes/image.d.ts +1 -1
- package/elysia/src/routes/index.d.ts +1 -1
- package/elysia/src/routes/internal.d.ts +1 -1
- package/elysia/src/routes/llms.d.ts +1 -1
- package/elysia/src/routes/og.d.ts +1 -1
- package/elysia/src/routes/redirects.d.ts +1 -1
- package/elysia/src/routes/robots.d.ts +1 -1
- package/elysia/src/routes/rss.d.ts +1 -1
- package/elysia/src/routes/search.d.ts +1 -1
- package/elysia/src/routes/sitemap.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts +1 -1
- package/elysia/src/routes/ssr.d.ts.map +1 -1
- package/elysia/src/routes/static.d.ts +1 -1
- package/elysia/src/routes/static.d.ts.map +1 -1
- package/elysia/src/types.d.ts +1 -1
- package/package.json +2 -9
- package/react/index.d.ts +1 -1
- package/react/index.js +2 -2
- package/react/index.js.map +1 -1
- package/react/src/components/ClientOnly.d.ts +1 -1
- package/react/src/components/ContentRoute.d.ts +1 -1
- package/react/src/components/Image.d.ts +1 -1
- package/react/src/components/LazyRoute.d.ts +1 -1
- package/react/src/components/Link.d.ts +1 -1
- package/react/src/components/Markdown.d.ts +1 -1
- package/react/src/components/Outlet.d.ts +1 -1
- package/react/src/components/index.d.ts +1 -1
- package/react/src/hooks/index.d.ts +1 -1
- package/react/src/hooks/useContent.d.ts +1 -1
- package/react/src/hooks/useData.d.ts +1 -1
- package/react/src/hooks/useFeed.d.ts +1 -1
- package/react/src/hooks/useLayoutData.d.ts +1 -1
- package/react/src/hooks/useLlms.d.ts +1 -1
- package/react/src/hooks/useNavigate.d.ts +1 -1
- package/react/src/hooks/useParams.d.ts +1 -1
- package/react/src/hooks/useRouter.d.ts +1 -1
- package/react/src/hooks/useSearch.d.ts +1 -1
- package/react/src/hooks/useSearchParams.d.ts +1 -1
- package/react/src/hooks/useToc.d.ts +1 -1
- package/react/src/index.d.ts +1 -1
- package/react/src/lib/collection.d.ts +1 -1
- package/react/src/lib/content.d.ts +1 -1
- package/react/src/lib/head.d.ts +1 -1
- package/react/src/lib/index.d.ts +1 -1
- package/react/src/lib/lazy-route.d.ts +1 -1
- package/react/src/lib/route-loader.d.ts +1 -1
- package/react/src/providers/ContentProvider.d.ts +1 -1
- package/react/src/providers/RerouteProvider.d.ts +1 -1
- package/react/src/providers/RouterProvider.d.ts +1 -1
- package/react/src/providers/index.d.ts +1 -1
- package/react/src/types/any.d.ts +1 -1
- package/react/src/types/index.d.ts +1 -1
- package/react/src/types/router.d.ts +1 -1
- package/telemetry/react.d.ts +2 -2
- package/telemetry/react.d.ts.map +1 -1
- package/telemetry/react.js +167 -185
- package/telemetry/react.js.map +7 -6
- package/telemetry/{index.d.ts → server.d.ts} +2 -2
- package/telemetry/server.d.ts.map +1 -0
- package/telemetry/server.js +1134 -0
- package/telemetry/server.js.map +44 -0
- package/telemetry/src/{browser/react.d.ts → react/api.d.ts} +4 -12
- package/telemetry/src/react/api.d.ts.map +1 -0
- package/telemetry/{browser.d.ts → src/react/index.d.ts} +4 -3
- package/telemetry/src/react/index.d.ts.map +1 -0
- package/telemetry/src/{browser/index.d.ts → react/telemetry.d.ts} +13 -13
- package/telemetry/src/react/telemetry.d.ts.map +1 -0
- package/telemetry/src/server/index.d.ts +3 -101
- package/telemetry/src/server/index.d.ts.map +1 -1
- package/telemetry/src/server/instrumentation.d.ts +62 -0
- package/telemetry/src/server/instrumentation.d.ts.map +1 -0
- package/telemetry/src/server/plugin.d.ts +72 -0
- package/telemetry/src/server/plugin.d.ts.map +1 -0
- package/telemetry/browser.d.ts.map +0 -1
- package/telemetry/browser.js +0 -382
- package/telemetry/browser.js.map +0 -10
- package/telemetry/index.d.ts.map +0 -1
- package/telemetry/index.js +0 -509
- package/telemetry/index.js.map +0 -10
- package/telemetry/src/browser/index.d.ts.map +0 -1
- package/telemetry/src/browser/react.d.ts.map +0 -1
package/react/src/index.d.ts
CHANGED
package/react/src/lib/head.d.ts
CHANGED
package/react/src/lib/index.d.ts
CHANGED
package/react/src/types/any.d.ts
CHANGED
package/telemetry/react.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reroute-js v0.
|
|
2
|
+
* reroute-js v0.26.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2025 stewones <hi@stewan.io>
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Built with Bun <3
|
|
9
9
|
*/
|
|
10
|
-
export * from './src/
|
|
10
|
+
export * from './src/react';
|
|
11
11
|
//# sourceMappingURL=react.d.ts.map
|
package/telemetry/react.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../packages/telemetry/react.
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../packages/telemetry/react.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/telemetry/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reroute-js v0.
|
|
2
|
+
* reroute-js v0.26.0
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @copyright 2025 stewones <hi@stewan.io>
|
|
@@ -41,11 +41,138 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
41
41
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
// packages/telemetry/src/
|
|
44
|
+
// packages/telemetry/src/react/api.tsx
|
|
45
|
+
import {
|
|
46
|
+
createContext,
|
|
47
|
+
useContext,
|
|
48
|
+
useEffect,
|
|
49
|
+
useMemo,
|
|
50
|
+
useRef,
|
|
51
|
+
useState
|
|
52
|
+
} from "react";
|
|
53
|
+
import { jsx } from "react/jsx-runtime";
|
|
54
|
+
function getBrowserTelemetryConfig() {
|
|
55
|
+
if (typeof window !== "undefined") {
|
|
56
|
+
const globalConfig = window.__REROUTE_TELEMETRY_BROWSER__;
|
|
57
|
+
if (globalConfig) {
|
|
58
|
+
return globalConfig;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
function TelemetryProvider({
|
|
64
|
+
children,
|
|
65
|
+
enabled,
|
|
66
|
+
serviceName,
|
|
67
|
+
serviceVersion,
|
|
68
|
+
otlpEndpoint,
|
|
69
|
+
apiKey,
|
|
70
|
+
environment,
|
|
71
|
+
enableConsoleCapture
|
|
72
|
+
}) {
|
|
73
|
+
const [telemetryReady, setTelemetryReady] = useState(false);
|
|
74
|
+
const [telemetryAPI, setTelemetryAPI] = useState(null);
|
|
75
|
+
const hasInitialized = useRef(false);
|
|
76
|
+
const globalConfig = useMemo(() => getBrowserTelemetryConfig(), []);
|
|
77
|
+
const mergedConfig = useMemo(() => ({
|
|
78
|
+
enabled: enabled ?? globalConfig.enabled ?? false,
|
|
79
|
+
serviceName: serviceName ?? globalConfig.serviceName ?? "reroute-app-browser",
|
|
80
|
+
serviceVersion: serviceVersion ?? globalConfig.serviceVersion ?? "1.0.0",
|
|
81
|
+
otlpEndpoint: otlpEndpoint ?? globalConfig.otlpEndpoint ?? "/api/telemetry",
|
|
82
|
+
apiKey: apiKey ?? globalConfig.apiKey,
|
|
83
|
+
environment: environment ?? globalConfig.environment ?? "development",
|
|
84
|
+
enableConsoleCapture: enableConsoleCapture ?? globalConfig.enableConsoleCapture ?? true
|
|
85
|
+
}), [
|
|
86
|
+
enabled,
|
|
87
|
+
serviceName,
|
|
88
|
+
serviceVersion,
|
|
89
|
+
otlpEndpoint,
|
|
90
|
+
apiKey,
|
|
91
|
+
environment,
|
|
92
|
+
enableConsoleCapture,
|
|
93
|
+
globalConfig
|
|
94
|
+
]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (IS_SERVER) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!mergedConfig.enabled) {
|
|
100
|
+
console.debug("[TelemetryProvider] Browser telemetry disabled");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (hasInitialized.current) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
hasInitialized.current = true;
|
|
107
|
+
Promise.resolve().then(() => (init_react2(), exports_react)).then((module) => {
|
|
108
|
+
module.initBrowserTelemetry(mergedConfig);
|
|
109
|
+
setTelemetryAPI(module);
|
|
110
|
+
setTelemetryReady(true);
|
|
111
|
+
console.debug("[TelemetryProvider] Browser telemetry initialized");
|
|
112
|
+
}).catch((error) => {
|
|
113
|
+
console.warn("[TelemetryProvider] Failed to load telemetry:", error);
|
|
114
|
+
hasInitialized.current = false;
|
|
115
|
+
});
|
|
116
|
+
}, [mergedConfig]);
|
|
117
|
+
const contextValue = useMemo(() => ({
|
|
118
|
+
createCustomSpan: (name, attributes) => {
|
|
119
|
+
if (telemetryReady && telemetryAPI) {
|
|
120
|
+
return telemetryAPI.createSpan(name, attributes);
|
|
121
|
+
}
|
|
122
|
+
return noopSpan;
|
|
123
|
+
},
|
|
124
|
+
trackCustomEvent: (eventName, attributes) => {
|
|
125
|
+
if (telemetryReady && telemetryAPI) {
|
|
126
|
+
telemetryAPI.trackEvent(eventName, attributes);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
trackCustomError: (error, context) => {
|
|
130
|
+
if (telemetryReady && telemetryAPI) {
|
|
131
|
+
telemetryAPI.trackError(error, context);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}), [telemetryReady, telemetryAPI]);
|
|
135
|
+
if (IS_SERVER) {
|
|
136
|
+
return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
|
|
137
|
+
value: noopContext,
|
|
138
|
+
children
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
|
|
142
|
+
value: contextValue,
|
|
143
|
+
children
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function useTelemetry() {
|
|
147
|
+
const context = useContext(TelemetryContext);
|
|
148
|
+
if (!context) {
|
|
149
|
+
throw new Error("useTelemetry must be used within a TelemetryProvider");
|
|
150
|
+
}
|
|
151
|
+
return context;
|
|
152
|
+
}
|
|
153
|
+
var IS_SERVER, noopSpan, noopContext, TelemetryContext;
|
|
154
|
+
var init_api = __esm(() => {
|
|
155
|
+
IS_SERVER = typeof window === "undefined";
|
|
156
|
+
noopSpan = {
|
|
157
|
+
setAttributes: () => {},
|
|
158
|
+
setStatus: () => {},
|
|
159
|
+
recordException: () => {},
|
|
160
|
+
end: () => {}
|
|
161
|
+
};
|
|
162
|
+
noopContext = {
|
|
163
|
+
createCustomSpan: () => noopSpan,
|
|
164
|
+
trackCustomEvent: () => {},
|
|
165
|
+
trackCustomError: () => {}
|
|
166
|
+
};
|
|
167
|
+
TelemetryContext = createContext(null);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// packages/telemetry/src/react/telemetry.ts
|
|
45
171
|
async function initBrowserTelemetry(options = {}) {
|
|
46
|
-
if (
|
|
172
|
+
if (IS_SERVER2 || isInitialized) {
|
|
47
173
|
return;
|
|
48
174
|
}
|
|
175
|
+
isInitialized = true;
|
|
49
176
|
try {
|
|
50
177
|
const [
|
|
51
178
|
{ getWebAutoInstrumentations },
|
|
@@ -70,9 +197,8 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
70
197
|
const SERVICE_NAME = options.serviceName || "reroute-app-browser";
|
|
71
198
|
const SERVICE_VERSION = options.serviceVersion || "1.0.0";
|
|
72
199
|
const OTLP_ENDPOINT = options.otlpEndpoint || "/api/telemetry";
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const ENABLE_CONSOLE_CAPTURE = options.enableConsoleCapture ?? IS_PRODUCTION;
|
|
200
|
+
const ENVIRONMENT = options.environment || env?.MODE || "development";
|
|
201
|
+
const ENABLE_CONSOLE_CAPTURE = options.enableConsoleCapture ?? true;
|
|
76
202
|
console.log(`[browser-telemetry] Initializing with endpoint: ${OTLP_ENDPOINT}`);
|
|
77
203
|
const headers = {};
|
|
78
204
|
const apiKey = options.apiKey || env?.REROUTE_SIGNOZ_API_KEY;
|
|
@@ -86,7 +212,7 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
86
212
|
const resource = resourceFromAttributes({
|
|
87
213
|
[ATTR_SERVICE_NAME]: SERVICE_NAME,
|
|
88
214
|
[ATTR_SERVICE_VERSION]: SERVICE_VERSION,
|
|
89
|
-
"deployment.environment":
|
|
215
|
+
"deployment.environment": ENVIRONMENT,
|
|
90
216
|
"browser.user_agent": navigator.userAgent,
|
|
91
217
|
"browser.language": navigator.language,
|
|
92
218
|
"browser.platform": navigator.platform,
|
|
@@ -109,11 +235,10 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
109
235
|
instrumentations: [
|
|
110
236
|
getWebAutoInstrumentations({
|
|
111
237
|
"@opentelemetry/instrumentation-document-load": {
|
|
112
|
-
enabled:
|
|
238
|
+
enabled: false
|
|
113
239
|
},
|
|
114
240
|
"@opentelemetry/instrumentation-user-interaction": {
|
|
115
|
-
enabled:
|
|
116
|
-
eventNames: ["click", "submit"]
|
|
241
|
+
enabled: false
|
|
117
242
|
},
|
|
118
243
|
"@opentelemetry/instrumentation-fetch": {
|
|
119
244
|
enabled: true,
|
|
@@ -129,17 +254,13 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
129
254
|
]
|
|
130
255
|
});
|
|
131
256
|
setupErrorHandlers().catch((err) => console.error("[browser-telemetry] Error handler setup failed:", err));
|
|
132
|
-
if (ENABLE_WEB_VITALS) {
|
|
133
|
-
setupWebVitals().catch((err) => console.error("[browser-telemetry] Web Vitals setup failed:", err));
|
|
134
|
-
}
|
|
135
257
|
if (ENABLE_CONSOLE_CAPTURE) {
|
|
136
258
|
setupConsoleCapture().catch((err) => console.error("[browser-telemetry] Console capture setup failed:", err));
|
|
137
259
|
}
|
|
138
|
-
setupVisibilityTracking().catch((err) => console.error("[browser-telemetry] Visibility tracking setup failed:", err));
|
|
139
|
-
isInitialized = true;
|
|
140
260
|
console.log("[browser-telemetry] Initialized successfully");
|
|
141
261
|
} catch (error) {
|
|
142
262
|
console.error("[browser-telemetry] Failed to initialize:", error);
|
|
263
|
+
isInitialized = false;
|
|
143
264
|
}
|
|
144
265
|
}
|
|
145
266
|
async function setupErrorHandlers() {
|
|
@@ -151,14 +272,15 @@ async function setupErrorHandlers() {
|
|
|
151
272
|
startTime: Date.now()
|
|
152
273
|
});
|
|
153
274
|
const stackTrace = event.error?.stack || "";
|
|
275
|
+
const errorMessage = event.message || event.error?.message || "Unknown error";
|
|
154
276
|
span.setStatus({
|
|
155
277
|
code: SpanStatusCode.ERROR,
|
|
156
|
-
message:
|
|
278
|
+
message: errorMessage
|
|
157
279
|
});
|
|
158
280
|
span.setAttributes({
|
|
159
281
|
error: true,
|
|
160
282
|
"error.type": event.error?.name || "UncaughtError",
|
|
161
|
-
"error.message":
|
|
283
|
+
"error.message": errorMessage,
|
|
162
284
|
"error.stack": stackTrace,
|
|
163
285
|
"error.filename": event.filename || "",
|
|
164
286
|
"error.lineno": event.lineno || 0,
|
|
@@ -178,10 +300,10 @@ async function setupErrorHandlers() {
|
|
|
178
300
|
});
|
|
179
301
|
}
|
|
180
302
|
span.end();
|
|
303
|
+
console.error("[browser-telemetry] Uncaught error:", event.error || event.message);
|
|
181
304
|
} catch (telemetryError) {
|
|
182
305
|
console.error("[browser-telemetry] Error tracking failed:", telemetryError);
|
|
183
306
|
}
|
|
184
|
-
console.error("[browser-telemetry] Uncaught error:", event.error || event.message);
|
|
185
307
|
});
|
|
186
308
|
window.addEventListener("unhandledrejection", (event) => {
|
|
187
309
|
try {
|
|
@@ -222,39 +344,6 @@ async function setupErrorHandlers() {
|
|
|
222
344
|
console.error("[browser-telemetry] Unhandled rejection:", event.reason);
|
|
223
345
|
});
|
|
224
346
|
}
|
|
225
|
-
async function setupWebVitals() {
|
|
226
|
-
try {
|
|
227
|
-
const { onLCP, onCLS, onTTFB, onINP } = await import("web-vitals");
|
|
228
|
-
const { trace } = await import("@opentelemetry/api");
|
|
229
|
-
const tracer = trace.getTracer("web-vitals");
|
|
230
|
-
const sendToAnalytics = (metric) => {
|
|
231
|
-
try {
|
|
232
|
-
const span = tracer.startSpan(`web_vitals.${metric.name}`, {
|
|
233
|
-
startTime: Date.now() - metric.value
|
|
234
|
-
});
|
|
235
|
-
span.setAttributes({
|
|
236
|
-
"metric.name": metric.name,
|
|
237
|
-
"metric.value": metric.value,
|
|
238
|
-
"metric.rating": metric.rating,
|
|
239
|
-
"metric.delta": metric.delta,
|
|
240
|
-
"metric.id": metric.id,
|
|
241
|
-
"browser.url": window.location.href,
|
|
242
|
-
"browser.pathname": window.location.pathname
|
|
243
|
-
});
|
|
244
|
-
span.end();
|
|
245
|
-
} catch (error) {
|
|
246
|
-
console.error("[browser-telemetry] Web Vitals tracking failed:", error);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
onLCP(sendToAnalytics);
|
|
250
|
-
onCLS(sendToAnalytics);
|
|
251
|
-
onTTFB(sendToAnalytics);
|
|
252
|
-
onINP(sendToAnalytics);
|
|
253
|
-
console.log("[browser-telemetry] Web Vitals tracking enabled");
|
|
254
|
-
} catch (error) {
|
|
255
|
-
console.warn("[browser-telemetry] Web Vitals not available:", error);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
347
|
async function setupConsoleCapture() {
|
|
259
348
|
const { trace } = await import("@opentelemetry/api");
|
|
260
349
|
const tracer = trace.getTracer("console");
|
|
@@ -278,23 +367,8 @@ async function setupConsoleCapture() {
|
|
|
278
367
|
wrappedError.__telemetry_captured__ = true;
|
|
279
368
|
console.error = wrappedError;
|
|
280
369
|
}
|
|
281
|
-
async function setupVisibilityTracking() {
|
|
282
|
-
const { trace } = await import("@opentelemetry/api");
|
|
283
|
-
const tracer = trace.getTracer("visibility");
|
|
284
|
-
document.addEventListener("visibilitychange", () => {
|
|
285
|
-
try {
|
|
286
|
-
const span = tracer.startSpan("browser.visibility_change");
|
|
287
|
-
span.setAttributes({
|
|
288
|
-
"visibility.state": document.visibilityState,
|
|
289
|
-
"browser.url": window.location.href,
|
|
290
|
-
"browser.timestamp": new Date().toISOString()
|
|
291
|
-
});
|
|
292
|
-
span.end();
|
|
293
|
-
} catch {}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
370
|
function createSpan(name, attributes = {}) {
|
|
297
|
-
if (
|
|
371
|
+
if (IS_SERVER2 || !isInitialized) {
|
|
298
372
|
return {
|
|
299
373
|
setAttributes: () => {},
|
|
300
374
|
setStatus: () => {},
|
|
@@ -326,7 +400,7 @@ function createSpan(name, attributes = {}) {
|
|
|
326
400
|
}
|
|
327
401
|
}
|
|
328
402
|
function trackEvent(eventName, attributes = {}) {
|
|
329
|
-
if (
|
|
403
|
+
if (IS_SERVER2 || !isInitialized) {
|
|
330
404
|
return;
|
|
331
405
|
}
|
|
332
406
|
try {
|
|
@@ -337,7 +411,7 @@ function trackEvent(eventName, attributes = {}) {
|
|
|
337
411
|
}
|
|
338
412
|
}
|
|
339
413
|
function trackError(error, context = {}) {
|
|
340
|
-
if (
|
|
414
|
+
if (IS_SERVER2 || !isInitialized) {
|
|
341
415
|
return;
|
|
342
416
|
}
|
|
343
417
|
try {
|
|
@@ -378,133 +452,41 @@ async function shutdownTelemetry() {
|
|
|
378
452
|
console.log("[browser-telemetry] Shut down successfully");
|
|
379
453
|
}
|
|
380
454
|
}
|
|
381
|
-
var
|
|
382
|
-
var
|
|
383
|
-
|
|
455
|
+
var IS_SERVER2, isInitialized = false, tracerProvider = null;
|
|
456
|
+
var init_telemetry = __esm(() => {
|
|
457
|
+
IS_SERVER2 = typeof window === "undefined";
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// packages/telemetry/src/react/index.ts
|
|
461
|
+
var init_react = __esm(() => {
|
|
462
|
+
init_api();
|
|
463
|
+
init_telemetry();
|
|
384
464
|
});
|
|
385
465
|
|
|
386
|
-
// packages/telemetry/
|
|
387
|
-
var
|
|
388
|
-
__export(
|
|
466
|
+
// packages/telemetry/react.ts
|
|
467
|
+
var exports_react = {};
|
|
468
|
+
__export(exports_react, {
|
|
469
|
+
useTelemetry: () => useTelemetry,
|
|
389
470
|
trackEvent: () => trackEvent,
|
|
390
471
|
trackError: () => trackError,
|
|
391
472
|
shutdownTelemetry: () => shutdownTelemetry,
|
|
392
473
|
initBrowserTelemetry: () => initBrowserTelemetry,
|
|
393
|
-
createSpan: () => createSpan
|
|
474
|
+
createSpan: () => createSpan,
|
|
475
|
+
TelemetryProvider: () => TelemetryProvider
|
|
394
476
|
});
|
|
395
|
-
var
|
|
396
|
-
|
|
477
|
+
var init_react2 = __esm(() => {
|
|
478
|
+
init_react();
|
|
397
479
|
});
|
|
480
|
+
init_react2();
|
|
398
481
|
|
|
399
|
-
// packages/telemetry/src/browser/react.tsx
|
|
400
|
-
import {
|
|
401
|
-
createContext,
|
|
402
|
-
useContext,
|
|
403
|
-
useEffect,
|
|
404
|
-
useMemo,
|
|
405
|
-
useRef,
|
|
406
|
-
useState
|
|
407
|
-
} from "react";
|
|
408
|
-
import { jsx } from "react/jsx-runtime";
|
|
409
|
-
var IS_SERVER2 = typeof window === "undefined";
|
|
410
|
-
var noopSpan = {
|
|
411
|
-
setAttributes: () => {},
|
|
412
|
-
setStatus: () => {},
|
|
413
|
-
recordException: () => {},
|
|
414
|
-
end: () => {}
|
|
415
|
-
};
|
|
416
|
-
var noopContext = {
|
|
417
|
-
createCustomSpan: () => noopSpan,
|
|
418
|
-
trackCustomEvent: () => {},
|
|
419
|
-
trackCustomError: () => {}
|
|
420
|
-
};
|
|
421
|
-
var TelemetryContext = createContext(null);
|
|
422
|
-
function TelemetryProvider({
|
|
423
|
-
children,
|
|
424
|
-
serviceName,
|
|
425
|
-
serviceVersion,
|
|
426
|
-
otlpEndpoint,
|
|
427
|
-
apiKey,
|
|
428
|
-
isProduction,
|
|
429
|
-
enableWebVitals,
|
|
430
|
-
enableConsoleCapture
|
|
431
|
-
}) {
|
|
432
|
-
const [telemetryReady, setTelemetryReady] = useState(false);
|
|
433
|
-
const [telemetryAPI, setTelemetryAPI] = useState(null);
|
|
434
|
-
const hasInitialized = useRef(false);
|
|
435
|
-
useEffect(() => {
|
|
436
|
-
if (IS_SERVER2) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if (hasInitialized.current) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
hasInitialized.current = true;
|
|
443
|
-
Promise.resolve().then(() => (init_browser2(), exports_browser)).then((module) => {
|
|
444
|
-
module.initBrowserTelemetry({
|
|
445
|
-
serviceName,
|
|
446
|
-
serviceVersion,
|
|
447
|
-
otlpEndpoint,
|
|
448
|
-
apiKey,
|
|
449
|
-
isProduction,
|
|
450
|
-
enableWebVitals,
|
|
451
|
-
enableConsoleCapture
|
|
452
|
-
});
|
|
453
|
-
setTelemetryAPI(module);
|
|
454
|
-
setTelemetryReady(true);
|
|
455
|
-
console.debug("[TelemetryProvider] Browser telemetry initialized");
|
|
456
|
-
}).catch((error) => {
|
|
457
|
-
console.warn("[TelemetryProvider] Failed to load telemetry:", error);
|
|
458
|
-
hasInitialized.current = false;
|
|
459
|
-
});
|
|
460
|
-
}, [
|
|
461
|
-
serviceName,
|
|
462
|
-
serviceVersion,
|
|
463
|
-
otlpEndpoint,
|
|
464
|
-
apiKey,
|
|
465
|
-
isProduction,
|
|
466
|
-
enableWebVitals,
|
|
467
|
-
enableConsoleCapture
|
|
468
|
-
]);
|
|
469
|
-
const contextValue = useMemo(() => ({
|
|
470
|
-
createCustomSpan: (name, attributes) => {
|
|
471
|
-
if (telemetryReady && telemetryAPI) {
|
|
472
|
-
return telemetryAPI.createSpan(name, attributes);
|
|
473
|
-
}
|
|
474
|
-
return noopSpan;
|
|
475
|
-
},
|
|
476
|
-
trackCustomEvent: (eventName, attributes) => {
|
|
477
|
-
if (telemetryReady && telemetryAPI) {
|
|
478
|
-
telemetryAPI.trackEvent(eventName, attributes);
|
|
479
|
-
}
|
|
480
|
-
},
|
|
481
|
-
trackCustomError: (error, context) => {
|
|
482
|
-
if (telemetryReady && telemetryAPI) {
|
|
483
|
-
telemetryAPI.trackError(error, context);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}), [telemetryReady, telemetryAPI]);
|
|
487
|
-
if (IS_SERVER2) {
|
|
488
|
-
return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
|
|
489
|
-
value: noopContext,
|
|
490
|
-
children
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
|
|
494
|
-
value: contextValue,
|
|
495
|
-
children
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
function useTelemetry() {
|
|
499
|
-
const context = useContext(TelemetryContext);
|
|
500
|
-
if (!context) {
|
|
501
|
-
throw new Error("useTelemetry must be used within a TelemetryProvider");
|
|
502
|
-
}
|
|
503
|
-
return context;
|
|
504
|
-
}
|
|
505
482
|
export {
|
|
506
483
|
useTelemetry,
|
|
484
|
+
trackEvent,
|
|
485
|
+
trackError,
|
|
486
|
+
shutdownTelemetry,
|
|
487
|
+
initBrowserTelemetry,
|
|
488
|
+
createSpan,
|
|
507
489
|
TelemetryProvider
|
|
508
490
|
};
|
|
509
491
|
|
|
510
|
-
//# debugId=
|
|
492
|
+
//# debugId=EF6D54D3079D2BAE64756E2164756E21
|