reroute-js 0.43.6 → 0.43.8

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.
Files changed (180) hide show
  1. package/cli/bin.d.ts +1 -1
  2. package/cli/bin.js +6 -6
  3. package/cli/bin.js.map +1 -1
  4. package/cli/index.d.ts +1 -1
  5. package/cli/index.js +4 -4
  6. package/cli/index.js.map +1 -1
  7. package/cli/src/cli.d.ts +1 -1
  8. package/cli/src/commands/analyze.d.ts +1 -1
  9. package/cli/src/commands/build.d.ts +1 -1
  10. package/cli/src/commands/dev.d.ts +1 -1
  11. package/cli/src/commands/gen.d.ts +1 -1
  12. package/cli/src/commands/index.d.ts +1 -1
  13. package/cli/src/commands/init.d.ts +1 -1
  14. package/cli/src/commands/lib/assets.d.ts +1 -1
  15. package/cli/src/commands/lib/bundler.d.ts +1 -1
  16. package/cli/src/commands/lib/command.d.ts +1 -1
  17. package/cli/src/commands/lib/env.d.ts +1 -1
  18. package/cli/src/commands/lib/index.d.ts +1 -1
  19. package/cli/src/commands/lib/log.d.ts +1 -1
  20. package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
  21. package/cli/src/commands/lib/markdown/index.d.ts +1 -1
  22. package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
  23. package/cli/src/commands/lib/production.d.ts +1 -1
  24. package/cli/src/commands/lib/server.d.ts +1 -1
  25. package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
  26. package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
  27. package/cli/src/commands/lib/tailwind.d.ts +1 -1
  28. package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
  29. package/cli/src/commands/lib/version.d.ts +1 -1
  30. package/cli/src/commands/og.d.ts +1 -1
  31. package/cli/src/commands/start.d.ts +1 -1
  32. package/cli/src/index.d.ts +1 -1
  33. package/core/index.d.ts +1 -1
  34. package/core/index.js +2 -2
  35. package/core/index.js.map +1 -1
  36. package/core/src/bundler/hash.d.ts +1 -1
  37. package/core/src/bundler/index.d.ts +1 -1
  38. package/core/src/config.d.ts +1 -1
  39. package/core/src/content/discovery.d.ts +1 -1
  40. package/core/src/content/index.d.ts +1 -1
  41. package/core/src/content/metadata.d.ts +1 -1
  42. package/core/src/index.d.ts +1 -1
  43. package/core/src/llms/extractor.d.ts +1 -1
  44. package/core/src/llms/formatter.d.ts +1 -1
  45. package/core/src/llms/full-generator.d.ts +1 -1
  46. package/core/src/llms/index-generator.d.ts +1 -1
  47. package/core/src/llms/index.d.ts +1 -1
  48. package/core/src/og/discovery.d.ts +1 -1
  49. package/core/src/og/index.d.ts +1 -1
  50. package/core/src/og/meta.d.ts +1 -1
  51. package/core/src/og/render.d.ts +1 -1
  52. package/core/src/og/types.d.ts +1 -1
  53. package/core/src/robots/discovery.d.ts +1 -1
  54. package/core/src/robots/generator.d.ts +1 -1
  55. package/core/src/robots/index.d.ts +1 -1
  56. package/core/src/robots/policies.d.ts +1 -1
  57. package/core/src/rss/discovery.d.ts +1 -1
  58. package/core/src/rss/generator.d.ts +1 -1
  59. package/core/src/rss/index.d.ts +1 -1
  60. package/core/src/sitemap/discovery.d.ts +1 -1
  61. package/core/src/sitemap/generator.d.ts +1 -1
  62. package/core/src/sitemap/index.d.ts +1 -1
  63. package/core/src/ssr/index.d.ts +1 -1
  64. package/core/src/ssr/lib/cache.d.ts +1 -1
  65. package/core/src/ssr/lib/collections.d.ts +1 -1
  66. package/core/src/ssr/lib/compression.d.ts +1 -1
  67. package/core/src/ssr/lib/compute/content.d.ts +1 -1
  68. package/core/src/ssr/lib/compute/index.d.ts +1 -1
  69. package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
  70. package/core/src/ssr/lib/compute/routes.d.ts +1 -1
  71. package/core/src/ssr/lib/data.d.ts +1 -1
  72. package/core/src/ssr/lib/html.d.ts +1 -1
  73. package/core/src/ssr/lib/imports.d.ts +1 -1
  74. package/core/src/ssr/lib/index.d.ts +1 -1
  75. package/core/src/ssr/lib/layouts.d.ts +1 -1
  76. package/core/src/ssr/lib/metadata.d.ts +1 -1
  77. package/core/src/ssr/lib/mime.d.ts +1 -1
  78. package/core/src/ssr/lib/modules.d.ts +1 -1
  79. package/core/src/ssr/lib/path.d.ts +1 -1
  80. package/core/src/ssr/lib/preload.d.ts +1 -1
  81. package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
  82. package/core/src/ssr/lib/scripts/data.d.ts +1 -1
  83. package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
  84. package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
  85. package/core/src/ssr/lib/scripts/index.d.ts +1 -1
  86. package/core/src/ssr/lib/seed.d.ts +1 -1
  87. package/core/src/ssr/lib/serialize.d.ts +1 -1
  88. package/core/src/ssr/lib/setup.d.ts +1 -1
  89. package/core/src/ssr/lib/styles.d.ts +1 -1
  90. package/core/src/ssr/lib/template.d.ts +1 -1
  91. package/core/src/ssr/lib/types.d.ts +1 -1
  92. package/core/src/ssr/render.d.ts +1 -1
  93. package/core/src/ssr/stream.d.ts +1 -1
  94. package/elysia/index.d.ts +1 -1
  95. package/elysia/index.js +2 -2
  96. package/elysia/index.js.map +1 -1
  97. package/elysia/src/index.d.ts +1 -1
  98. package/elysia/src/libs/assets.d.ts +1 -1
  99. package/elysia/src/libs/cache.d.ts +1 -1
  100. package/elysia/src/libs/caching.d.ts +1 -1
  101. package/elysia/src/libs/http.d.ts +1 -1
  102. package/elysia/src/libs/image.d.ts +1 -1
  103. package/elysia/src/libs/index.d.ts +1 -1
  104. package/elysia/src/libs/llms.d.ts +1 -1
  105. package/elysia/src/libs/response.d.ts +1 -1
  106. package/elysia/src/libs/serving.d.ts +1 -1
  107. package/elysia/src/plugin.d.ts +1 -1
  108. package/elysia/src/routes/artifacts.d.ts +1 -1
  109. package/elysia/src/routes/content.d.ts +1 -1
  110. package/elysia/src/routes/image.d.ts +1 -1
  111. package/elysia/src/routes/index.d.ts +1 -1
  112. package/elysia/src/routes/internal.d.ts +1 -1
  113. package/elysia/src/routes/llms.d.ts +1 -1
  114. package/elysia/src/routes/og.d.ts +1 -1
  115. package/elysia/src/routes/redirects.d.ts +1 -1
  116. package/elysia/src/routes/robots.d.ts +1 -1
  117. package/elysia/src/routes/rss.d.ts +1 -1
  118. package/elysia/src/routes/search.d.ts +1 -1
  119. package/elysia/src/routes/sitemap.d.ts +1 -1
  120. package/elysia/src/routes/ssr.d.ts +1 -1
  121. package/elysia/src/routes/static.d.ts +1 -1
  122. package/elysia/src/types.d.ts +1 -1
  123. package/package.json +3 -2
  124. package/react/index.d.ts +1 -1
  125. package/react/index.js +2 -2
  126. package/react/index.js.map +1 -1
  127. package/react/src/components/ClientOnly.d.ts +1 -1
  128. package/react/src/components/ContentRoute.d.ts +1 -1
  129. package/react/src/components/Image.d.ts +1 -1
  130. package/react/src/components/LazyRoute.d.ts +1 -1
  131. package/react/src/components/Link.d.ts +1 -1
  132. package/react/src/components/Markdown.d.ts +1 -1
  133. package/react/src/components/Outlet.d.ts +1 -1
  134. package/react/src/components/index.d.ts +1 -1
  135. package/react/src/hooks/index.d.ts +1 -1
  136. package/react/src/hooks/useContent.d.ts +1 -1
  137. package/react/src/hooks/useData.d.ts +1 -1
  138. package/react/src/hooks/useFeed.d.ts +1 -1
  139. package/react/src/hooks/useLayoutData.d.ts +1 -1
  140. package/react/src/hooks/useLlms.d.ts +1 -1
  141. package/react/src/hooks/useNavigate.d.ts +1 -1
  142. package/react/src/hooks/useParams.d.ts +1 -1
  143. package/react/src/hooks/useRouter.d.ts +1 -1
  144. package/react/src/hooks/useSearch.d.ts +1 -1
  145. package/react/src/hooks/useSearchParams.d.ts +1 -1
  146. package/react/src/hooks/useToc.d.ts +1 -1
  147. package/react/src/index.d.ts +1 -1
  148. package/react/src/lib/collection.d.ts +1 -1
  149. package/react/src/lib/content.d.ts +1 -1
  150. package/react/src/lib/head.d.ts +1 -1
  151. package/react/src/lib/index.d.ts +1 -1
  152. package/react/src/lib/lazy-route.d.ts +1 -1
  153. package/react/src/lib/route-loader.d.ts +1 -1
  154. package/react/src/providers/ContentProvider.d.ts +1 -1
  155. package/react/src/providers/RerouteProvider.d.ts +1 -1
  156. package/react/src/providers/RouterProvider.d.ts +1 -1
  157. package/react/src/providers/index.d.ts +1 -1
  158. package/react/src/types/any.d.ts +1 -1
  159. package/react/src/types/index.d.ts +1 -1
  160. package/react/src/types/router.d.ts +1 -1
  161. package/telemetry/react.d.ts +1 -1
  162. package/telemetry/react.js +197 -241
  163. package/telemetry/react.js.map +6 -7
  164. package/telemetry/server.d.ts +1 -1
  165. package/telemetry/server.js +2 -2
  166. package/telemetry/server.js.map +1 -1
  167. package/telemetry/src/react/api.d.ts +1 -1
  168. package/telemetry/src/react/api.d.ts.map +1 -1
  169. package/telemetry/src/react/context.d.ts +1 -1
  170. package/telemetry/src/react/index.d.ts +1 -1
  171. package/telemetry/src/react/telemetry.d.ts +1 -1
  172. package/telemetry/src/react/telemetry.d.ts.map +1 -1
  173. package/telemetry/src/server/context.d.ts +1 -1
  174. package/telemetry/src/server/headers/extractor.d.ts +1 -1
  175. package/telemetry/src/server/headers/index.d.ts +1 -1
  176. package/telemetry/src/server/headers/presets.d.ts +1 -1
  177. package/telemetry/src/server/index.d.ts +1 -1
  178. package/telemetry/src/server/instrumentation.d.ts +1 -1
  179. package/telemetry/src/server/plugin.d.ts +1 -1
  180. package/telemetry/src/server/sourcemap.d.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.43.6
