reroute-js 0.26.0 → 0.27.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.
Files changed (193) hide show
  1. package/README.md +12 -8
  2. package/cli/bin.d.ts +1 -1
  3. package/cli/bin.js +136 -40
  4. package/cli/bin.js.map +16 -13
  5. package/cli/index.d.ts +1 -1
  6. package/cli/index.js +4 -4
  7. package/cli/index.js.map +1 -1
  8. package/cli/src/cli.d.ts +1 -1
  9. package/cli/src/commands/analyze.d.ts +1 -1
  10. package/cli/src/commands/build.d.ts +1 -1
  11. package/cli/src/commands/build.d.ts.map +1 -1
  12. package/cli/src/commands/dev.d.ts +1 -1
  13. package/cli/src/commands/gen.d.ts +1 -1
  14. package/cli/src/commands/gen.d.ts.map +1 -1
  15. package/cli/src/commands/index.d.ts +1 -1
  16. package/cli/src/commands/init.d.ts +1 -1
  17. package/cli/src/commands/lib/assets.d.ts +1 -1
  18. package/cli/src/commands/lib/bundler.d.ts +1 -1
  19. package/cli/src/commands/lib/command.d.ts +1 -1
  20. package/cli/src/commands/lib/env.d.ts +1 -1
  21. package/cli/src/commands/lib/index.d.ts +1 -1
  22. package/cli/src/commands/lib/log.d.ts +1 -1
  23. package/cli/src/commands/lib/markdown/availability.d.ts +1 -1
  24. package/cli/src/commands/lib/markdown/index.d.ts +1 -1
  25. package/cli/src/commands/lib/markdown/processor.d.ts +1 -1
  26. package/cli/src/commands/lib/production.d.ts +1 -1
  27. package/cli/src/commands/lib/server.d.ts +1 -1
  28. package/cli/src/commands/lib/streaming/analyzer.d.ts +1 -1
  29. package/cli/src/commands/lib/streaming/suspense.d.ts +1 -1
  30. package/cli/src/commands/lib/tailwind.d.ts +1 -1
  31. package/cli/src/commands/lib/terminal-ui.d.ts +1 -1
  32. package/cli/src/commands/lib/version.d.ts +1 -1
  33. package/cli/src/commands/og.d.ts +1 -1
  34. package/cli/src/commands/start.d.ts +1 -1
  35. package/cli/src/index.d.ts +1 -1
  36. package/core/index.d.ts +1 -1
  37. package/core/index.js +96 -9
  38. package/core/index.js.map +14 -11
  39. package/core/src/bundler/hash.d.ts +1 -1
  40. package/core/src/bundler/index.d.ts +1 -1
  41. package/core/src/config.d.ts +41 -13
  42. package/core/src/config.d.ts.map +1 -1
  43. package/core/src/content/discovery.d.ts +1 -1
  44. package/core/src/content/index.d.ts +1 -1
  45. package/core/src/content/metadata.d.ts +1 -1
  46. package/core/src/index.d.ts +1 -1
  47. package/core/src/llms/extractor.d.ts +1 -1
  48. package/core/src/llms/formatter.d.ts +1 -1
  49. package/core/src/llms/full-generator.d.ts +1 -1
  50. package/core/src/llms/index-generator.d.ts +1 -1
  51. package/core/src/llms/index.d.ts +1 -1
  52. package/core/src/og/discovery.d.ts +1 -1
  53. package/core/src/og/index.d.ts +1 -1
  54. package/core/src/og/meta.d.ts +1 -1
  55. package/core/src/og/render.d.ts +1 -1
  56. package/core/src/og/types.d.ts +1 -1
  57. package/core/src/robots/discovery.d.ts +1 -1
  58. package/core/src/robots/generator.d.ts +1 -1
  59. package/core/src/robots/index.d.ts +1 -1
  60. package/core/src/robots/policies.d.ts +1 -1
  61. package/core/src/rss/discovery.d.ts +1 -1
  62. package/core/src/rss/generator.d.ts +1 -1
  63. package/core/src/rss/index.d.ts +1 -1
  64. package/core/src/sitemap/discovery.d.ts +1 -1
  65. package/core/src/sitemap/generator.d.ts +1 -1
  66. package/core/src/sitemap/index.d.ts +1 -1
  67. package/core/src/ssr/index.d.ts +1 -1
  68. package/core/src/ssr/lib/cache.d.ts +1 -1
  69. package/core/src/ssr/lib/collections.d.ts +1 -1
  70. package/core/src/ssr/lib/compression.d.ts +1 -1
  71. package/core/src/ssr/lib/compute/content.d.ts +1 -1
  72. package/core/src/ssr/lib/compute/index.d.ts +1 -1
  73. package/core/src/ssr/lib/compute/layouts.d.ts +1 -1
  74. package/core/src/ssr/lib/compute/routes.d.ts +1 -1
  75. package/core/src/ssr/lib/data.d.ts +1 -1
  76. package/core/src/ssr/lib/html.d.ts +1 -1
  77. package/core/src/ssr/lib/imports.d.ts +1 -1
  78. package/core/src/ssr/lib/index.d.ts +1 -1
  79. package/core/src/ssr/lib/layouts.d.ts +1 -1
  80. package/core/src/ssr/lib/metadata.d.ts +1 -1
  81. package/core/src/ssr/lib/mime.d.ts +1 -1
  82. package/core/src/ssr/lib/modules.d.ts +1 -1
  83. package/core/src/ssr/lib/path.d.ts +1 -1
  84. package/core/src/ssr/lib/preload.d.ts +1 -1
  85. package/core/src/ssr/lib/scripts/collections.d.ts +1 -1
  86. package/core/src/ssr/lib/scripts/data.d.ts +5 -2
  87. package/core/src/ssr/lib/scripts/data.d.ts.map +1 -1
  88. package/core/src/ssr/lib/scripts/escape.d.ts +1 -1
  89. package/core/src/ssr/lib/scripts/feeds.d.ts +1 -1
  90. package/core/src/ssr/lib/scripts/index.d.ts +1 -1
  91. package/core/src/ssr/lib/seed.d.ts +1 -1
  92. package/core/src/ssr/lib/serialize.d.ts +17 -0
  93. package/core/src/ssr/lib/serialize.d.ts.map +1 -0
  94. package/core/src/ssr/lib/setup.d.ts +5 -2
  95. package/core/src/ssr/lib/setup.d.ts.map +1 -1
  96. package/core/src/ssr/lib/styles.d.ts +1 -1
  97. package/core/src/ssr/lib/template.d.ts +1 -1
  98. package/core/src/ssr/lib/types.d.ts +1 -1
  99. package/core/src/ssr/render.d.ts +1 -1
  100. package/core/src/ssr/render.d.ts.map +1 -1
  101. package/core/src/ssr/stream.d.ts +1 -1
  102. package/core/src/ssr/stream.d.ts.map +1 -1
  103. package/elysia/index.d.ts +1 -1
  104. package/elysia/index.js +96 -9
  105. package/elysia/index.js.map +14 -11
  106. package/elysia/src/index.d.ts +1 -1
  107. package/elysia/src/libs/assets.d.ts +1 -1
  108. package/elysia/src/libs/cache.d.ts +1 -1
  109. package/elysia/src/libs/caching.d.ts +1 -1
  110. package/elysia/src/libs/http.d.ts +1 -1
  111. package/elysia/src/libs/image.d.ts +1 -1
  112. package/elysia/src/libs/index.d.ts +1 -1
  113. package/elysia/src/libs/llms.d.ts +1 -1
  114. package/elysia/src/libs/response.d.ts +1 -1
  115. package/elysia/src/libs/serving.d.ts +1 -1
  116. package/elysia/src/plugin.d.ts +1 -1
  117. package/elysia/src/routes/artifacts.d.ts +1 -1
  118. package/elysia/src/routes/content.d.ts +1 -1
  119. package/elysia/src/routes/image.d.ts +1 -1
  120. package/elysia/src/routes/index.d.ts +1 -1
  121. package/elysia/src/routes/internal.d.ts +1 -1
  122. package/elysia/src/routes/llms.d.ts +1 -1
  123. package/elysia/src/routes/og.d.ts +1 -1
  124. package/elysia/src/routes/redirects.d.ts +1 -1
  125. package/elysia/src/routes/robots.d.ts +1 -1
  126. package/elysia/src/routes/rss.d.ts +1 -1
  127. package/elysia/src/routes/search.d.ts +1 -1
  128. package/elysia/src/routes/sitemap.d.ts +1 -1
  129. package/elysia/src/routes/ssr.d.ts +1 -1
  130. package/elysia/src/routes/static.d.ts +1 -1
  131. package/elysia/src/types.d.ts +1 -1
  132. package/package.json +9 -13
  133. package/react/index.d.ts +1 -1
  134. package/react/index.js +2 -2
  135. package/react/index.js.map +1 -1
  136. package/react/src/components/ClientOnly.d.ts +1 -1
  137. package/react/src/components/ContentRoute.d.ts +1 -1
  138. package/react/src/components/Image.d.ts +1 -1
  139. package/react/src/components/LazyRoute.d.ts +1 -1
  140. package/react/src/components/Link.d.ts +1 -1
  141. package/react/src/components/Markdown.d.ts +1 -1
  142. package/react/src/components/Outlet.d.ts +1 -1
  143. package/react/src/components/index.d.ts +1 -1
  144. package/react/src/hooks/index.d.ts +1 -1
  145. package/react/src/hooks/useContent.d.ts +1 -1
  146. package/react/src/hooks/useData.d.ts +1 -1
  147. package/react/src/hooks/useFeed.d.ts +1 -1
  148. package/react/src/hooks/useLayoutData.d.ts +1 -1
  149. package/react/src/hooks/useLlms.d.ts +1 -1
  150. package/react/src/hooks/useNavigate.d.ts +1 -1
  151. package/react/src/hooks/useParams.d.ts +1 -1
  152. package/react/src/hooks/useRouter.d.ts +1 -1
  153. package/react/src/hooks/useSearch.d.ts +1 -1
  154. package/react/src/hooks/useSearchParams.d.ts +1 -1
  155. package/react/src/hooks/useToc.d.ts +1 -1
  156. package/react/src/index.d.ts +1 -1
  157. package/react/src/lib/collection.d.ts +1 -1
  158. package/react/src/lib/content.d.ts +1 -1
  159. package/react/src/lib/head.d.ts +1 -1
  160. package/react/src/lib/index.d.ts +1 -1
  161. package/react/src/lib/lazy-route.d.ts +1 -1
  162. package/react/src/lib/route-loader.d.ts +1 -1
  163. package/react/src/providers/ContentProvider.d.ts +1 -1
  164. package/react/src/providers/RerouteProvider.d.ts +1 -1
  165. package/react/src/providers/RouterProvider.d.ts +1 -1
  166. package/react/src/providers/index.d.ts +1 -1
  167. package/react/src/types/any.d.ts +1 -1
  168. package/react/src/types/index.d.ts +1 -1
  169. package/react/src/types/router.d.ts +1 -1
  170. package/telemetry/react.d.ts +1 -1
  171. package/telemetry/react.js +539 -30
  172. package/telemetry/react.js.map +7 -6
  173. package/telemetry/server.d.ts +1 -1
  174. package/telemetry/server.js +304 -20
  175. package/telemetry/server.js.map +12 -10
  176. package/telemetry/src/react/api.d.ts +3 -2
  177. package/telemetry/src/react/api.d.ts.map +1 -1
  178. package/telemetry/src/react/context.d.ts +62 -0
  179. package/telemetry/src/react/context.d.ts.map +1 -0
  180. package/telemetry/src/react/index.d.ts +2 -1
  181. package/telemetry/src/react/index.d.ts.map +1 -1
  182. package/telemetry/src/react/telemetry.d.ts +4 -53
  183. package/telemetry/src/react/telemetry.d.ts.map +1 -1
  184. package/telemetry/src/server/context.d.ts +61 -0
  185. package/telemetry/src/server/context.d.ts.map +1 -0
  186. package/telemetry/src/server/index.d.ts +3 -1
  187. package/telemetry/src/server/index.d.ts.map +1 -1
  188. package/telemetry/src/server/instrumentation.d.ts +27 -2
  189. package/telemetry/src/server/instrumentation.d.ts.map +1 -1
  190. package/telemetry/src/server/plugin.d.ts +1 -1
  191. package/telemetry/src/server/plugin.d.ts.map +1 -1
  192. package/telemetry/src/server/sourcemap.d.ts +55 -0
  193. package/telemetry/src/server/sourcemap.d.ts.map +1 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * reroute-js v0.26.0
