@logbrew/next 0.1.7 → 0.1.9
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 +13 -9
- package/client.cjs +1 -1
- package/client.js +1 -1
- package/examples/client-route-spans.mjs +1 -1
- package/examples/readme-example.mjs +1 -1
- package/examples/real-user-smoke.mjs +1 -1
- package/index.cjs +94 -52
- package/index.d.cts +7 -0
- package/index.d.ts +7 -0
- package/instrumentation.cjs +6 -8
- package/instrumentation.js +6 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,13 +128,17 @@ it returns. A delivery or callback failure is reported through
|
|
|
128
128
|
already handling. The Edge runtime is left unchanged; use a Node.js route or
|
|
129
129
|
server boundary for LogBrew server delivery.
|
|
130
130
|
|
|
131
|
-
By default, the issue includes the error message,
|
|
132
|
-
stable route file path, router kind,
|
|
133
|
-
reason, and render type when Next.js
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
By default, the issue includes the error message, exception type, structured
|
|
132
|
+
stack frames, Next.js error digest, method, stable route file path, router kind,
|
|
133
|
+
route type, render source, revalidation reason, and render type when Next.js
|
|
134
|
+
supplies them. The exception mechanism is `nextjs.on_request_error`, or
|
|
135
|
+
`nextjs.route_handler` for errors thrown inside `withLogBrewRouteHandler`.
|
|
136
|
+
Frames keep only the file basename, line, column, and function name. The issue
|
|
137
|
+
does not capture request headers, authorization values, cookies, request
|
|
138
|
+
bodies, query strings, URL fragments, concrete dynamic path values, or raw
|
|
139
|
+
stack text. Set `includePathname: true` only when a query-free concrete
|
|
140
|
+
pathname is intentional and acceptable for that application, and
|
|
141
|
+
`includeErrorStack: true` only when raw stack text is acceptable.
|
|
138
142
|
|
|
139
143
|
If the same Route Handler also uses `withLogBrewRouteHandler`, set
|
|
140
144
|
`captureErrors: false` on that wrapper so the global request-error hook is the
|
|
@@ -232,7 +236,7 @@ import {
|
|
|
232
236
|
const client = createLogBrewNextBrowserClient({
|
|
233
237
|
clientKey: "LOGBREW_CLIENT_KEY",
|
|
234
238
|
sdkName: "my-next-app",
|
|
235
|
-
sdkVersion: "0.1.
|
|
239
|
+
sdkVersion: "0.1.9"
|
|
236
240
|
});
|
|
237
241
|
|
|
238
242
|
const routePatterns = [
|
|
@@ -269,7 +273,7 @@ import { createLogBrewNextClient } from "@logbrew/next";
|
|
|
269
273
|
const client = createLogBrewNextClient({
|
|
270
274
|
serverApiKey: "LOGBREW_SERVER_API_KEY",
|
|
271
275
|
sdkName: "my-next-app",
|
|
272
|
-
sdkVersion: "0.1.
|
|
276
|
+
sdkVersion: "0.1.9"
|
|
273
277
|
});
|
|
274
278
|
```
|
|
275
279
|
|
package/client.cjs
CHANGED
package/client.js
CHANGED
|
@@ -24,7 +24,7 @@ const event = captureNextNavigation(client, {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
const payload = JSON.parse(client.previewJson());
|
|
27
|
-
if (!event || event.attributes.metadata.routeTemplate !== "/projects/[projectId]/settings" || event.attributes.metadata.operation !== "browser.navigation" || payload.sdk.version !== "0.1.
|
|
27
|
+
if (!event || event.attributes.metadata.routeTemplate !== "/projects/[projectId]/settings" || event.attributes.metadata.operation !== "browser.navigation" || payload.sdk.version !== "0.1.9") {
|
|
28
28
|
throw new Error(`unexpected Next client route span: ${JSON.stringify(event)}`);
|
|
29
29
|
}
|
|
30
30
|
|
package/index.cjs
CHANGED
|
@@ -2,6 +2,7 @@ const { AsyncLocalStorage } = require("node:async_hooks");
|
|
|
2
2
|
const {
|
|
3
3
|
LogBrewClient,
|
|
4
4
|
SdkError,
|
|
5
|
+
createIssueAttributesFromError,
|
|
5
6
|
parseTraceparent
|
|
6
7
|
} = require("@logbrew/sdk");
|
|
7
8
|
const { createNodeFetchTransport } = require("@logbrew/node");
|
|
@@ -24,7 +25,7 @@ function createLogBrewNextClient({
|
|
|
24
25
|
serverApiKey,
|
|
25
26
|
context,
|
|
26
27
|
sdkName = "logbrew-next",
|
|
27
|
-
sdkVersion = "0.1.
|
|
28
|
+
sdkVersion = "0.1.9",
|
|
28
29
|
maxRetries = 2
|
|
29
30
|
} = {}) {
|
|
30
31
|
const authKey = serverApiKey ?? apiKey ?? readEnvServerApiKey() ?? readEnvApiKey();
|
|
@@ -49,11 +50,14 @@ function createLogBrewNextRequestErrorHandler(options = {}) {
|
|
|
49
50
|
const client = resolvedClient.client;
|
|
50
51
|
const transport = resolveTransport(options, { ...runtime, client }, defaultTransport);
|
|
51
52
|
runtime = { ...runtime, client, transport };
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
try {
|
|
54
|
+
const event = typeof options.errorEvent === "function"
|
|
55
|
+
? options.errorEvent(error, runtime)
|
|
56
|
+
: createNextRequestErrorEvent(error, request, context, options);
|
|
57
|
+
client.issue(event.id, event.timestamp, event.attributes);
|
|
58
|
+
} catch (captureError) {
|
|
59
|
+
await notifyFailure(options, captureError, runtime);
|
|
60
|
+
}
|
|
57
61
|
const response = resolvedClient.owned
|
|
58
62
|
? await client.shutdown(transport)
|
|
59
63
|
: await client.flush(transport);
|
|
@@ -69,6 +73,7 @@ function createLogBrewNextRequestErrorHandler(options = {}) {
|
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
function createNextRequestErrorEvent(error, request = {}, context = {}, {
|
|
76
|
+
includeErrorStack = false,
|
|
72
77
|
includePathname = false,
|
|
73
78
|
now = () => new Date().toISOString(),
|
|
74
79
|
idFactory = defaultNextRequestErrorId
|
|
@@ -80,10 +85,13 @@ function createNextRequestErrorEvent(error, request = {}, context = {}, {
|
|
|
80
85
|
return {
|
|
81
86
|
id: idFactory(error, request, context),
|
|
82
87
|
timestamp: now(),
|
|
83
|
-
attributes: {
|
|
88
|
+
attributes: createIssueAttributesFromError(error, {
|
|
84
89
|
title: `${method} ${routePath} failed`,
|
|
85
|
-
level: "error",
|
|
86
90
|
message: nextErrorMessage(error),
|
|
91
|
+
mechanism: "nextjs.on_request_error",
|
|
92
|
+
handled: false,
|
|
93
|
+
source: "nextjs.on_request_error",
|
|
94
|
+
includeErrorStack,
|
|
87
95
|
metadata: {
|
|
88
96
|
framework: "nextjs",
|
|
89
97
|
method,
|
|
@@ -93,10 +101,11 @@ function createNextRequestErrorEvent(error, request = {}, context = {}, {
|
|
|
93
101
|
...nextCategoricalMetadata("renderSource", context?.renderSource, NEXT_RENDER_SOURCES),
|
|
94
102
|
...nextCategoricalMetadata("revalidateReason", context?.revalidateReason, NEXT_REVALIDATE_REASONS),
|
|
95
103
|
...nextCategoricalMetadata("renderType", context?.renderType, NEXT_RENDER_TYPES),
|
|
104
|
+
...nextRequestTraceMetadata(request),
|
|
96
105
|
...(errorDigest ? { errorDigest } : {}),
|
|
97
106
|
...(pathname ? { pathname } : {})
|
|
98
107
|
}
|
|
99
|
-
}
|
|
108
|
+
})
|
|
100
109
|
};
|
|
101
110
|
}
|
|
102
111
|
|
|
@@ -110,7 +119,7 @@ function withLogBrewRouteHandler(handler, options = {}) {
|
|
|
110
119
|
: undefined;
|
|
111
120
|
|
|
112
121
|
return async function logBrewRouteHandler(request, context = {}) {
|
|
113
|
-
const client = resolveClient(options, request, context);
|
|
122
|
+
const { client, owned } = resolveClient(options, request, context);
|
|
114
123
|
const transport = resolveTransport(options, { request, context, client }, defaultTransport);
|
|
115
124
|
const trace = createRouteTraceContext(request, undefined, options);
|
|
116
125
|
const helpers = createRouteHelpers(client, transport, trace);
|
|
@@ -120,10 +129,10 @@ function withLogBrewRouteHandler(handler, options = {}) {
|
|
|
120
129
|
try {
|
|
121
130
|
const response = await handler(request, context, helpers);
|
|
122
131
|
ensureResponse(response);
|
|
123
|
-
await captureRouteSuccess(options, { request, response, context, client, transport, startedAt, trace });
|
|
132
|
+
await captureRouteSuccess(options, { request, response, context, client, owned, transport, startedAt, trace });
|
|
124
133
|
return response;
|
|
125
134
|
} catch (error) {
|
|
126
|
-
await recordRouteError(options, error, { request, context, client, transport, trace });
|
|
135
|
+
await recordRouteError(options, error, { request, context, client, owned, transport, trace });
|
|
127
136
|
throw error;
|
|
128
137
|
}
|
|
129
138
|
});
|
|
@@ -142,7 +151,7 @@ function createRouteRequestEvent(request, response, {
|
|
|
142
151
|
spanIdFactory = defaultSpanIdFactory,
|
|
143
152
|
trace
|
|
144
153
|
} = {}) {
|
|
145
|
-
const routePath = routeTemplateOnly(routeTemplate
|
|
154
|
+
const routePath = routeTemplateOnly(routeTemplate);
|
|
146
155
|
const method = request?.method ?? "GET";
|
|
147
156
|
const statusCode = Number(response?.status ?? 0);
|
|
148
157
|
const id = idFactory(request, response, routePath);
|
|
@@ -180,6 +189,7 @@ function createRouteRequestEvent(request, response, {
|
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
function createRouteErrorEvent(error, request, {
|
|
192
|
+
includeErrorStack = false,
|
|
183
193
|
includeSearchParams = false,
|
|
184
194
|
now = () => new Date().toISOString(),
|
|
185
195
|
idFactory = defaultRouteErrorId,
|
|
@@ -187,17 +197,18 @@ function createRouteErrorEvent(error, request, {
|
|
|
187
197
|
trace
|
|
188
198
|
} = {}) {
|
|
189
199
|
const url = safeUrl(request);
|
|
190
|
-
const routePath = routeTemplateOnly(routeTemplate
|
|
200
|
+
const routePath = routeTemplateOnly(routeTemplate);
|
|
191
201
|
const method = request?.method ?? "GET";
|
|
192
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
193
202
|
const routeTrace = trace ?? getActiveLogBrewTrace();
|
|
194
203
|
return {
|
|
195
204
|
id: idFactory(request, routePath),
|
|
196
205
|
timestamp: now(),
|
|
197
|
-
attributes: {
|
|
206
|
+
attributes: createIssueAttributesFromError(error, {
|
|
198
207
|
title: `${method} ${routePath} failed`,
|
|
199
|
-
|
|
200
|
-
|
|
208
|
+
mechanism: "nextjs.route_handler",
|
|
209
|
+
handled: false,
|
|
210
|
+
source: "nextjs.route_handler",
|
|
211
|
+
includeErrorStack,
|
|
201
212
|
metadata: {
|
|
202
213
|
framework: "nextjs",
|
|
203
214
|
method,
|
|
@@ -206,7 +217,7 @@ function createRouteErrorEvent(error, request, {
|
|
|
206
217
|
...(includeSearchParams ? { search: url.search || null } : {}),
|
|
207
218
|
...traceMetadata(routeTrace)
|
|
208
219
|
}
|
|
209
|
-
}
|
|
220
|
+
})
|
|
210
221
|
};
|
|
211
222
|
}
|
|
212
223
|
|
|
@@ -218,7 +229,7 @@ function createRequestMetricEvent(request, response, {
|
|
|
218
229
|
routeTemplate
|
|
219
230
|
} = {}) {
|
|
220
231
|
const method = request?.method ?? "GET";
|
|
221
|
-
const resolvedRouteTemplate = routeTemplateOnly(routeTemplate
|
|
232
|
+
const resolvedRouteTemplate = routeTemplateOnly(routeTemplate);
|
|
222
233
|
const statusCode = Number(response?.status ?? 0);
|
|
223
234
|
return {
|
|
224
235
|
id: idFactory(request, response, resolvedRouteTemplate),
|
|
@@ -243,12 +254,12 @@ function createRequestMetricEvent(request, response, {
|
|
|
243
254
|
|
|
244
255
|
function resolveClient(options, request, context) {
|
|
245
256
|
if (typeof options.client === "function") {
|
|
246
|
-
return options.client({ request, context });
|
|
257
|
+
return { client: options.client({ request, context }), owned: true };
|
|
247
258
|
}
|
|
248
259
|
if (options.client) {
|
|
249
|
-
return options.client;
|
|
260
|
+
return { client: options.client, owned: false };
|
|
250
261
|
}
|
|
251
|
-
return createLogBrewNextClient(options);
|
|
262
|
+
return { client: createLogBrewNextClient(options), owned: true };
|
|
252
263
|
}
|
|
253
264
|
|
|
254
265
|
function resolveTransport(options, runtime, defaultTransport) {
|
|
@@ -293,11 +304,16 @@ async function notifyFlush(options, flushResponse, context) {
|
|
|
293
304
|
|
|
294
305
|
async function notifyFailure(options, error, context) {
|
|
295
306
|
if (typeof options.onCaptureError === "function") {
|
|
296
|
-
|
|
307
|
+
try {
|
|
308
|
+
await options.onCaptureError(error, context);
|
|
309
|
+
} catch {
|
|
310
|
+
// A capture callback must not change the application's response or error.
|
|
311
|
+
}
|
|
297
312
|
}
|
|
298
313
|
}
|
|
299
314
|
|
|
300
|
-
async function captureRouteSuccess(options,
|
|
315
|
+
async function captureRouteSuccess(options, runtime) {
|
|
316
|
+
const { request, response, context, client, startedAt, trace } = runtime;
|
|
301
317
|
try {
|
|
302
318
|
const durationMs = (options.captureRequests !== false || options.captureRequestMetrics === true)
|
|
303
319
|
? routeDurationMs(options, startedAt)
|
|
@@ -308,7 +324,17 @@ async function captureRouteSuccess(options, { request, response, context, client
|
|
|
308
324
|
if (options.captureRequestMetrics === true) {
|
|
309
325
|
recordRouteMetric(options, { request, response, context, client, durationMs, trace });
|
|
310
326
|
}
|
|
311
|
-
|
|
327
|
+
} catch (error) {
|
|
328
|
+
await notifyFailure(options, error, { request, context, client, trace });
|
|
329
|
+
}
|
|
330
|
+
await finalizeRouteCapture(options, runtime);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function finalizeRouteCapture(options, { request, context, client, owned, transport, trace }) {
|
|
334
|
+
try {
|
|
335
|
+
const flushResponse = owned
|
|
336
|
+
? await client.shutdown(transport)
|
|
337
|
+
: await client.flush(transport);
|
|
312
338
|
await notifyFlush(options, flushResponse, { request, context, client, trace });
|
|
313
339
|
} catch (error) {
|
|
314
340
|
await notifyFailure(options, error, { request, context, client, trace });
|
|
@@ -341,25 +367,24 @@ function recordRouteMetric(options, { request, response, context, client, durati
|
|
|
341
367
|
captureRouteMetricEvent(client, event);
|
|
342
368
|
}
|
|
343
369
|
|
|
344
|
-
async function recordRouteError(options, error,
|
|
345
|
-
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
370
|
+
async function recordRouteError(options, error, runtime) {
|
|
371
|
+
const { request, context, client, trace } = runtime;
|
|
348
372
|
const routeTrace = trace ?? getActiveLogBrewTrace();
|
|
349
|
-
const event = typeof options.errorEvent === "function"
|
|
350
|
-
? options.errorEvent(error, { request, context, client, trace: routeTrace })
|
|
351
|
-
: createRouteErrorEvent(error, request, {
|
|
352
|
-
...options,
|
|
353
|
-
routeTemplate: resolveRouteTemplate(options, request, context),
|
|
354
|
-
trace: routeTrace
|
|
355
|
-
});
|
|
356
373
|
try {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
374
|
+
if (options.captureErrors !== false) {
|
|
375
|
+
const event = typeof options.errorEvent === "function"
|
|
376
|
+
? options.errorEvent(error, { request, context, client, trace: routeTrace })
|
|
377
|
+
: createRouteErrorEvent(error, request, {
|
|
378
|
+
...options,
|
|
379
|
+
routeTemplate: resolveRouteTemplate(options, request, context),
|
|
380
|
+
trace: routeTrace
|
|
381
|
+
});
|
|
382
|
+
client.issue(event.id, event.timestamp, event.attributes);
|
|
383
|
+
}
|
|
360
384
|
} catch (captureError) {
|
|
361
385
|
await notifyFailure(options, captureError, { request, context, client, trace: routeTrace });
|
|
362
386
|
}
|
|
387
|
+
await finalizeRouteCapture(options, { ...runtime, trace: routeTrace });
|
|
363
388
|
}
|
|
364
389
|
|
|
365
390
|
function captureRouteRequestEvent(client, event) {
|
|
@@ -415,7 +440,7 @@ function nextRoutePath(value) {
|
|
|
415
440
|
try {
|
|
416
441
|
pathname = new URL(value, "http://localhost").pathname;
|
|
417
442
|
} catch {
|
|
418
|
-
|
|
443
|
+
return "/";
|
|
419
444
|
}
|
|
420
445
|
if (typeof pathname !== "string" || pathname === "") {
|
|
421
446
|
return "/";
|
|
@@ -451,11 +476,35 @@ function nextErrorMessage(error) {
|
|
|
451
476
|
: `${normalized.slice(0, MAX_REQUEST_ERROR_MESSAGE_LENGTH - 1)}…`;
|
|
452
477
|
}
|
|
453
478
|
|
|
479
|
+
function nextRequestTraceMetadata(request) {
|
|
480
|
+
try {
|
|
481
|
+
const traceparent = getTraceparentHeader(request);
|
|
482
|
+
if (!traceparent) {
|
|
483
|
+
return {};
|
|
484
|
+
}
|
|
485
|
+
const trace = parseTraceparent(traceparent);
|
|
486
|
+
return {
|
|
487
|
+
traceId: trace.traceId,
|
|
488
|
+
parentSpanId: trace.parentSpanId,
|
|
489
|
+
sampled: trace.sampled
|
|
490
|
+
};
|
|
491
|
+
} catch {
|
|
492
|
+
return {};
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
454
496
|
function getTraceparentHeader(request) {
|
|
455
|
-
|
|
497
|
+
const headers = request?.headers;
|
|
498
|
+
if (!headers) {
|
|
456
499
|
return undefined;
|
|
457
500
|
}
|
|
458
|
-
|
|
501
|
+
let value;
|
|
502
|
+
if (typeof headers.get === "function") {
|
|
503
|
+
value = headers.get("traceparent");
|
|
504
|
+
} else {
|
|
505
|
+
const names = Object.keys(headers).filter(name => name.toLowerCase() === "traceparent");
|
|
506
|
+
value = names.length === 1 ? headers[names[0]] : undefined;
|
|
507
|
+
}
|
|
459
508
|
return typeof value === "string" ? value : undefined;
|
|
460
509
|
}
|
|
461
510
|
|
|
@@ -463,18 +512,11 @@ function resolveRouteTemplate(options, request, context) {
|
|
|
463
512
|
const value = typeof options.routeTemplate === "function"
|
|
464
513
|
? options.routeTemplate(request, context)
|
|
465
514
|
: options.routeTemplate;
|
|
466
|
-
return routeTemplateOnly(value
|
|
515
|
+
return routeTemplateOnly(value);
|
|
467
516
|
}
|
|
468
517
|
|
|
469
518
|
function routeTemplateOnly(value) {
|
|
470
|
-
|
|
471
|
-
return "/";
|
|
472
|
-
}
|
|
473
|
-
try {
|
|
474
|
-
return new URL(value, "http://localhost").pathname || "/";
|
|
475
|
-
} catch {
|
|
476
|
-
return value.split(/[?#]/)[0] || "/";
|
|
477
|
-
}
|
|
519
|
+
return nextRoutePath(value);
|
|
478
520
|
}
|
|
479
521
|
|
|
480
522
|
function statusCodeClass(statusCode) {
|
package/index.d.cts
CHANGED
|
@@ -75,6 +75,7 @@ export type LogBrewNextRequestErrorOptions = CreateLogBrewNextClientConfig & Nod
|
|
|
75
75
|
transport?: Transport | ((context: LogBrewNextRequestErrorInput & { client: LogBrewClient }) => Transport);
|
|
76
76
|
/** Opt into a query-free concrete pathname. Stable routePath metadata remains the default. */
|
|
77
77
|
includePathname?: boolean;
|
|
78
|
+
/** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
|
|
78
79
|
now?: () => string;
|
|
79
80
|
idFactory?: (
|
|
80
81
|
error: LogBrewNextRequestError,
|
|
@@ -170,14 +171,18 @@ export type LogBrewRouteMetricEvent = {
|
|
|
170
171
|
};
|
|
171
172
|
|
|
172
173
|
export type LogBrewRouteOptions<TContext = LogBrewRouteContext> = CreateLogBrewNextClientConfig & NodeFetchTransportConfig & {
|
|
174
|
+
/** A fixed client stays caller-owned and is flushed, not shut down. A factory must return a fresh client per request. */
|
|
173
175
|
client?: LogBrewClient | LogBrewClientFactory<TContext>;
|
|
174
176
|
/** Override the default Node fetch transport, optionally per request. */
|
|
175
177
|
transport?: Transport | LogBrewTransportFactory<TContext>;
|
|
176
178
|
captureRequests?: boolean;
|
|
177
179
|
captureRequestMetrics?: boolean;
|
|
178
180
|
captureErrors?: boolean;
|
|
181
|
+
/** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
|
|
182
|
+
includeErrorStack?: boolean;
|
|
179
183
|
includeSearchParams?: boolean;
|
|
180
184
|
metricName?: string;
|
|
185
|
+
/** Supply a stable route template. Missing or invalid templates use "/" without reading the request pathname. */
|
|
181
186
|
routeTemplate?: string | ((request: Request, context: TContext) => string | null | undefined);
|
|
182
187
|
now?: () => string;
|
|
183
188
|
nowMs?: () => number;
|
|
@@ -222,6 +227,7 @@ export declare function createNextRequestErrorEvent(
|
|
|
222
227
|
request: LogBrewNextRequestErrorRequest,
|
|
223
228
|
context: LogBrewNextRequestErrorContext,
|
|
224
229
|
options?: {
|
|
230
|
+
includeErrorStack?: boolean;
|
|
225
231
|
includePathname?: boolean;
|
|
226
232
|
now?: () => string;
|
|
227
233
|
idFactory?: (
|
|
@@ -268,6 +274,7 @@ export declare function createRouteErrorEvent(
|
|
|
268
274
|
error: unknown,
|
|
269
275
|
request: Request,
|
|
270
276
|
options?: {
|
|
277
|
+
includeErrorStack?: boolean;
|
|
271
278
|
includeSearchParams?: boolean;
|
|
272
279
|
now?: () => string;
|
|
273
280
|
idFactory?: (request: Request, routeTemplate?: string) => string;
|
package/index.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export type LogBrewNextRequestErrorOptions = CreateLogBrewNextClientConfig & Nod
|
|
|
75
75
|
transport?: Transport | ((context: LogBrewNextRequestErrorInput & { client: LogBrewClient }) => Transport);
|
|
76
76
|
/** Opt into a query-free concrete pathname. Stable routePath metadata remains the default. */
|
|
77
77
|
includePathname?: boolean;
|
|
78
|
+
/** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
|
|
78
79
|
now?: () => string;
|
|
79
80
|
idFactory?: (
|
|
80
81
|
error: LogBrewNextRequestError,
|
|
@@ -170,14 +171,18 @@ export type LogBrewRouteMetricEvent = {
|
|
|
170
171
|
};
|
|
171
172
|
|
|
172
173
|
export type LogBrewRouteOptions<TContext = LogBrewRouteContext> = CreateLogBrewNextClientConfig & NodeFetchTransportConfig & {
|
|
174
|
+
/** A fixed client stays caller-owned and is flushed, not shut down. A factory must return a fresh client per request. */
|
|
173
175
|
client?: LogBrewClient | LogBrewClientFactory<TContext>;
|
|
174
176
|
/** Override the default Node fetch transport, optionally per request. */
|
|
175
177
|
transport?: Transport | LogBrewTransportFactory<TContext>;
|
|
176
178
|
captureRequests?: boolean;
|
|
177
179
|
captureRequestMetrics?: boolean;
|
|
178
180
|
captureErrors?: boolean;
|
|
181
|
+
/** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
|
|
182
|
+
includeErrorStack?: boolean;
|
|
179
183
|
includeSearchParams?: boolean;
|
|
180
184
|
metricName?: string;
|
|
185
|
+
/** Supply a stable route template. Missing or invalid templates use "/" without reading the request pathname. */
|
|
181
186
|
routeTemplate?: string | ((request: Request, context: TContext) => string | null | undefined);
|
|
182
187
|
now?: () => string;
|
|
183
188
|
nowMs?: () => number;
|
|
@@ -222,6 +227,7 @@ export declare function createNextRequestErrorEvent(
|
|
|
222
227
|
request: LogBrewNextRequestErrorRequest,
|
|
223
228
|
context: LogBrewNextRequestErrorContext,
|
|
224
229
|
options?: {
|
|
230
|
+
includeErrorStack?: boolean;
|
|
225
231
|
includePathname?: boolean;
|
|
226
232
|
now?: () => string;
|
|
227
233
|
idFactory?: (
|
|
@@ -268,6 +274,7 @@ export declare function createRouteErrorEvent(
|
|
|
268
274
|
error: unknown,
|
|
269
275
|
request: Request,
|
|
270
276
|
options?: {
|
|
277
|
+
includeErrorStack?: boolean;
|
|
271
278
|
includeSearchParams?: boolean;
|
|
272
279
|
now?: () => string;
|
|
273
280
|
idFactory?: (request: Request, routeTemplate?: string) => string;
|
package/instrumentation.cjs
CHANGED
|
@@ -3,15 +3,13 @@ let nodeHandlerPromise;
|
|
|
3
3
|
function createLogBrewNextRequestErrorHandler(options = {}) {
|
|
4
4
|
let handler;
|
|
5
5
|
return async function logBrewNextRequestErrorHandler(error, request, context) {
|
|
6
|
-
if (globalThis.process?.env?.NEXT_RUNTIME === "edge") {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
if (process.env.NEXT_RUNTIME !== "edge") {
|
|
8
|
+
nodeHandlerPromise ??= Promise.resolve().then(() => require("./index.cjs"));
|
|
9
|
+
const nodeModule = await nodeHandlerPromise;
|
|
10
|
+
handler ??= nodeModule.createLogBrewNextRequestErrorHandler(options);
|
|
11
|
+
await handler(error, request, context);
|
|
12
|
+
}
|
|
15
13
|
} catch (captureError) {
|
|
16
14
|
if (typeof options.onCaptureError === "function") {
|
|
17
15
|
try {
|
package/instrumentation.js
CHANGED
|
@@ -3,15 +3,13 @@ let nodeHandlerPromise;
|
|
|
3
3
|
export function createLogBrewNextRequestErrorHandler(options = {}) {
|
|
4
4
|
let handler;
|
|
5
5
|
return async function logBrewNextRequestErrorHandler(error, request, context) {
|
|
6
|
-
if (globalThis.process?.env?.NEXT_RUNTIME === "edge") {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
if (process.env.NEXT_RUNTIME !== "edge") {
|
|
8
|
+
nodeHandlerPromise ??= import("./index.js");
|
|
9
|
+
const module = await nodeHandlerPromise;
|
|
10
|
+
handler ??= module.createLogBrewNextRequestErrorHandler(options);
|
|
11
|
+
await handler(error, request, context);
|
|
12
|
+
}
|
|
15
13
|
} catch (captureError) {
|
|
16
14
|
if (typeof options.onCaptureError === "function") {
|
|
17
15
|
try {
|