@logbrew/next 0.1.13 → 0.1.15
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 +6 -4
- package/client.cjs +3 -3
- package/client.d.cts +1 -1
- package/client.d.ts +1 -1
- package/client.js +3 -3
- package/edge.cjs +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 +17 -9
- package/index.d.cts +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -173,6 +173,8 @@ metrics, and trace context.
|
|
|
173
173
|
|
|
174
174
|
`notFound()`, `forbidden()`, and `unauthorized()` inside a wrapped Route Handler are not issues: they describe the request, not a failure in your app. Next.js still sends its 404, 403, or 401 response, and the wrapper records the request with that status. Other thrown errors stay issues even when they carry a 4xx `status`, because Next.js answers them with a 500. Set `captureClientErrors: true` to report those three as issues too.
|
|
175
175
|
|
|
176
|
+
`redirect()` and `permanentRedirect()` inside a wrapped Route Handler are not issues either. Next.js still sends its 307 or 308 response, and the wrapper records the request with that status. The wrapper does not record the redirect destination. `captureClientErrors` does not change this.
|
|
177
|
+
|
|
176
178
|
## App Router Route Handler
|
|
177
179
|
|
|
178
180
|
```js
|
|
@@ -268,7 +270,7 @@ import {
|
|
|
268
270
|
const client = createLogBrewNextBrowserClient({
|
|
269
271
|
clientKey: "LOGBREW_CLIENT_KEY",
|
|
270
272
|
sdkName: "my-next-app",
|
|
271
|
-
sdkVersion: "0.1.
|
|
273
|
+
sdkVersion: "0.1.15"
|
|
272
274
|
});
|
|
273
275
|
|
|
274
276
|
const routePatterns = [
|
|
@@ -299,8 +301,8 @@ Use `captureNextNavigation(client, input)` when you want to emit a route span fr
|
|
|
299
301
|
|
|
300
302
|
## Client Errors
|
|
301
303
|
|
|
302
|
-
`createLogBrewNextBrowserClient()` sends events on its own with `fetch` (
|
|
303
|
-
|
|
304
|
+
`createLogBrewNextBrowserClient()` sends events on its own with `fetch` (1
|
|
305
|
+
second after the first queued event). Pass a `transport` to
|
|
304
306
|
replace it, or `transport: null` to keep the client manual. Browser events
|
|
305
307
|
carry the release and environment from `NEXT_PUBLIC_LOGBREW_RELEASE` and
|
|
306
308
|
`NEXT_PUBLIC_LOGBREW_ENVIRONMENT`, or from `NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA`
|
|
@@ -345,7 +347,7 @@ import { createLogBrewNextClient } from "@logbrew/next";
|
|
|
345
347
|
const client = createLogBrewNextClient({
|
|
346
348
|
serverApiKey: "LOGBREW_SERVER_API_KEY",
|
|
347
349
|
sdkName: "my-next-app",
|
|
348
|
-
sdkVersion: "0.1.
|
|
350
|
+
sdkVersion: "0.1.15"
|
|
349
351
|
});
|
|
350
352
|
```
|
|
351
353
|
|
package/client.cjs
CHANGED
|
@@ -10,8 +10,8 @@ const {
|
|
|
10
10
|
} = require("@logbrew/sdk");
|
|
11
11
|
|
|
12
12
|
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
13
|
-
//
|
|
14
|
-
const DEFAULT_BROWSER_DELIVERY_INTERVAL_MS =
|
|
13
|
+
// Send 1 second after the first queued event; pagehide flushes the rest when the page closes.
|
|
14
|
+
const DEFAULT_BROWSER_DELIVERY_INTERVAL_MS = 1000;
|
|
15
15
|
const clientEndpoints = new WeakMap();
|
|
16
16
|
|
|
17
17
|
function createLogBrewNextBrowserClient({
|
|
@@ -22,7 +22,7 @@ function createLogBrewNextBrowserClient({
|
|
|
22
22
|
endpoint = DEFAULT_ENDPOINT,
|
|
23
23
|
eventFilter,
|
|
24
24
|
sdkName = "logbrew-next-client",
|
|
25
|
-
sdkVersion = "0.1.
|
|
25
|
+
sdkVersion = "0.1.15",
|
|
26
26
|
maxQueueSize,
|
|
27
27
|
maxRetries = 2,
|
|
28
28
|
onEventDropped,
|
package/client.d.cts
CHANGED
|
@@ -19,7 +19,7 @@ export type CreateLogBrewNextBrowserClientConfig = {
|
|
|
19
19
|
eventFilter?: EventFilter;
|
|
20
20
|
maxQueueSize?: number;
|
|
21
21
|
onEventDropped?: (drop: DroppedEvent) => void;
|
|
22
|
-
/** Delivery interval after the first queued event. Defaults to
|
|
22
|
+
/** Delivery interval after the first queued event. Defaults to 1000 ms. */
|
|
23
23
|
deliveryIntervalMs?: number;
|
|
24
24
|
/** Ingest endpoint for the built-in fetch transport. */
|
|
25
25
|
endpoint?: string;
|
package/client.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type CreateLogBrewNextBrowserClientConfig = {
|
|
|
19
19
|
eventFilter?: EventFilter;
|
|
20
20
|
maxQueueSize?: number;
|
|
21
21
|
onEventDropped?: (drop: DroppedEvent) => void;
|
|
22
|
-
/** Delivery interval after the first queued event. Defaults to
|
|
22
|
+
/** Delivery interval after the first queued event. Defaults to 1000 ms. */
|
|
23
23
|
deliveryIntervalMs?: number;
|
|
24
24
|
/** Ingest endpoint for the built-in fetch transport. */
|
|
25
25
|
endpoint?: string;
|
package/client.js
CHANGED
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
} from "@logbrew/sdk";
|
|
11
11
|
|
|
12
12
|
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
13
|
-
//
|
|
14
|
-
const DEFAULT_BROWSER_DELIVERY_INTERVAL_MS =
|
|
13
|
+
// Send 1 second after the first queued event; pagehide flushes the rest when the page closes.
|
|
14
|
+
const DEFAULT_BROWSER_DELIVERY_INTERVAL_MS = 1000;
|
|
15
15
|
const clientEndpoints = new WeakMap();
|
|
16
16
|
|
|
17
17
|
export function createLogBrewNextBrowserClient({
|
|
@@ -22,7 +22,7 @@ export function createLogBrewNextBrowserClient({
|
|
|
22
22
|
endpoint = DEFAULT_ENDPOINT,
|
|
23
23
|
eventFilter,
|
|
24
24
|
sdkName = "logbrew-next-client",
|
|
25
|
-
sdkVersion = "0.1.
|
|
25
|
+
sdkVersion = "0.1.15",
|
|
26
26
|
maxQueueSize,
|
|
27
27
|
maxRetries = 2,
|
|
28
28
|
onEventDropped,
|
package/edge.cjs
CHANGED
|
@@ -25,7 +25,7 @@ function createLogBrewNextEdgeRequestErrorHandler(options = {}) {
|
|
|
25
25
|
apiKey: authKey,
|
|
26
26
|
context: deploymentContext,
|
|
27
27
|
sdkName: options.sdkName ?? "logbrew-next",
|
|
28
|
-
sdkVersion: options.sdkVersion ?? "0.1.
|
|
28
|
+
sdkVersion: options.sdkVersion ?? "0.1.15",
|
|
29
29
|
maxRetries: options.maxRetries ?? 2
|
|
30
30
|
});
|
|
31
31
|
const event = typeof options.errorEvent === "function"
|
|
@@ -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.15") {
|
|
28
28
|
throw new Error(`unexpected Next client route span: ${JSON.stringify(event)}`);
|
|
29
29
|
}
|
|
30
30
|
|
package/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ function createLogBrewNextClient({
|
|
|
23
23
|
serverApiKey,
|
|
24
24
|
context,
|
|
25
25
|
sdkName = "logbrew-next",
|
|
26
|
-
sdkVersion = "0.1.
|
|
26
|
+
sdkVersion = "0.1.15",
|
|
27
27
|
maxRetries = 2
|
|
28
28
|
} = {}) {
|
|
29
29
|
const authKey = serverApiKey ?? apiKey ?? readEnvServerApiKey() ?? readEnvApiKey();
|
|
@@ -94,11 +94,11 @@ function withLogBrewRouteHandler(handler, options = {}) {
|
|
|
94
94
|
await captureRouteResponse(options, { request, response, context, client, owned, transport, startedAt, trace });
|
|
95
95
|
return response;
|
|
96
96
|
} catch (error) {
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
97
|
+
const nextStatus = nextResponseStatus(error, options);
|
|
98
|
+
if (nextStatus === undefined) {
|
|
99
99
|
await recordRouteError(options, error, { request, context, client, owned, transport, trace });
|
|
100
100
|
} else {
|
|
101
|
-
const response = new Response(null, { status:
|
|
101
|
+
const response = new Response(null, { status: nextStatus });
|
|
102
102
|
await captureRouteResponse(options, { request, response, context, client, owned, transport, startedAt, trace });
|
|
103
103
|
}
|
|
104
104
|
throw error;
|
|
@@ -291,14 +291,22 @@ function createRouteHelpers(client, transport, trace, request) {
|
|
|
291
291
|
};
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
|
|
294
|
+
// Next.js answers these thrown digests itself: redirect() and permanentRedirect() with a 3xx, and
|
|
295
|
+
// notFound(), forbidden(), and unauthorized() with a 4xx. The redirect destination is never read.
|
|
296
|
+
function nextResponseStatus(error, { captureClientErrors }) {
|
|
297
|
+
const digest = typeof error?.digest === "string" ? error.digest : "";
|
|
298
|
+
const redirect = /^NEXT_REDIRECT;(?:push|replace);.*;(30[378]);$/su.exec(digest);
|
|
299
|
+
if (redirect) {
|
|
300
|
+
return Number(redirect[1]);
|
|
301
|
+
}
|
|
302
|
+
if (captureClientErrors === true) {
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
297
305
|
if (digest === "NEXT_NOT_FOUND") {
|
|
298
306
|
return 404;
|
|
299
307
|
}
|
|
300
|
-
const
|
|
301
|
-
return
|
|
308
|
+
const clientError = /^NEXT_HTTP_ERROR_FALLBACK;(4\d\d)$/u.exec(digest);
|
|
309
|
+
return clientError ? Number(clientError[1]) : undefined;
|
|
302
310
|
}
|
|
303
311
|
|
|
304
312
|
function ensureResponse(response) {
|
package/index.d.cts
CHANGED
|
@@ -180,7 +180,7 @@ export type LogBrewRouteOptions<TContext = LogBrewRouteContext> = CreateLogBrewN
|
|
|
180
180
|
captureRequests?: boolean;
|
|
181
181
|
captureRequestMetrics?: boolean;
|
|
182
182
|
captureErrors?: boolean;
|
|
183
|
-
/** Report `notFound()`, `forbidden()`, and `unauthorized()` as issues too. Defaults to false. */
|
|
183
|
+
/** Report `notFound()`, `forbidden()`, and `unauthorized()` as issues too. Defaults to false. `redirect()` is never an issue. */
|
|
184
184
|
captureClientErrors?: boolean;
|
|
185
185
|
/** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
|
|
186
186
|
includeErrorStack?: boolean;
|
package/index.d.ts
CHANGED
|
@@ -180,7 +180,7 @@ export type LogBrewRouteOptions<TContext = LogBrewRouteContext> = CreateLogBrewN
|
|
|
180
180
|
captureRequests?: boolean;
|
|
181
181
|
captureRequestMetrics?: boolean;
|
|
182
182
|
captureErrors?: boolean;
|
|
183
|
-
/** Report `notFound()`, `forbidden()`, and `unauthorized()` as issues too. Defaults to false. */
|
|
183
|
+
/** Report `notFound()`, `forbidden()`, and `unauthorized()` as issues too. Defaults to false. `redirect()` is never an issue. */
|
|
184
184
|
captureClientErrors?: boolean;
|
|
185
185
|
/** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
|
|
186
186
|
includeErrorStack?: boolean;
|