2
+ * reroute-js v0.27.0
3
3
  *
4
4
  * @license MIT
5
5
  * @copyright 2025 stewones <hi@stewan.io>
@@ -8,9 +8,49 @@
8
8
  * Built with Bun <3
9
9
  */
10
10
  import { createRequire } from "node:module";
11
+ var __defProp = Object.defineProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, {
15
+ get: all[name],
16
+ enumerable: true,
17
+ configurable: true,
18
+ set: (newValue) => all[name] = () => newValue
19
+ });
20
+ };
11
21
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
12
22
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
13
23
 
24
+ // packages/telemetry/src/server/context.ts
25
+ import { AsyncLocalStorage } from "node:async_hooks";
26
+ function setContext(attributes) {
27
+ const current = contextStorage.getStore() || {};
28
+ const updated = { ...current, ...attributes };
29
+ try {
30
+ if (contextStorage.getStore()) {}
31
+ } catch {}
32
+ globalContextAttributes = updated;
33
+ }
34
+ function clearContext() {
35
+ globalContextAttributes = {};
36
+ }
37
+ function getContextAttr() {
38
+ return contextStorage.getStore() || globalContextAttributes || {};
39
+ }
40
+ function getContextAttributesForTelemetry() {
41
+ const attrs = getContextAttr();
42
+ const prefixed = {};
43
+ for (const [key, value] of Object.entries(attrs)) {
44
+ prefixed[`context.${key}`] = value;
45
+ }
46
+ return prefixed;
47
+ }
48
+ var contextStorage, globalContextAttributes;
49
+ var init_context = __esm(() => {
50
+ contextStorage = new AsyncLocalStorage;
51
+ globalContextAttributes = {};
52
+ });
53
+
14
54
  // packages/telemetry/src/server/instrumentation.ts