2
+ * reroute-js v0.43.8
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2026 stewones <hi@stewan.io>
@@ -41,149 +41,6 @@ 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/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 deserializeIgnoreRoutes(serialized) {
55
- if (!(serialized && Array.isArray(serialized)))
56
- return;
57
- return serialized.map((pattern) => {
58
- if (pattern?.type === "string") {
59
- return pattern.value;
60
- }
61
- if (pattern?.type === "regex") {
62
- return new RegExp(pattern.value, pattern.flags);
63
- }
64
- return pattern;
65
- });
66
- }
67
- function getBrowserTelemetryConfig() {
68
- if (typeof window !== "undefined") {
69
- const globalConfig = window.__REROUTE_TELEMETRY_BROWSER__;
70
- if (globalConfig) {
71
- if (globalConfig.ignoreRoutes) {
72
- globalConfig.ignoreRoutes = deserializeIgnoreRoutes(globalConfig.ignoreRoutes);
73
- }
74
- return globalConfig;
75
- }
76
- }
77
- return {};
78
- }
79
- function TelemetryProvider({
80
- children,
81
- enabled,
82
- serviceName,
83
- serviceVersion,
84
- otlpEndpoint,
85
- apiKey,
86
- environment,
87
- enableConsoleCapture
88
- }) {
89
- const [telemetryReady, setTelemetryReady] = useState(false);
90
- const [telemetryAPI, setTelemetryAPI] = useState(null);
91
- const hasInitialized = useRef(false);
92
- const globalConfig = useMemo(() => getBrowserTelemetryConfig(), []);
93
- const mergedConfig = useMemo(() => ({
94
- enabled: enabled ?? globalConfig.enabled ?? false,
95
- serviceName: serviceName ?? globalConfig.serviceName ?? "reroute-app-browser",
96
- serviceVersion: serviceVersion ?? globalConfig.serviceVersion ?? "1.0.0",
97
- otlpEndpoint: otlpEndpoint ?? globalConfig.otlpEndpoint ?? "/__reroute_telemetry",
98
- apiKey: apiKey ?? globalConfig.apiKey,
99
- environment: environment ?? globalConfig.environment ?? "development",
100
- enableConsoleCapture: enableConsoleCapture ?? globalConfig.enableConsoleCapture ?? true,
101
- ignoreRoutes: globalConfig.ignoreRoutes
102
- }), [
103
- enabled,
104
- serviceName,
105
- serviceVersion,
106
- otlpEndpoint,
107
- apiKey,
108
- environment,
109
- enableConsoleCapture,
110
- globalConfig
111
- ]);
112
- useEffect(() => {
113
- if (IS_SERVER) {
114
- return;
115
- }
116
- if (!mergedConfig.enabled) {
117
- console.debug("[TelemetryProvider] Browser telemetry disabled");
118
- return;
119
- }
120
- if (hasInitialized.current) {
121
- return;
122
- }
123
- hasInitialized.current = true;
124
- Promise.resolve().then(() => (init_react2(), exports_react)).then((module) => {
125
- module.initBrowserTelemetry(mergedConfig);
126
- setTelemetryAPI(module);
127
- setTelemetryReady(true);
128
- console.debug("[TelemetryProvider] Browser telemetry initialized");
129
- }).catch((error) => {
130
- console.warn("[TelemetryProvider] Failed to load telemetry:", error);
131
- hasInitialized.current = false;
132
- });
133
- }, [mergedConfig]);
134
- const contextValue = useMemo(() => ({
135
- createCustomSpan: (name, attributes) => {
136
- if (telemetryReady && telemetryAPI) {
137
- return telemetryAPI.createSpan(name, attributes);
138
- }
139
- return noopSpan;
140
- },
141
- trackCustomEvent: (eventName, attributes) => {
142
- if (telemetryReady && telemetryAPI) {
143
- telemetryAPI.trackEvent(eventName, attributes);
144
- }
145
- },
146
- trackCustomError: (error, context) => {
147
- if (telemetryReady && telemetryAPI) {
148
- telemetryAPI.trackError(error, context);
149
- }
150
- }
151
- }), [telemetryReady, telemetryAPI]);
152
- if (IS_SERVER) {
153
- return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
154
- value: noopContext,
155
- children
156
- });
157
- }
158
- return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
159
- value: contextValue,
160
- children
161
- });
162
- }
163
- function useTelemetry() {
164
- const context = useContext(TelemetryContext);
165
- if (!context) {
166
- throw new Error("useTelemetry must be used within a TelemetryProvider");
167
- }
168
- return context;
169
- }
170
- var IS_SERVER, noopSpan, noopContext, TelemetryContext;
171
- var init_api = __esm(() => {
172
- IS_SERVER = typeof window === "undefined";
173
- noopSpan = {
174
- setAttributes: () => {},
175
- setStatus: () => {},
176
- recordException: () => {},
177
- end: () => {}
178
- };
179
- noopContext = {
180
- createCustomSpan: () => noopSpan,
181
- trackCustomEvent: () => {},
182
- trackCustomError: () => {}
183
- };
184
- TelemetryContext = createContext(null);
185
- });
186
-
187
44
  // packages/telemetry/src/react/context.ts
