@logbrew/next 0.1.12 → 0.1.14

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 CHANGED
@@ -64,7 +64,7 @@ logbrew read logs --project "$LOGBREW_PROJECT_ID" \
64
64
  --json
65
65
  ```
66
66
 
67
- A successful ingest response proves submission. The authenticated read proves
67
+ A successful ingest response confirms submission. The authenticated read confirms
68
68
  that the event is indexed for the same project. If you no longer need the
69
69
  temporary project, archive it and remove its revoked one-time key file:
70
70
 
@@ -149,7 +149,10 @@ sends the same issue with `fetch` and loads no Node.js modules.
149
149
  Server and Edge issues carry the release and environment from
150
150
  `LOGBREW_RELEASE` and `LOGBREW_ENVIRONMENT`, or from Vercel's
151
151
  `VERCEL_GIT_COMMIT_SHA` and `VERCEL_ENV` when the LogBrew variables are not
152
- set. `LOGBREW_SERVICE_NAME` sets the service. Explicit `context` fields win.
152
+ set. `LOGBREW_SERVICE_NAME` sets the service. Without it, server issues and
153
+ Route Handler events use the `name` in your app's `package.json`. Edge and
154
+ browser code cannot read that file, so set `LOGBREW_SERVICE_NAME` or pass
155
+ `context` there. Explicit `context` fields win.
153
156
 
154
157
  By default, the issue includes the error message, exception type, structured
155
158
  stack frames, Next.js error digest, method, stable route file path, router kind,
@@ -168,6 +171,10 @@ If the same Route Handler also uses `withLogBrewRouteHandler`, set
168
171
  single issue owner. The wrapper can continue to capture successful requests,
169
172
  metrics, and trace context.
170
173
 
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
+
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
+
171
178
  ## App Router Route Handler
172
179
 
173
180
  ```js