15
55
  import { context, SpanStatusCode, trace } from "@opentelemetry/api";
16
56
  function isOtelAvailable() {
@@ -133,6 +173,45 @@ function withParentSpanSync(parentSpan, fn) {
133
173
  const ctx = trace.setSpan(context.active(), parentSpan);
134
174
  return context.with(ctx, fn);
135
175
  }
176
+ function extractTraceContext(headers) {
177
+ if (!isOtelAvailable())
178
+ return;
179
+ try {
180
+ const { propagation } = __require("@opentelemetry/api");
181
+ const carrier = {};
182
+ if (headers instanceof Headers) {
183
+ carrier.traceparent = headers.get("traceparent") || undefined;
184
+ carrier.tracestate = headers.get("tracestate") || undefined;
185
+ } else {
186
+ carrier.traceparent = headers.traceparent;
187
+ carrier.tracestate = headers.tracestate;
188
+ }
189
+ if (!carrier.traceparent) {
190
+ return;
191
+ }
192
+ return propagation.extract(context.active(), carrier);
193
+ } catch (error) {
194
+ console.error("[telemetry] Failed to extract trace context:", error);
195
+ return;
196
+ }
197
+ }
198
+ function getTraceContextForInjection(span) {
199
+ if (!(isOtelAvailable() && span))
200
+ return;
201
+ try {
202
+ const { propagation } = __require("@opentelemetry/api");
203
+ const carrier = {};
204
+ const ctx = trace.setSpan(context.active(), span);
205
+ propagation.inject(ctx, carrier);
206
+ return {
207
+ traceparent: carrier.traceparent,
208
+ tracestate: carrier.tracestate
209
+ };
210
+ } catch (error) {
211
+ console.error("[telemetry] Failed to get trace context for injection:", error);
212
+ return;
213
+ }
214
+ }
136
215
  var otelAvailable, noopSpan;
137
216
  var init_instrumentation = __esm(() => {
138
217
  noopSpan = new NoopSpan;
@@ -514,9 +593,154 @@ var init_core = __esm(() => {
514
593
  init_src();
515
594
  });
516
595
 
596
+ // packages/telemetry/src/server/sourcemap.ts
597
+ var exports_sourcemap = {};
598
+ __export(exports_sourcemap, {
599
+ resolveStackTrace: () => resolveStackTrace,
600
+ formatStackFrames: () => formatStackFrames,
601
+ enhanceError: () => enhanceError,
602
+ clearSourceMapCache: () => clearSourceMapCache
603
+ });
604
+ import { promises as fs } from "node:fs";
605
+ import { join as join2 } from "node:path";
606
+ import { SourceMapConsumer } from "source-map";
607
+ function parseStackFrame(line) {
608
+ const patterns = [
609
+ /^\s*at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/,
610
+ /^\s*at\s+(.+?):(\d+):(\d+)/,
611
+ /^(.+?)@(.+?):(\d+):(\d+)/
612
+ ];
613
+ for (const pattern of patterns) {
614
+ const match = line.match(pattern);
615
+ if (match) {
616
+ if (match.length === 5 && match[2]) {
617
+ return {
618
+ raw: line,
619
+ functionName: match[1].trim(),
620
+ fileName: match[2],
621
+ lineNumber: Number.parseInt(match[3], 10),
622
+ columnNumber: Number.parseInt(match[4], 10)
623
+ };
624
+ }
625
+ if (match.length === 4 && match[1]) {
626
+ const hasAt = line.includes("@");
627
+ return {
628
+ raw: line,
629
+ functionName: hasAt ? match[1] : undefined,
630
+ fileName: hasAt ? match[2] : match[1],
631
+ lineNumber: Number.parseInt(hasAt ? match[3] : match[2], 10),
632
+ columnNumber: Number.parseInt(hasAt ? match[4] : match[3], 10)
633
+ };
634
+ }
635
+ }
636
+ }
637
+ return { raw: line };
638
+ }
639
+ async function loadSourceMap(fileName, rerouteDir) {
640
+ if (sourcemapCache.has(fileName)) {
641
+ return sourcemapCache.get(fileName) || null;
642
+ }
643
+ try {
644
+ const possiblePaths = [];
645
+ if (rerouteDir) {
646
+ const baseName = fileName.split("/").pop() || fileName;
647
+ possiblePaths.push(join2(rerouteDir, "bundles", `${baseName}.map`));
648
+ }
649
+ possiblePaths.push(`${fileName}.map`);
650
+ for (const mapPath of possiblePaths) {
651
+ try {
652
+ const mapContent = await fs.readFile(mapPath, "utf-8");
653
+ const consumer = await new SourceMapConsumer(mapContent);
654
+ sourcemapCache.set(fileName, consumer);
655
+ return consumer;
656
+ } catch {}
657
+ }
658
+ return null;
659
+ } catch (error) {
660
+ console.error(`[sourcemap] Failed to load sourcemap for ${fileName}:`, error);
661
+ return null;
662
+ }
663
+ }
664
+ function mapPosition(consumer, line, column) {
665
+ const pos = consumer.originalPositionFor({ line, column });
666
+ return {
667
+ source: pos.source,
668
+ line: pos.line,
669
+ column: pos.column,
670
+ name: pos.name
671
+ };
672
+ }
673
+ async function resolveStackTrace(stack, options = {}) {
674
+ const lines = stack.split(`
675
+ `);
676
+ const frames = [];
677
+ for (const line of lines) {
678
+ const frame = parseStackFrame(line);
679
+ if (frame?.fileName && frame.lineNumber && frame.columnNumber) {
680
+ try {
681
+ const consumer = await loadSourceMap(frame.fileName, options.rerouteDir);
682
+ if (consumer) {
683
+ frame.mapped = mapPosition(consumer, frame.lineNumber, frame.columnNumber);
684
+ }
685
+ } catch (_error) {}
686
+ }
687
+ frames.push(frame);
688
+ }
689
+ const mappedLines = frames.map((frame) => {
690
+ if (frame.mapped?.source && frame.mapped.line !== null) {
691
+ const location = `${frame.mapped.source}:${frame.mapped.line}:${frame.mapped.column ?? 0}`;
692
+ if (frame.mapped.name || frame.functionName) {
693
+ return ` at ${frame.mapped.name || frame.functionName} (${location})`;
694
+ }
695
+ return ` at ${location}`;
696
+ }
697
+ return frame.raw;
698
+ });
699
+ return {
700
+ original: stack,
701
+ frames,
702
+ mapped: mappedLines.join(`
703
+ `)
704
+ };
705
+ }
706
+ async function enhanceError(error, options = {}) {
707
+ if (!error.stack)
708
+ return error;
709
+ try {
710
+ const result = await resolveStackTrace(error.stack, options);
711
+ error.sourceMappedStack = result.mapped;
712
+ error.stackFrames = result.frames;
713
+ } catch {}
714
+ return error;
715
+ }
716
+ function clearSourceMapCache() {
717
+ for (const consumer of sourcemapCache.values()) {
718
+ consumer.destroy();
719
+ }
720
+ sourcemapCache.clear();
721
+ }
722
+ function formatStackFrames(frames) {
723
+ return frames.map((frame) => {
724
+ if (frame.mapped?.source && frame.mapped.line !== null) {
725
+ const location = `${frame.mapped.source}:${frame.mapped.line}:${frame.mapped.column ?? 0}`;
726
+ if (frame.mapped.name || frame.functionName) {
727
+ return ` at ${frame.mapped.name || frame.functionName} (${location})`;
728
+ }
729
+ return ` at ${location}`;
730
+ }
731
+ return frame.raw;
732
+ }).join(`
733
+ `);
734
+ }
735
+ var sourcemapCache;
736
+ var init_sourcemap = __esm(() => {
737
+ sourcemapCache = new Map;
738
+ });
739
+
517
740
  // packages/telemetry/src/server/plugin.ts
518
741
  import os from "node:os";
519
742
  import {
743
+ context as context2,
520
744
  metrics,
521
745
  SpanStatusCode as SpanStatusCode2,
522
746
  trace as trace2
@@ -600,10 +824,10 @@ function telemetry(options = {}) {
600
824
  const OTLP_ENDPOINT = merged.otlpEndpoint || process.env.OTEL_EXPORTER_OTLP_ENDPOINT || "http://localhost:4318";
601
825
  const METRICS_INTERVAL = merged.metricsInterval ?? 5000;
602
826
  const proxyConfig = merged.proxy;
603
- const ENABLE_PROXY = typeof proxyConfig === "boolean" ? proxyConfig : proxyConfig?.enabled ?? !!proxyConfig;
604
- const PROXY_PATHNAME = typeof proxyConfig === "object" ? proxyConfig.pathname ?? "/api/telemetry" : "/api/telemetry";
605
- const PROXY_VERBOSE = typeof proxyConfig === "object" ? proxyConfig.verbose ?? false : false;
606
- const PROXY_HANDLER = typeof proxyConfig === "object" ? proxyConfig.handler : undefined;
827
+ const ENABLE_PROXY = proxyConfig?.enabled ?? !!proxyConfig;
828
+ const PROXY_PATHNAME = proxyConfig?.pathname ?? "/__reroute/telemetry";
829
+ const PROXY_VERBOSE = proxyConfig?.verbose ?? false;
830
+ const PROXY_HANDLER = proxyConfig?.handler;
607
831
  const ENABLE_TRACES = merged.enableTraces ?? true;
608
832
  const ENABLE_METRICS = merged.enableMetrics ?? true;
609
833
  const ENABLE_LOGS = merged.enableLogs ?? true;
@@ -817,19 +1041,27 @@ function telemetry(options = {}) {
817
1041
  store.shouldIgnoreTelemetry = true;
818
1042
  }
819
1043
  }
1044
+ const incomingContext = extractTraceContext(request.headers);
820
1045
  if (tracer && !store.shouldIgnoreTelemetry) {
821
1046
  try {
822
- const span = tracer.startSpan(`${method} ${route}`, {
823
- attributes: {
824
- "http.request.method": method,
825
- "http.route": route,
826
- "url.full": request.url,
827
- "url.scheme": url.protocol.replace(":", ""),
828
- "server.address": url.host,
829
- "service.name": SERVICE_NAME,
830
- ...CUSTOM_ATTRIBUTES
831
- }
832
- });
1047
+ const createSpan = () => {
1048
+ return tracer.startSpan(`${method} ${route}`, {
1049
+ attributes: {
1050
+ "http.request.method": method,
1051
+ "http.route": route,
1052
+ "url.full": request.url,
1053
+ "url.scheme": url.protocol.replace(":", ""),
1054
+ "server.address": url.host,
1055
+ "service.name": SERVICE_NAME,
1056
+ ...CUSTOM_ATTRIBUTES
1057
+ }
1058
+ });
1059
+ };
1060
+ const span = incomingContext ? context2.with(incomingContext, createSpan) : createSpan();
1061
+ const sessionAttrs = getContextAttributesForTelemetry();
1062
+ if (Object.keys(sessionAttrs).length > 0) {
1063
+ span.setAttributes(sessionAttrs);
1064
+ }
833
1065
  store.telemetrySpan = span;
834
1066
  } catch (error) {
835
1067
  console.error("[telemetry] Failed to create span:", error);
@@ -883,7 +1115,7 @@ function telemetry(options = {}) {
883
1115
  } catch (error) {
884
1116
  console.error("[telemetry] Failed to increment request counter:", error);
885
1117
  }
886
- }).onError(({ error, request, set, store }) => {
1118
+ }).onError(async ({ error, request, set, store }) => {
887
1119
  const errorDetails = getErrorDetails(error);
888
1120
  const duration = Date.now() - (store.startTime || Date.now());
889
1121
  const url = new URL(request.url);
@@ -897,24 +1129,38 @@ function telemetry(options = {}) {
897
1129
  const span = store.telemetrySpan;
898
1130
  if (span) {
899
1131
  const errorObj = error instanceof Error ? error : new Error(errorDetails.message);
1132
+ const rerouteDir = ".reroute";
1133
+ if (rerouteDir && errorObj.stack) {
1134
+ try {
1135
+ await enhanceError(errorObj, { rerouteDir });
1136
+ } catch (smError) {
1137
+ console.error("[telemetry] Sourcemap enhancement failed:", smError);
1138
+ }
1139
+ }
900
1140
  span.recordException(errorObj);
901
1141
  span.setStatus({
902
1142
  code: SpanStatusCode2.ERROR,
903
1143
  message: `${errorDetails.name}: ${errorDetails.message}`
904
1144
  });
1145
+ const enhancedError = errorObj;
1146
+ const stackToUse = enhancedError.sourceMappedStack || errorDetails.stack;
905
1147
  span.setAttributes({
906
1148
  error: true,
907
1149
  "error.type": errorDetails.name,
908
1150
  "error.message": errorDetails.message,
909
1151
  "error.stack": errorDetails.stack,
1152
+ ...enhancedError.sourceMappedStack ? {
1153
+ "error.stack.decoded": enhancedError.sourceMappedStack
1154
+ } : {},
910
1155
  "http.response.status_code": typeof set.status === "number" ? set.status : 500,
911
1156
  "http.duration_ms": duration,
912
- ...CUSTOM_ATTRIBUTES
1157
+ ...CUSTOM_ATTRIBUTES,
1158
+ ...getContextAttributesForTelemetry()
913
1159
  });
914
1160
  span.addEvent("exception", {
915
1161
  "exception.type": errorDetails.name,
916
1162
  "exception.message": errorDetails.message,
917
- "exception.stacktrace": errorDetails.stack,
1163
+ "exception.stacktrace": stackToUse,
918
1164
  "exception.escaped": "false"
919
1165
  });
920
1166
  span.end();
@@ -1029,6 +1275,29 @@ function telemetry(options = {}) {
1029
1275
  console.error("[telemetry] Failed to record request duration:", metricsError);
1030
1276
  }
1031
1277
  });
1278
+ if (merged.sourcemaps?.enabled !== false) {
1279
+ const rerouteDir = ".reroute";
1280
+ app.post("/__reroute/telemetry/inspect", async ({ body }) => {
1281
+ try {
1282
+ const { stack } = body;
1283
+ if (!stack) {
1284
+ return { error: "Missing stack trace" };
1285
+ }
1286
+ const { resolveStackTrace: resolveStackTrace2 } = await Promise.resolve().then(() => (init_sourcemap(), exports_sourcemap));
1287
+ const result = await resolveStackTrace2(stack, { rerouteDir });
1288
+ return {
1289
+ original: result.original,
1290
+ mapped: result.mapped,
1291
+ frames: result.frames
1292
+ };
1293
+ } catch (error) {
1294
+ console.error("[telemetry] Error inspection failed:", error);
1295
+ return {
1296
+ error: error instanceof Error ? error.message : "Unknown error"
1297
+ };
1298
+ }
1299
+ });
1300
+ }
1032
1301
  if (ENABLE_PROXY) {
1033
1302
  const API_KEY = merged.apiKey || process.env.SIGNOZ_API_KEY;
1034
1303
  const handleProxy = async (endpoint, requestBody) => {
@@ -1107,12 +1376,17 @@ function telemetry(options = {}) {
1107
1376
  }
1108
1377
  var init_plugin = __esm(() => {
1109
1378
  init_core();
1379
+ init_context();
1380
+ init_instrumentation();
1381
+ init_sourcemap();
1110
1382
  });
1111
1383
 
1112
1384
  // packages/telemetry/src/server/index.ts
1113
1385
  var init_server = __esm(() => {
1386
+ init_context();
1114
1387
  init_instrumentation();
1115
1388
  init_plugin();
1389
+ init_sourcemap();
1116
1390
  });
1117
1391
 
1118
1392
  // packages/telemetry/server.ts
@@ -1128,7 +1402,17 @@ export {
1128
1402
  withParentSpan,
1129
1403
  telemetry,
1130
1404
  setSpanAttributes,
1405
+ setContext,
1406
+ resolveStackTrace,
1407
+ getTraceContextForInjection,
1408
+ getContextAttributesForTelemetry,
1409
+ getContextAttr,
1410
+ formatStackFrames,
1411
+ extractTraceContext,
1412
+ enhanceError,
1413
+ clearSourceMapCache,
1414
+ clearContext,
1131
1415
  addSpanEvent
1132
1416
  };
1133
1417
 
1134
- //# debugId=B91F92BF15BBA06264756E2164756E21
1418
+ //# debugId=428DDF76947758DA64756E2164756E21