usetraceforge 0.1.15 → 0.1.16
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/dist/index.js +3 -0
- package/dist/next.d.ts +1 -1
- package/dist/next.js +14 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -121,6 +121,9 @@ const setupAutoCapture = () => {
|
|
|
121
121
|
};
|
|
122
122
|
const TraceForge = {
|
|
123
123
|
init: (options) => {
|
|
124
|
+
if (!options.apiKey) {
|
|
125
|
+
throw new Error("TraceForge.init() failed: Missing API Key.");
|
|
126
|
+
}
|
|
124
127
|
const previousApiKey = config?.apiKey ?? null;
|
|
125
128
|
const previousEndpoint = config?.endpoint ?? defaultEndpoint;
|
|
126
129
|
config = {
|
package/dist/next.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function withTraceForgeRoute(handler: Function): (...args: any[]) => Promise<any>;
|
package/dist/next.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import TraceForge from "./index.js";
|
|
2
2
|
// A wrapper for Next.js API Routes (App Router or Pages Router)
|
|
3
|
-
export function
|
|
3
|
+
export function withTraceForgeRoute(handler) {
|
|
4
4
|
return async function (...args) {
|
|
5
|
+
// Auto-initialize TraceForge in this isolated runtime if it hasn't been initialized
|
|
6
|
+
try {
|
|
7
|
+
if (process.env.NEXT_PUBLIC_TRACEFORGE_API_KEY) {
|
|
8
|
+
TraceForge.init({
|
|
9
|
+
apiKey: process.env.NEXT_PUBLIC_TRACEFORGE_API_KEY,
|
|
10
|
+
endpoint: process.env.NEXT_PUBLIC_TRACEFORGE_INGEST_URL,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
// Ignore init errors here, it will fail gracefully during capture if truly unconfigured
|
|
16
|
+
}
|
|
5
17
|
try {
|
|
6
18
|
return await handler(...args);
|
|
7
19
|
}
|
|
8
20
|
catch (error) {
|
|
9
21
|
// Catch Next.js serverless API errors
|
|
10
22
|
await TraceForge.captureException(error, {
|
|
11
|
-
environment: "node",
|
|
23
|
+
environment: process.env.NODE_ENV || "node",
|
|
12
24
|
tags: {
|
|
13
25
|
runtime: "nextjs-api"
|
|
14
26
|
}
|