reroute-js 0.25.3 → 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 +164 -183
- 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 -383
- package/telemetry/browser.js.map +0 -10
- package/telemetry/index.d.ts.map +0 -1
- package/telemetry/index.js +0 -525
- 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,9 +41,135 @@ 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
|
}
|
|
49
175
|
isInitialized = true;
|
|
@@ -71,9 +197,8 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
71
197
|
const SERVICE_NAME = options.serviceName || "reroute-app-browser";
|
|
72
198
|
const SERVICE_VERSION = options.serviceVersion || "1.0.0";
|
|
73
199
|
const OTLP_ENDPOINT = options.otlpEndpoint || "/api/telemetry";
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const ENABLE_CONSOLE_CAPTURE = options.enableConsoleCapture ?? IS_PRODUCTION;
|
|
200
|
+
const ENVIRONMENT = options.environment || env?.MODE || "development";
|
|
201
|
+
const ENABLE_CONSOLE_CAPTURE = options.enableConsoleCapture ?? true;
|
|
77
202
|
console.log(`[browser-telemetry] Initializing with endpoint: ${OTLP_ENDPOINT}`);
|
|
78
203
|
const headers = {};
|
|
79
204
|
const apiKey = options.apiKey || env?.REROUTE_SIGNOZ_API_KEY;
|
|
@@ -87,7 +212,7 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
87
212
|
const resource = resourceFromAttributes({
|
|
88
213
|
[ATTR_SERVICE_NAME]: SERVICE_NAME,
|
|
89
214
|
[ATTR_SERVICE_VERSION]: SERVICE_VERSION,
|
|
90
|
-
"deployment.environment":
|
|
215
|
+
"deployment.environment": ENVIRONMENT,
|
|
91
216
|
"browser.user_agent": navigator.userAgent,
|
|
92
217
|
"browser.language": navigator.language,
|
|
93
218
|
"browser.platform": navigator.platform,
|
|
@@ -113,8 +238,7 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
113
238
|
enabled: false
|
|
114
239
|
},
|
|
115
240
|
"@opentelemetry/instrumentation-user-interaction": {
|
|
116
|
-
enabled:
|
|
117
|
-
eventNames: ["click", "submit"]
|
|
241
|
+
enabled: false
|
|
118
242
|
},
|
|
119
243
|
"@opentelemetry/instrumentation-fetch": {
|
|
120
244
|
enabled: true,
|
|
@@ -130,13 +254,9 @@ async function initBrowserTelemetry(options = {}) {
|
|
|
130
254
|
]
|
|
131
255
|
});
|
|
132
256
|
setupErrorHandlers().catch((err) => console.error("[browser-telemetry] Error handler setup failed:", err));
|
|
133
|
-
if (ENABLE_WEB_VITALS) {
|
|
134
|
-
setupWebVitals().catch((err) => console.error("[browser-telemetry] Web Vitals setup failed:", err));
|
|
135
|
-
}
|
|
136
257
|
if (ENABLE_CONSOLE_CAPTURE) {
|
|
137
258
|
setupConsoleCapture().catch((err) => console.error("[browser-telemetry] Console capture setup failed:", err));
|
|
138
259
|
}
|
|
139
|
-
setupVisibilityTracking().catch((err) => console.error("[browser-telemetry] Visibility tracking setup failed:", err));
|
|
140
260
|
console.log("[browser-telemetry] Initialized successfully");
|
|
141
261
|
} catch (error) {
|
|
142
262
|
console.error("[browser-telemetry] Failed to initialize:", error);
|
|
@@ -152,14 +272,15 @@ async function setupErrorHandlers() {
|
|
|
152
272
|
startTime: Date.now()
|
|
153
273
|
});
|
|
154
274
|
const stackTrace = event.error?.stack || "";
|
|
275
|
+
const errorMessage = event.message || event.error?.message || "Unknown error";
|
|
155
276
|
span.setStatus({
|
|
156
277
|
code: SpanStatusCode.ERROR,
|
|
157
|
-
message:
|
|
278
|
+
message: errorMessage
|
|
158
279
|
});
|
|
159
280
|
span.setAttributes({
|
|
160
281
|
error: true,
|
|
161
282
|
"error.type": event.error?.name || "UncaughtError",
|
|
162
|
-
"error.message":
|
|
283
|
+
"error.message": errorMessage,
|
|
163
284
|
"error.stack": stackTrace,
|
|
164
285
|
"error.filename": event.filename || "",
|
|
165
286
|
"error.lineno": event.lineno || 0,
|
|
@@ -179,10 +300,10 @@ async function setupErrorHandlers() {
|
|
|
179
300
|
});
|
|
180
301
|
}
|
|
181
302
|
span.end();
|
|
303
|
+
console.error("[browser-telemetry] Uncaught error:", event.error || event.message);
|
|
182
304
|
} catch (telemetryError) {
|
|
183
305
|
console.error("[browser-telemetry] Error tracking failed:", telemetryError);
|
|
184
306
|
}
|
|
185
|
-
console.error("[browser-telemetry] Uncaught error:", event.error || event.message);
|
|
186
307
|
});
|
|
187
308
|
window.addEventListener("unhandledrejection", (event) => {
|
|
188
309
|
try {
|
|
@@ -223,39 +344,6 @@ async function setupErrorHandlers() {
|
|
|
223
344
|
console.error("[browser-telemetry] Unhandled rejection:", event.reason);
|
|
224
345
|
});
|
|
225
346
|
}
|
|
226
|
-
async function setupWebVitals() {
|
|
227
|
-
try {
|
|
228
|
-
const { onLCP, onCLS, onTTFB, onINP } = await import("web-vitals");
|
|
229
|
-
const { trace } = await import("@opentelemetry/api");
|
|
230
|
-
const tracer = trace.getTracer("web-vitals");
|
|
231
|
-
const sendToAnalytics = (metric) => {
|
|
232
|
-
try {
|
|
233
|
-
const span = tracer.startSpan(`web_vitals.${metric.name}`, {
|
|
234
|
-
startTime: Date.now() - metric.value
|
|
235
|
-
});
|
|
236
|
-
span.setAttributes({
|
|
237
|
-
"metric.name": metric.name,
|
|
238
|
-
"metric.value": metric.value,
|
|
239
|
-
"metric.rating": metric.rating,
|
|
240
|
-
"metric.delta": metric.delta,
|
|
241
|
-
"metric.id": metric.id,
|
|
242
|
-
"browser.url": window.location.href,
|
|
243
|
-
"browser.pathname": window.location.pathname
|
|
244
|
-
});
|
|
245
|
-
span.end();
|
|
246
|
-
} catch (error) {
|
|
247
|
-
console.error("[browser-telemetry] Web Vitals tracking failed:", error);
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
onLCP(sendToAnalytics);
|
|
251
|
-
onCLS(sendToAnalytics);
|
|
252
|
-
onTTFB(sendToAnalytics);
|
|
253
|
-
onINP(sendToAnalytics);
|
|
254
|
-
console.log("[browser-telemetry] Web Vitals tracking enabled");
|
|
255
|
-
} catch (error) {
|
|
256
|
-
console.warn("[browser-telemetry] Web Vitals not available:", error);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
347
|
async function setupConsoleCapture() {
|
|
260
348
|
const { trace } = await import("@opentelemetry/api");
|
|
261
349
|
const tracer = trace.getTracer("console");
|
|
@@ -279,23 +367,8 @@ async function setupConsoleCapture() {
|
|
|
279
367
|
wrappedError.__telemetry_captured__ = true;
|
|
280
368
|
console.error = wrappedError;
|
|
281
369
|
}
|
|
282
|
-
async function setupVisibilityTracking() {
|
|
283
|
-
const { trace } = await import("@opentelemetry/api");
|
|
284
|
-
const tracer = trace.getTracer("visibility");
|
|
285
|
-
document.addEventListener("visibilitychange", () => {
|
|
286
|
-
try {
|
|
287
|
-
const span = tracer.startSpan("browser.visibility_change");
|
|
288
|
-
span.setAttributes({
|
|
289
|
-
"visibility.state": document.visibilityState,
|
|
290
|
-
"browser.url": window.location.href,
|
|
291
|
-
"browser.timestamp": new Date().toISOString()
|
|
292
|
-
});
|
|
293
|
-
span.end();
|
|
294
|
-
} catch {}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
370
|
function createSpan(name, attributes = {}) {
|
|
298
|
-
if (
|
|
371
|
+
if (IS_SERVER2 || !isInitialized) {
|
|
299
372
|
return {
|
|
300
373
|
setAttributes: () => {},
|
|
301
374
|
setStatus: () => {},
|
|
@@ -327,7 +400,7 @@ function createSpan(name, attributes = {}) {
|
|
|
327
400
|
}
|
|
328
401
|
}
|
|
329
402
|
function trackEvent(eventName, attributes = {}) {
|
|
330
|
-
if (
|
|
403
|
+
if (IS_SERVER2 || !isInitialized) {
|
|
331
404
|
return;
|
|
332
405
|
}
|
|
333
406
|
try {
|
|
@@ -338,7 +411,7 @@ function trackEvent(eventName, attributes = {}) {
|
|
|
338
411
|
}
|
|
339
412
|
}
|
|
340
413
|
function trackError(error, context = {}) {
|
|
341
|
-
if (
|
|
414
|
+
if (IS_SERVER2 || !isInitialized) {
|
|
342
415
|
return;
|
|
343
416
|
}
|
|
344
417
|
try {
|
|
@@ -379,133 +452,41 @@ async function shutdownTelemetry() {
|
|
|
379
452
|
console.log("[browser-telemetry] Shut down successfully");
|
|
380
453
|
}
|
|
381
454
|
}
|
|
382
|
-
var
|
|
383
|
-
var
|
|
384
|
-
|
|
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();
|
|
385
464
|
});
|
|
386
465
|
|
|
387
|
-
// packages/telemetry/
|
|
388
|
-
var
|
|
389
|
-
__export(
|
|
466
|
+
// packages/telemetry/react.ts
|
|
467
|
+
var exports_react = {};
|
|
468
|
+
__export(exports_react, {
|
|
469
|
+
useTelemetry: () => useTelemetry,
|
|
390
470
|
trackEvent: () => trackEvent,
|
|
391
471
|
trackError: () => trackError,
|
|
392
472
|
shutdownTelemetry: () => shutdownTelemetry,
|
|
393
473
|
initBrowserTelemetry: () => initBrowserTelemetry,
|
|
394
|
-
createSpan: () => createSpan
|
|
474
|
+
createSpan: () => createSpan,
|
|
475
|
+
TelemetryProvider: () => TelemetryProvider
|
|
395
476
|
});
|
|
396
|
-
var
|
|
397
|
-
|
|
477
|
+
var init_react2 = __esm(() => {
|
|
478
|
+
init_react();
|
|
398
479
|
});
|
|
480
|
+
init_react2();
|
|
399
481
|
|
|
400
|
-
// packages/telemetry/src/browser/react.tsx
|
|
401
|
-
import {
|
|
402
|
-
createContext,
|
|
403
|
-
useContext,
|
|
404
|
-
useEffect,
|
|
405
|
-
useMemo,
|
|
406
|
-
useRef,
|
|
407
|
-
useState
|
|
408
|
-
} from "react";
|
|
409
|
-
import { jsx } from "react/jsx-runtime";
|
|
410
|
-
var IS_SERVER2 = typeof window === "undefined";
|
|
411
|
-
var noopSpan = {
|
|
412
|
-
setAttributes: () => {},
|
|
413
|
-
setStatus: () => {},
|
|
414
|
-
recordException: () => {},
|
|
415
|
-
end: () => {}
|
|
416
|
-
};
|
|
417
|
-
var noopContext = {
|
|
418
|
-
createCustomSpan: () => noopSpan,
|
|
419
|
-
trackCustomEvent: () => {},
|
|
420
|
-
trackCustomError: () => {}
|
|
421
|
-
};
|
|
422
|
-
var TelemetryContext = createContext(null);
|
|
423
|
-
function TelemetryProvider({
|
|
424
|
-
children,
|
|
425
|
-
serviceName,
|
|
426
|
-
serviceVersion,
|
|
427
|
-
otlpEndpoint,
|
|
428
|
-
apiKey,
|
|
429
|
-
isProduction,
|
|
430
|
-
enableWebVitals,
|
|
431
|
-
enableConsoleCapture
|
|
432
|
-
}) {
|
|
433
|
-
const [telemetryReady, setTelemetryReady] = useState(false);
|
|
434
|
-
const [telemetryAPI, setTelemetryAPI] = useState(null);
|
|
435
|
-
const hasInitialized = useRef(false);
|
|
436
|
-
useEffect(() => {
|
|
437
|
-
if (IS_SERVER2) {
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (hasInitialized.current) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
hasInitialized.current = true;
|
|
444
|
-
Promise.resolve().then(() => (init_browser2(), exports_browser)).then((module) => {
|
|
445
|
-
module.initBrowserTelemetry({
|
|
446
|
-
serviceName,
|
|
447
|
-
serviceVersion,
|
|
448
|
-
otlpEndpoint,
|
|
449
|
-
apiKey,
|
|
450
|
-
isProduction,
|
|
451
|
-
enableWebVitals,
|
|
452
|
-
enableConsoleCapture
|
|
453
|
-
});
|
|
454
|
-
setTelemetryAPI(module);
|
|
455
|
-
setTelemetryReady(true);
|
|
456
|
-
console.debug("[TelemetryProvider] Browser telemetry initialized");
|
|
457
|
-
}).catch((error) => {
|
|
458
|
-
console.warn("[TelemetryProvider] Failed to load telemetry:", error);
|
|
459
|
-
hasInitialized.current = false;
|
|
460
|
-
});
|
|
461
|
-
}, [
|
|
462
|
-
serviceName,
|
|
463
|
-
serviceVersion,
|
|
464
|
-
otlpEndpoint,
|
|
465
|
-
apiKey,
|
|
466
|
-
isProduction,
|
|
467
|
-
enableWebVitals,
|
|
468
|
-
enableConsoleCapture
|
|
469
|
-
]);
|
|
470
|
-
const contextValue = useMemo(() => ({
|
|
471
|
-
createCustomSpan: (name, attributes) => {
|
|
472
|
-
if (telemetryReady && telemetryAPI) {
|
|
473
|
-
return telemetryAPI.createSpan(name, attributes);
|
|
474
|
-
}
|
|
475
|
-
return noopSpan;
|
|
476
|
-
},
|
|
477
|
-
trackCustomEvent: (eventName, attributes) => {
|
|
478
|
-
if (telemetryReady && telemetryAPI) {
|
|
479
|
-
telemetryAPI.trackEvent(eventName, attributes);
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
trackCustomError: (error, context) => {
|
|
483
|
-
if (telemetryReady && telemetryAPI) {
|
|
484
|
-
telemetryAPI.trackError(error, context);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}), [telemetryReady, telemetryAPI]);
|
|
488
|
-
if (IS_SERVER2) {
|
|
489
|
-
return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
|
|
490
|
-
value: noopContext,
|
|
491
|
-
children
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
|
|
495
|
-
value: contextValue,
|
|
496
|
-
children
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
function useTelemetry() {
|
|
500
|
-
const context = useContext(TelemetryContext);
|
|
501
|
-
if (!context) {
|
|
502
|
-
throw new Error("useTelemetry must be used within a TelemetryProvider");
|
|
503
|
-
}
|
|
504
|
-
return context;
|
|
505
|
-
}
|
|
506
482
|
export {
|
|
507
483
|
useTelemetry,
|
|
484
|
+
trackEvent,
|
|
485
|
+
trackError,
|
|
486
|
+
shutdownTelemetry,
|
|
487
|
+
initBrowserTelemetry,
|
|
488
|
+
createSpan,
|
|
508
489
|
TelemetryProvider
|
|
509
490
|
};
|
|
510
491
|
|
|
511
|
-
//# debugId=
|
|
492
|
+
//# debugId=EF6D54D3079D2BAE64756E2164756E21
|