188
45
  function setContext(attributes) {
189
46
  contextAttributes = { ...contextAttributes, ...attributes };
@@ -207,6 +64,14 @@ var init_context = __esm(() => {
207
64
  });
208
65
 
209
66
  // packages/telemetry/src/react/telemetry.ts
67
+ var exports_telemetry = {};
68
+ __export(exports_telemetry, {
69
+ trackEvent: () => trackEvent,
70
+ trackError: () => trackError,
71
+ shutdownTelemetry: () => shutdownTelemetry,
72
+ initBrowserTelemetry: () => initBrowserTelemetry,
73
+ createSpan: () => createSpan
74
+ });
210
75
  function addBreadcrumb(category, message, data) {
211
76
  breadcrumbs.push({
212
77
  timestamp: Date.now(),
@@ -268,7 +133,7 @@ function shouldIgnoreUrl(url, method = "GET") {
268
133
  });
269
134
  }
270
135
  async function initBrowserTelemetry(options = {}) {
271
- if (IS_SERVER2 || isInitialized) {
136
+ if (IS_SERVER || isInitialized) {
272
137
  return;
273
138
  }
274
139
  isInitialized = true;
@@ -278,14 +143,16 @@ async function initBrowserTelemetry(options = {}) {
278
143
  ignorePatterns.push(/cloudflareinsights\.com/);
279
144
  try {
280
145
  const [
281
- { getWebAutoInstrumentations },
146
+ { FetchInstrumentation },
147
+ { XMLHttpRequestInstrumentation },
282
148
  { OTLPTraceExporter },
283
149
  { registerInstrumentations },
284
150
  { BatchSpanProcessor, WebTracerProvider },
285
151
  { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION },
286
152
  otelApi
287
153
  ] = await Promise.all([
288
- import("@opentelemetry/auto-instrumentations-web"),
154
+ import("@opentelemetry/instrumentation-fetch"),
155
+ import("@opentelemetry/instrumentation-xml-http-request"),
289
156
  import("@opentelemetry/exporter-trace-otlp-http"),
290
157
  import("@opentelemetry/instrumentation"),
291
158
  import("@opentelemetry/sdk-trace-web"),
@@ -341,67 +208,40 @@ async function initBrowserTelemetry(options = {}) {
341
208
  });
342
209
  tracerProvider.register();
343
210
  await setupTraceContextFromServer();
211
+ const ignoreUrlPatterns = ignorePatterns.map((pattern) => {
212
+ if (typeof pattern === "string") {
213
+ return new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
214
+ }
215
+ if (pattern instanceof RegExp) {
216
+ return pattern;
217
+ }
218
+ return /.^/;
219
+ });
220
+ const applyCustomAttributesOnSpan = (span, request) => {
221
+ const url = request.url || "";
222
+ const method = request.method || "GET";
223
+ for (const pattern of ignorePatterns) {
224
+ if (typeof pattern === "function") {
225
+ if (shouldIgnoreUrl(url, method)) {
226
+ span.end();
227
+ return;
228
+ }
229
+ }
230
+ }
231
+ };
344
232
  registerInstrumentations({
345
233
  instrumentations: [
346
- getWebAutoInstrumentations({
347
- "@opentelemetry/instrumentation-document-load": {
348
- enabled: false
349
- },
350
- "@opentelemetry/instrumentation-user-interaction": {
351
- enabled: false
352
- },
353
- "@opentelemetry/instrumentation-fetch": {
354
- enabled: true,
355
- propagateTraceHeaderCorsUrls: [/.*/],
356
- clearTimingResources: true,
357
- ignoreUrls: ignorePatterns.map((pattern) => {
358
- if (typeof pattern === "string") {
359
- return new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
360
- }
361
- if (pattern instanceof RegExp) {
362
- return pattern;
363
- }
364
- return /.^/;
365
- }),
366
- applyCustomAttributesOnSpan: (span, request) => {
367
- const url = request.url || "";
368
- const method = request.method || "GET";
369
- for (const pattern of ignorePatterns) {
370
- if (typeof pattern === "function") {
371
- if (shouldIgnoreUrl(url, method)) {
372
- span.end();
373
- return;
374
- }
375
- }
376
- }
377
- }
378
- },
379
- "@opentelemetry/instrumentation-xml-http-request": {
380
- enabled: true,
381
- propagateTraceHeaderCorsUrls: [/.*/],
382
- clearTimingResources: true,
383
- ignoreUrls: ignorePatterns.map((pattern) => {
384
- if (typeof pattern === "string") {
385
- return new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
386
- }
387
- if (pattern instanceof RegExp) {
388
- return pattern;
389
- }
390
- return /.^/;
391
- }),
392
- applyCustomAttributesOnSpan: (span, request) => {
393
- const url = request.url || "";
394
- const method = request.method || "GET";
395
- for (const pattern of ignorePatterns) {
396
- if (typeof pattern === "function") {
397
- if (shouldIgnoreUrl(url, method)) {
398
- span.end();
399
- return;
400
- }
401
- }
402
- }
403
- }
404
- }
234
+ new FetchInstrumentation({
235
+ propagateTraceHeaderCorsUrls: [/.*/],
236
+ clearTimingResources: true,
237
+ ignoreUrls: ignoreUrlPatterns,
238
+ applyCustomAttributesOnSpan
239
+ }),
240
+ new XMLHttpRequestInstrumentation({
241
+ propagateTraceHeaderCorsUrls: [/.*/],
242
+ clearTimingResources: true,
243
+ ignoreUrls: ignoreUrlPatterns,
244
+ applyCustomAttributesOnSpan
405
245
  })
406
246
  ]
407
247
  });
@@ -424,7 +264,7 @@ async function initBrowserTelemetry(options = {}) {
424
264
  }
425
265
  }
426
266
  function setupBreadcrumbTracking() {
427
- if (IS_SERVER2)
267
+ if (IS_SERVER)
428
268
  return;
429
269
  document.addEventListener("click", (event) => {
430
270
  const target = event.target;
@@ -485,7 +325,7 @@ function setupBreadcrumbTracking() {
485
325
  console.log("[browser-telemetry] Breadcrumb tracking enabled");
486
326
  }
487
327
  function setupNetworkTracking() {
488
- if (IS_SERVER2)
328
+ if (IS_SERVER)
489
329
  return;
490
330
  const originalFetch = window.fetch;
491
331
  window.fetch = async function(input, init) {
@@ -566,7 +406,7 @@ function setupNetworkTracking() {
566
406
  console.log("[browser-telemetry] Network tracking enabled");
567
407
  }
568
408
  function getPerformanceMetrics() {
569
- if (IS_SERVER2)
409
+ if (IS_SERVER)
570
410
  return {};
571
411
  const metrics = {};
572
412
  const memory = performance.memory;
@@ -825,7 +665,7 @@ async function setupConsoleCapture() {
825
665
  console.error = wrappedError;
826
666
  }
827
667
  function createSpan(name, attributes = {}) {
828
- if (IS_SERVER2 || !isInitialized || !trace) {
668
+ if (IS_SERVER || !isInitialized || !trace) {
829
669
  return {
830
670
  setAttributes: () => {},
831
671
  setStatus: () => {},
@@ -868,7 +708,7 @@ function createSpan(name, attributes = {}) {
868
708
  }
869
709
  }
870
710
  function trackEvent(eventName, attributes = {}) {
871
- if (IS_SERVER2 || !isInitialized) {
711
+ if (IS_SERVER || !isInitialized) {
872
712
  return;
873
713
  }
874
714
  try {
@@ -879,7 +719,7 @@ function trackEvent(eventName, attributes = {}) {
879
719
  }
880
720
  }
881
721
  async function trackError(error, context = {}) {
882
- if (IS_SERVER2 || !isInitialized || !trace || !SpanStatusCode) {
722
+ if (IS_SERVER || !isInitialized || !trace || !SpanStatusCode) {
883
723
  return;
884
724
  }
885
725
  try {
@@ -959,42 +799,158 @@ async function shutdownTelemetry() {
959
799
  console.log("[browser-telemetry] Shut down successfully");
960
800
  }
961
801
  }
962
- var IS_SERVER2, trace = null, SpanStatusCode = null, isInitialized = false, tracerProvider = null, serverTraceContext = null, ignorePatterns, breadcrumbs, MAX_BREADCRUMBS = 20, networkRequests, MAX_NETWORK_REQUESTS = 15;
802
+ var IS_SERVER, trace = null, SpanStatusCode = null, isInitialized = false, tracerProvider = null, serverTraceContext = null, ignorePatterns, breadcrumbs, MAX_BREADCRUMBS = 20, networkRequests, MAX_NETWORK_REQUESTS = 15;
963
803
  var init_telemetry = __esm(() => {
964
804
  init_context();
965
- IS_SERVER2 = typeof window === "undefined";
805
+ IS_SERVER = typeof window === "undefined";
966
806
  ignorePatterns = [];
967
807
  breadcrumbs = [];
968
808
  networkRequests = [];
969
809
  });
970
810
 
971
- // packages/telemetry/src/react/index.ts
972
- var init_react = __esm(() => {
973
- init_api();
974
- init_context();
975
- init_telemetry();
976
- });
977
-
978
- // packages/telemetry/react.ts
979
- var exports_react = {};
980
- __export(exports_react, {
981
- useTelemetry: () => useTelemetry,
982
- trackEvent: () => trackEvent,
983
- trackError: () => trackError,
984
- shutdownTelemetry: () => shutdownTelemetry,
985
- setContext: () => setContext,
986
- initBrowserTelemetry: () => initBrowserTelemetry,
987
- getContextAttributesForTelemetry: () => getContextAttributesForTelemetry,
988
- getContextAttr: () => getContextAttr,
989
- createSpan: () => createSpan,
990
- clearContext: () => clearContext,
991
- TelemetryProvider: () => TelemetryProvider
992
- });
993
- var init_react2 = __esm(() => {
994
- init_react();
995
- });
996
- init_react2();
811
+ // packages/telemetry/src/react/api.tsx
812
+ import {
813
+ createContext,
814
+ useContext,
815
+ useEffect,
816
+ useMemo,
817
+ useRef,
818
+ useState
819
+ } from "react";
820
+ import { jsx } from "react/jsx-runtime";
821
+ function deserializeIgnoreRoutes(serialized) {
822
+ if (!(serialized && Array.isArray(serialized)))
823
+ return;
824
+ return serialized.map((pattern) => {
825
+ if (pattern?.type === "string") {
826
+ return pattern.value;
827
+ }
828
+ if (pattern?.type === "regex") {
829
+ return new RegExp(pattern.value, pattern.flags);
830
+ }
831
+ return pattern;
832
+ });
833
+ }
834
+ function getBrowserTelemetryConfig() {
835
+ if (typeof window !== "undefined") {
836
+ const globalConfig = window.__REROUTE_TELEMETRY_BROWSER__;
837
+ if (globalConfig) {
838
+ if (globalConfig.ignoreRoutes) {
839
+ globalConfig.ignoreRoutes = deserializeIgnoreRoutes(globalConfig.ignoreRoutes);
840
+ }
841
+ return globalConfig;
842
+ }
843
+ }
844
+ return {};
845
+ }
846
+ var IS_SERVER2 = typeof window === "undefined";
847
+ var noopSpan = {
848
+ setAttributes: () => {},
849
+ setStatus: () => {},
850
+ recordException: () => {},
851
+ end: () => {}
852
+ };
853
+ var noopContext = {
854
+ createCustomSpan: () => noopSpan,
855
+ trackCustomEvent: () => {},
856
+ trackCustomError: () => {}
857
+ };
858
+ var TelemetryContext = createContext(null);
859
+ function TelemetryProvider({
860
+ children,
861
+ enabled,
862
+ serviceName,
863
+ serviceVersion,
864
+ otlpEndpoint,
865
+ apiKey,
866
+ environment,
867
+ enableConsoleCapture
868
+ }) {
869
+ const [telemetryReady, setTelemetryReady] = useState(false);
870
+ const [telemetryAPI, setTelemetryAPI] = useState(null);
871
+ const hasInitialized = useRef(false);
872
+ const globalConfig = useMemo(() => getBrowserTelemetryConfig(), []);
873
+ const mergedConfig = useMemo(() => ({
874
+ enabled: enabled ?? globalConfig.enabled ?? false,
875
+ serviceName: serviceName ?? globalConfig.serviceName ?? "reroute-app-browser",
876
+ serviceVersion: serviceVersion ?? globalConfig.serviceVersion ?? "1.0.0",
877
+ otlpEndpoint: otlpEndpoint ?? globalConfig.otlpEndpoint ?? "/__reroute_telemetry",
878
+ apiKey: apiKey ?? globalConfig.apiKey,
879
+ environment: environment ?? globalConfig.environment ?? "development",
880
+ enableConsoleCapture: enableConsoleCapture ?? globalConfig.enableConsoleCapture ?? true,
881
+ ignoreRoutes: globalConfig.ignoreRoutes
882
+ }), [
883
+ enabled,
884
+ serviceName,
885
+ serviceVersion,
886
+ otlpEndpoint,
887
+ apiKey,
888
+ environment,
889
+ enableConsoleCapture,
890
+ globalConfig
891
+ ]);
892
+ useEffect(() => {
893
+ if (IS_SERVER2) {
894
+ return;
895
+ }
896
+ if (!mergedConfig.enabled) {
897
+ console.debug("[TelemetryProvider] Browser telemetry disabled");
898
+ return;
899
+ }
900
+ if (hasInitialized.current) {
901
+ return;
902
+ }
903
+ hasInitialized.current = true;
904
+ Promise.resolve().then(() => (init_telemetry(), exports_telemetry)).then((module) => {
905
+ module.initBrowserTelemetry(mergedConfig);
906
+ setTelemetryAPI(module);
907
+ setTelemetryReady(true);
908
+ console.debug("[TelemetryProvider] Browser telemetry initialized");
909
+ }).catch((error) => {
910
+ console.warn("[TelemetryProvider] Failed to load telemetry:", error);
911
+ hasInitialized.current = false;
912
+ });
913
+ }, [mergedConfig]);
914
+ const contextValue = useMemo(() => ({
915
+ createCustomSpan: (name, attributes) => {
916
+ if (telemetryReady && telemetryAPI) {
917
+ return telemetryAPI.createSpan(name, attributes);
918
+ }
919
+ return noopSpan;
920
+ },
921
+ trackCustomEvent: (eventName, attributes) => {
922
+ if (telemetryReady && telemetryAPI) {
923
+ telemetryAPI.trackEvent(eventName, attributes);
924
+ }
925
+ },
926
+ trackCustomError: (error, context) => {
927
+ if (telemetryReady && telemetryAPI) {
928
+ telemetryAPI.trackError(error, context);
929
+ }
930
+ }
931
+ }), [telemetryReady, telemetryAPI]);
932
+ if (IS_SERVER2) {
933
+ return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
934
+ value: noopContext,
935
+ children
936
+ });
937
+ }
938
+ return /* @__PURE__ */ jsx(TelemetryContext.Provider, {
939
+ value: contextValue,
940
+ children
941
+ });
942
+ }
943
+ function useTelemetry() {
944
+ const context = useContext(TelemetryContext);
945
+ if (!context) {
946
+ throw new Error("useTelemetry must be used within a TelemetryProvider");
947
+ }
948
+ return context;
949
+ }
997
950
 
951
+ // packages/telemetry/src/react/index.ts
952
+ init_context();
953
+ init_telemetry();
998
954
  export {
999
955
  useTelemetry,
1000
956
  trackEvent,
@@ -1009,4 +965,4 @@ export {
1009
965
  TelemetryProvider
1010
966
  };
1011
967
 
1012
- //# debugId=6E3B7E94F48A999D64756E2164756E21
968
+ //# debugId=0ECADDBD520FE42764756E2164756E21