@@ -263,7 +270,7 @@ import {
263
270
  const client = createLogBrewNextBrowserClient({
264
271
  clientKey: "LOGBREW_CLIENT_KEY",
265
272
  sdkName: "my-next-app",
266
- sdkVersion: "0.1.12"
273
+ sdkVersion: "0.1.14"
267
274
  });
268
275
 
269
276
  const routePatterns = [
@@ -340,7 +347,7 @@ import { createLogBrewNextClient } from "@logbrew/next";
340
347
  const client = createLogBrewNextClient({
341
348
  serverApiKey: "LOGBREW_SERVER_API_KEY",
342
349
  sdkName: "my-next-app",
343
- sdkVersion: "0.1.12"
350
+ sdkVersion: "0.1.14"
344
351
  });
345
352
  ```
346
353
 
package/client.cjs CHANGED
@@ -22,7 +22,7 @@ function createLogBrewNextBrowserClient({
22
22
  endpoint = DEFAULT_ENDPOINT,
23
23
  eventFilter,
24
24
  sdkName = "logbrew-next-client",
25
- sdkVersion = "0.1.12",
25
+ sdkVersion = "0.1.14",
26
26
  maxQueueSize,
27
27
  maxRetries = 2,
28
28
  onEventDropped,
package/client.js CHANGED
@@ -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.12",
25
+ sdkVersion = "0.1.14",
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.12",
28
+ sdkVersion: options.sdkVersion ?? "0.1.14",
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.12") {
27
+ if (!event || event.attributes.metadata.routeTemplate !== "/projects/[projectId]/settings" || event.attributes.metadata.operation !== "browser.navigation" || payload.sdk.version !== "0.1.14") {
28
28
  throw new Error(`unexpected Next client route span: ${JSON.stringify(event)}`);
29
29
  }
30
30
 
@@ -12,7 +12,7 @@ const POST = withLogBrewRouteHandler(
12
12
  serverApiKey: "LOGBREW_SERVER_API_KEY",
13
13
  captureRequests: false,
14
14
  sdkName: "logbrew-next-readme-example",
15
- sdkVersion: "0.1.12",
15
+ sdkVersion: "0.1.14",
16
16
  transport
17
17
  }
18
18
  );
@@ -12,7 +12,7 @@ const POST = withLogBrewRouteHandler(
12
12
  serverApiKey: "LOGBREW_SERVER_API_KEY",
13
13
  captureRequests: false,
14
14
  sdkName: "logbrew-next-real-user-smoke",
15
- sdkVersion: "0.1.12",
15
+ sdkVersion: "0.1.14",
16
16
  maxRetries: 1,
17
17
  transport
18
18
  }
package/index.cjs CHANGED
@@ -5,7 +5,7 @@ const {
5
5
  createIssueAttributesFromError,
6
6
  parseTraceparent
7
7
  } = require("@logbrew/sdk");
8
- const { createNodeFetchTransport } = require("@logbrew/node");
8
+ const { addLogBrewPackageService, createNodeFetchTransport } = require("@logbrew/node");
9
9
  const {
10
10
  createNextRequestErrorEvent,
11
11
  getTraceparentHeader,
@@ -23,7 +23,7 @@ function createLogBrewNextClient({
23
23
  serverApiKey,
24
24
  context,
25
25
  sdkName = "logbrew-next",
26
- sdkVersion = "0.1.12",
26
+ sdkVersion = "0.1.14",
27
27
  maxRetries = 2
28
28
  } = {}) {
29
29
  const authKey = serverApiKey ?? apiKey ?? readEnvServerApiKey() ?? readEnvApiKey();
@@ -33,7 +33,7 @@ function createLogBrewNextClient({
33
33
  "createLogBrewNextClient requires serverApiKey, apiKey, LOGBREW_SERVER_API_KEY, or LOGBREW_API_KEY"
34
34
  );
35
35
  }
36
- const deploymentContext = nextDeploymentContext(context);
36
+ const deploymentContext = addLogBrewPackageService(nextDeploymentContext(context));
37
37
  return LogBrewClient.create({ apiKey: authKey, context: deploymentContext, sdkName, sdkVersion, maxRetries });
38
38
  }
39
39
 
@@ -91,10 +91,16 @@ function withLogBrewRouteHandler(handler, options = {}) {
91
91
  try {
92
92
  const response = await handler(request, context, helpers);
93
93
  ensureResponse(response);
94
- await captureRouteSuccess(options, { request, response, context, client, owned, transport, startedAt, trace });
94
+ await captureRouteResponse(options, { request, response, context, client, owned, transport, startedAt, trace });
95
95
  return response;
96
96
  } catch (error) {
97
- await recordRouteError(options, error, { request, context, client, owned, transport, trace });
97
+ const nextStatus = nextResponseStatus(error, options);
98
+ if (nextStatus === undefined) {
99
+ await recordRouteError(options, error, { request, context, client, owned, transport, trace });
100
+ } else {
101
+ const response = new Response(null, { status: nextStatus });
102
+ await captureRouteResponse(options, { request, response, context, client, owned, transport, startedAt, trace });
103
+ }
98
104
  throw error;
99
105
  }
100
106
  });
@@ -285,6 +291,24 @@ function createRouteHelpers(client, transport, trace, request) {
285
291
  };
286
292
  }
287
293
 
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
+ }
305
+ if (digest === "NEXT_NOT_FOUND") {
306
+ return 404;
307
+ }
308
+ const clientError = /^NEXT_HTTP_ERROR_FALLBACK;(4\d\d)$/u.exec(digest);
309
+ return clientError ? Number(clientError[1]) : undefined;
310
+ }
311
+
288
312
  function ensureResponse(response) {
289
313
  if (!(response instanceof Response)) {
290
314
  throw new SdkError("route_handler_error", "Next.js route handler must return a Response");
@@ -307,7 +331,7 @@ async function notifyFailure(options, error, context) {
307
331
  }
308
332
  }
309
333
 
310
- async function captureRouteSuccess(options, runtime) {
334
+ async function captureRouteResponse(options, runtime) {
311
335
  const { request, response, context, client, startedAt, trace } = runtime;
312
336
  try {
313
337
  const durationMs = (options.captureRequests !== false || options.captureRequestMetrics === true)
package/index.d.cts CHANGED
@@ -180,6 +180,8 @@ 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. `redirect()` is never an issue. */
184
+ captureClientErrors?: boolean;
183
185
  /** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
184
186
  includeErrorStack?: boolean;
185
187
  includeSearchParams?: boolean;
package/index.d.ts CHANGED
@@ -180,6 +180,8 @@ 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. `redirect()` is never an issue. */
184
+ captureClientErrors?: boolean;
183
185
  /** Include raw stack text in issue metadata. Structured frames are always captured. Defaults to false. */
184
186
  includeErrorStack?: boolean;
185
187
  includeSearchParams?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/next",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Next.js App Router helpers for the public LogBrew JavaScript SDK.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
@@ -93,7 +93,7 @@
93
93
  "url": "git+https://github.com/LogBrewCo/sdk.git"
94
94
  },
95
95
  "peerDependencies": {
96
- "@logbrew/node": "^0.1.2",
96
+ "@logbrew/node": "^0.1.24",
97
97
  "@logbrew/sdk": "^0.1.32",
98
98
  "next": ">=15",
99
99
  "react": ">=18",