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.
- package/README.md +12 -8
- package/cli/bin.d.ts +1 -1
- package/cli/bin.js +136 -40
- package/cli/bin.js.map +16 -13
- 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/build.d.ts.map +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 +96 -9
- package/core/index.js.map +14 -11
- package/core/src/bundler/hash.d.ts +1 -1
- package/core/src/bundler/index.d.ts +1 -1
- package/core/src/config.d.ts +41 -13
- 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 +5 -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/serialize.d.ts +17 -0
- package/core/src/ssr/lib/serialize.d.ts.map +1 -0
- package/core/src/ssr/lib/setup.d.ts +5 -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 +1 -1
- package/core/src/ssr/render.d.ts.map +1 -1
- package/core/src/ssr/stream.d.ts +1 -1
- package/core/src/ssr/stream.d.ts.map +1 -1
- package/elysia/index.d.ts +1 -1
- package/elysia/index.js +96 -9
- package/elysia/index.js.map +14 -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/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/static.d.ts +1 -1
- package/elysia/src/types.d.ts +1 -1
- package/package.json +9 -13
- 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 +1 -1
- package/telemetry/react.js +539 -30
- package/telemetry/react.js.map +7 -6
- package/telemetry/server.d.ts +1 -1
- package/telemetry/server.js +304 -20
- package/telemetry/server.js.map +12 -10
- package/telemetry/src/react/api.d.ts +3 -2
- package/telemetry/src/react/api.d.ts.map +1 -1
- package/telemetry/src/react/context.d.ts +62 -0
- package/telemetry/src/react/context.d.ts.map +1 -0
- package/telemetry/src/react/index.d.ts +2 -1
- package/telemetry/src/react/index.d.ts.map +1 -1
- package/telemetry/src/react/telemetry.d.ts +4 -53
- package/telemetry/src/react/telemetry.d.ts.map +1 -1
- package/telemetry/src/server/context.d.ts +61 -0
- package/telemetry/src/server/context.d.ts.map +1 -0
- package/telemetry/src/server/index.d.ts +3 -1
- package/telemetry/src/server/index.d.ts.map +1 -1
- package/telemetry/src/server/instrumentation.d.ts +27 -2
- package/telemetry/src/server/instrumentation.d.ts.map +1 -1
- package/telemetry/src/server/plugin.d.ts +1 -1
- package/telemetry/src/server/plugin.d.ts.map +1 -1
- package/telemetry/src/server/sourcemap.d.ts +55 -0
- package/telemetry/src/server/sourcemap.d.ts.map +1 -0
package/telemetry/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* reroute-js v0.
|
|
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 =
|
|
604
|
-
const PROXY_PATHNAME =
|
|
605
|
-
const PROXY_VERBOSE =
|
|
606
|
-
const PROXY_HANDLER =
|
|
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
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
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":
|
|
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=
|
|
1418
|
+
//# debugId=428DDF76947758DA64756E2164756E21
|