@logbrew/next 0.1.11 → 0.1.13

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
 
@@ -75,6 +75,24 @@ rm -f "$HOME/.logbrew/next-service.ingest"
75
75
  unset LOGBREW_PROJECT_ID
76
76
  ```
77
77
 
78
+ ## Read Events Back
79
+
80
+ A successful send shows that LogBrew accepted the request. It does not show
81
+ that you can read the event. After your app sends one event, read it
82
+ back with a project read key:
83
+
84
+ ```bash
85
+ logbrew projects keys create "<project_id>" --kind read \
86
+ --ingest-key-file "$HOME/.logbrew/setup-check.read" --json
87
+ export LOGBREW_TOKEN="$(< "$HOME/.logbrew/setup-check.read")"
88
+ logbrew read logs --since 1h --json
89
+ logbrew issues --since 1h --json
90
+ ```
91
+
92
+ A read key reads 1 project and cannot send telemetry. Run `unset LOGBREW_TOKEN`
93
+ when you finish. [Read your events back](https://docs.logbrew.co/guides/verify-setup)
94
+ covers key kinds, empty results, and how to revoke the key.
95
+
78
96
  ## Release Artifacts
79
97
 
80
98
  For production Next.js builds, wrap `next.config.mjs` with the build-time release-artifact helper. It enables `productionBrowserSourceMaps` only when your config has not chosen a value, runs after the production compile, injects matching Debug IDs, strips embedded source text by default, writes a privacy-bounded manifest next to `.next`, and can upload the prepared artifacts before the build completes:
@@ -131,7 +149,10 @@ sends the same issue with `fetch` and loads no Node.js modules.
131
149
  Server and Edge issues carry the release and environment from
132
150
  `LOGBREW_RELEASE` and `LOGBREW_ENVIRONMENT`, or from Vercel's
133
151
  `VERCEL_GIT_COMMIT_SHA` and `VERCEL_ENV` when the LogBrew variables are not
134
- 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.
135
156
 
136
157
  By default, the issue includes the error message, exception type, structured
137
158
  stack frames, Next.js error digest, method, stable route file path, router kind,
@@ -150,6 +171,8 @@ If the same Route Handler also uses `withLogBrewRouteHandler`, set
150
171
  single issue owner. The wrapper can continue to capture successful requests,
151
172
  metrics, and trace context.
152
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
+
153
176
  ## App Router Route Handler
154
177
 
155
178
  ```js
@@ -245,7 +268,7 @@ import {
245
268
  const client = createLogBrewNextBrowserClient({
246
269
  clientKey: "LOGBREW_CLIENT_KEY",
247
270
  sdkName: "my-next-app",
248
- sdkVersion: "0.1.11"
271
+ sdkVersion: "0.1.13"
249
272
  });
250
273
 
251
274
  const routePatterns = [
@@ -322,7 +345,7 @@ import { createLogBrewNextClient } from "@logbrew/next";
322
345
  const client = createLogBrewNextClient({
323
346
  serverApiKey: "LOGBREW_SERVER_API_KEY",
324
347
  sdkName: "my-next-app",
325
- sdkVersion: "0.1.11"
348
+ sdkVersion: "0.1.13"
326
349
  });
327
350
  ```
328
351
 
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.11",
25
+ sdkVersion = "0.1.13",
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.11",
25
+ sdkVersion = "0.1.13",
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.11",
28
+ sdkVersion: options.sdkVersion ?? "0.1.13",
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.11") {
27
+ if (!event || event.attributes.metadata.routeTemplate !== "/projects/[projectId]/settings" || event.attributes.metadata.operation !== "browser.navigation" || payload.sdk.version !== "0.1.13") {
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.11",
15
+ sdkVersion: "0.1.13",
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.11",
15
+ sdkVersion: "0.1.13",
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.11",
26
+ sdkVersion = "0.1.13",
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 clientErrorStatus = options.captureClientErrors === true ? undefined : nextClientErrorStatus(error);
98
+ if (clientErrorStatus === undefined) {
99
+ await recordRouteError(options, error, { request, context, client, owned, transport, trace });
100
+ } else {
101
+ const response = new Response(null, { status: clientErrorStatus });
102
+ await captureRouteResponse(options, { request, response, context, client, owned, transport, startedAt, trace });
103
+ }
98
104
  throw error;
99
105
  }
100
106
  });
@@ -285,6 +291,16 @@ function createRouteHelpers(client, transport, trace, request) {
285
291
  };
286
292
  }
287
293
 
294
+ // notFound(), forbidden(), and unauthorized() throw these digests, and Next.js answers with that 4xx.
295
+ function nextClientErrorStatus(error) {
296
+ const digest = error?.digest;
297
+ if (digest === "NEXT_NOT_FOUND") {
298
+ return 404;
299
+ }
300
+ const match = typeof digest === "string" ? /^NEXT_HTTP_ERROR_FALLBACK;(4\d\d)$/u.exec(digest) : null;
301
+ return match ? Number(match[1]) : undefined;
302
+ }
303
+
288
304
  function ensureResponse(response) {
289
305
  if (!(response instanceof Response)) {
290
306
  throw new SdkError("route_handler_error", "Next.js route handler must return a Response");
@@ -307,7 +323,7 @@ async function notifyFailure(options, error, context) {
307
323
  }
308
324
  }
309
325
 
310
- async function captureRouteSuccess(options, runtime) {
326
+ async function captureRouteResponse(options, runtime) {
311
327
  const { request, response, context, client, startedAt, trace } = runtime;
312
328
  try {
313
329
  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. */
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. */
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.11",
3
+ "version": "0.1.13",
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",