@logbrew/next 0.1.18 → 0.1.19

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
@@ -121,6 +121,8 @@ export default withLogBrewNextReleaseArtifacts(
121
121
 
122
122
  The helper defaults minified URLs to `app:///_next/static/chunks/...`. Use `minifiedPathPrefix`, `manifestPath`, `repositoryUrl`, `commitSha`, or `stripSourcePrefix` when your deploy needs explicit paths or source-link metadata. Set `LOGBREW_RELEASE_ARTIFACT_TOKEN` in the build environment to a dedicated release-artifact token. Use `tokenEnv` for a different CI variable, or `dryRun: true` to prepare the complete build output without a network request. Existing `compiler.runAfterProductionCompile` work runs first. Upload is disabled when `upload` is omitted, and any unsafe preparation or upload result fails the production build without exposing response text or secret values.
123
123
 
124
+ The helper uploads every chunk in `.next/static/chunks` that has a source map. It skips a chunk that has no `sourceMappingURL` comment and no `.map` file next to it, such as the polyfill chunk that Turbopack builds without a source map, lists it in the manifest's `skippedSources`, and counts it in the upload summary. A chunk that names a source map that is missing or empty still fails the build.
125
+
124
126
  ## App Router Request Errors
125
127
 
126
128
  Use Next.js's root `instrumentation.ts` file when you want one server error hook
@@ -270,7 +272,7 @@ import {
270
272
  const client = createLogBrewNextBrowserClient({
271
273
  clientKey: "LOGBREW_CLIENT_KEY",
272
274
  sdkName: "my-next-app",
273
- sdkVersion: "0.1.18"
275
+ sdkVersion: "0.1.19"
274
276
  });
275
277
 
276
278
  const routePatterns = [
@@ -339,6 +341,25 @@ query, status), and route changes. Requests to the LogBrew endpoint are
339
341
  skipped. Pass `breadcrumbs: false` to turn them off. `uninstall()` removes the
340
342
  listeners and puts back every patched method.
341
343
 
344
+ Each of these issues carries the route template of the latest page view that
345
+ `useLogBrewNextNavigation` recorded, never the concrete path. An error before
346
+ the first page view, such as a hydration error, has no page view yet. To name
347
+ its route too, pass `routeTemplate`, a function that maps the current path to
348
+ its route template:
349
+
350
+ ```tsx
351
+ import { createNextRouteTemplate, installLogBrewNextClientErrorCapture } from "@logbrew/next/client";
352
+
353
+ installLogBrewNextClientErrorCapture({
354
+ client: logbrew,
355
+ routeTemplate: (pathname) =>
356
+ createNextRouteTemplate({ pathname, routePatterns: ["/projects/[projectId]", "/settings"] })
357
+ });
358
+ ```
359
+
360
+ When the function returns `undefined` or throws, the issue keeps the route of
361
+ the latest page view.
362
+
342
363
  The same call sends the page's Web Vitals as histogram metrics when the page is
343
364
  first hidden: `browser.web_vital.lcp`, `browser.web_vital.inp`,
344
365
  `browser.web_vital.fcp`, and `browser.web_vital.ttfb` in milliseconds, and
@@ -356,7 +377,7 @@ import { createLogBrewNextClient } from "@logbrew/next";
356
377
  const client = createLogBrewNextClient({
357
378
  serverApiKey: "LOGBREW_SERVER_API_KEY",
358
379
  sdkName: "my-next-app",
359
- sdkVersion: "0.1.18"
380
+ sdkVersion: "0.1.19"
360
381
  });
361
382
  ```
362
383
 
package/client.cjs CHANGED
@@ -15,6 +15,8 @@ const DEFAULT_BROWSER_DELIVERY_INTERVAL_MS = 1000;
15
15
  const clientEndpoints = new WeakMap();
16
16
  // The first route template each client's navigation hook saw: the route the page loaded on.
17
17
  const landingRouteTemplates = new WeakMap();
18
+ // The route template of each client's latest page view: the route a later browser error happened on.
19
+ const currentRouteTemplates = new WeakMap();
18
20
  // Good and poor limits from https://web.dev/articles/vitals.
19
21
  const WEB_VITALS = {
20
22
  cls: { description: "Cumulative Layout Shift of one page load.", good: 0.1, poor: 0.25, unit: "1" },
@@ -32,7 +34,7 @@ function createLogBrewNextBrowserClient({
32
34
  endpoint = DEFAULT_ENDPOINT,
33
35
  eventFilter,
34
36
  sdkName = "logbrew-next-client",
35
- sdkVersion = "0.1.18",
37
+ sdkVersion = "0.1.19",
36
38
  maxQueueSize,
37
39
  maxRetries = 2,
38
40
  onEventDropped,
@@ -82,8 +84,9 @@ function captureNextClientError(client, error, { digest, routeTemplate, flush =
82
84
 
83
85
  // Report uncaught browser errors and unhandled rejections, and flush queued events on pagehide.
84
86
  // Console, fetch, XHR, and route-change breadcrumbs ride along with each issue; breadcrumbs: false turns them off.
87
+ // Each issue carries the route template of the latest page view, or the one routeTemplate(pathname) returns.
85
88
  // Web Vitals go out as metrics when the page is first hidden; webVitals: false turns them off.
86
- function installLogBrewNextClientErrorCapture({ breadcrumbs = true, browserWindow = globalThis.window, client, webVitals = true } = {}) {
89
+ function installLogBrewNextClientErrorCapture({ breadcrumbs = true, browserWindow = globalThis.window, client, routeTemplate, webVitals = true } = {}) {
87
90
  if (!client || !browserWindow || typeof browserWindow.addEventListener !== "function") {
88
91
  throw new SdkError("configuration_error", "installLogBrewNextClientErrorCapture requires a client and a browser window");
89
92
  }
@@ -94,7 +97,10 @@ function installLogBrewNextClientErrorCapture({ breadcrumbs = true, browserWindo
94
97
  mechanism,
95
98
  runtime: "browser",
96
99
  source: mechanism,
97
- metadata: { framework: "nextjs" }
100
+ metadata: compactMetadata({
101
+ framework: "nextjs",
102
+ routeTemplate: browserErrorRouteTemplate(client, browserWindow, routeTemplate)
103
+ })
98
104
  }));
99
105
  } catch {
100
106
  // Capture failures never reach the page.
@@ -369,6 +375,7 @@ function captureNextNavigation(client, input = {}) {
369
375
  return undefined;
370
376
  }
371
377
  client.span(event.id, event.timestamp, event.attributes);
378
+ currentRouteTemplates.set(client, event.attributes.metadata.routeTemplate);
372
379
  if (!landingRouteTemplates.has(client)) {
373
380
  landingRouteTemplates.set(client, event.attributes.metadata.routeTemplate);
374
381
  }
@@ -411,6 +418,23 @@ function useLogBrewNextNavigation(options = {}) {
411
418
  });
412
419
  }
413
420
 
421
+ // The app's resolver reads the current path, so it also names errors raised before the first
422
+ // page view, such as hydration errors. Otherwise the latest page view names the route.
423
+ function browserErrorRouteTemplate(client, browserWindow, resolveRouteTemplate) {
424
+ if (typeof resolveRouteTemplate === "function") {
425
+ try {
426
+ const pathname = pathnameOnly(browserWindow.location?.pathname);
427
+ const resolved = pathname ? normalizeRouteTemplate(resolveRouteTemplate(pathname)) : undefined;
428
+ if (resolved) {
429
+ return resolved;
430
+ }
431
+ } catch {
432
+ // A failing resolver never stops the error report.
433
+ }
434
+ }
435
+ return currentRouteTemplates.get(client);
436
+ }
437
+
414
438
  function compactMetadata(metadata) {
415
439
  const compacted = {};
416
440
  for (const [key, value] of Object.entries(metadata)) {
package/client.d.cts CHANGED
@@ -49,6 +49,11 @@ export declare function installLogBrewNextClientErrorCapture(options: {
49
49
  browserWindow?: Window;
50
50
  /** Console, fetch, XHR, and route-change breadcrumbs on each issue. Defaults to true. */
51
51
  breadcrumbs?: boolean;
52
+ /**
53
+ * Returns the route template for the page's current path, such as `/[locale]/products/[slug]`, or undefined.
54
+ * Names errors raised before the first page view, such as hydration errors. Return a template, never the concrete path.
55
+ */
56
+ routeTemplate?: (pathname: string) => string | undefined;
52
57
  /** LCP, INP, CLS, FCP, and TTFB as `browser.web_vital.*` metrics when the page is first hidden. Defaults to true. */
53
58
  webVitals?: boolean;
54
59
  }): { uninstall(): void };
package/client.d.ts CHANGED
@@ -49,6 +49,11 @@ export declare function installLogBrewNextClientErrorCapture(options: {
49
49
  browserWindow?: Window;
50
50
  /** Console, fetch, XHR, and route-change breadcrumbs on each issue. Defaults to true. */
51
51
  breadcrumbs?: boolean;
52
+ /**
53
+ * Returns the route template for the page's current path, such as `/[locale]/products/[slug]`, or undefined.
54
+ * Names errors raised before the first page view, such as hydration errors. Return a template, never the concrete path.
55
+ */
56
+ routeTemplate?: (pathname: string) => string | undefined;
52
57
  /** LCP, INP, CLS, FCP, and TTFB as `browser.web_vital.*` metrics when the page is first hidden. Defaults to true. */
53
58
  webVitals?: boolean;
54
59
  }): { uninstall(): void };
package/client.js CHANGED
@@ -15,6 +15,8 @@ const DEFAULT_BROWSER_DELIVERY_INTERVAL_MS = 1000;
15
15
  const clientEndpoints = new WeakMap();
16
16
  // The first route template each client's navigation hook saw: the route the page loaded on.
17
17
  const landingRouteTemplates = new WeakMap();
18
+ // The route template of each client's latest page view: the route a later browser error happened on.
19
+ const currentRouteTemplates = new WeakMap();
18
20
  // Good and poor limits from https://web.dev/articles/vitals.
19
21
  const WEB_VITALS = {
20
22
  cls: { description: "Cumulative Layout Shift of one page load.", good: 0.1, poor: 0.25, unit: "1" },
@@ -32,7 +34,7 @@ export function createLogBrewNextBrowserClient({
32
34
  endpoint = DEFAULT_ENDPOINT,
33
35
  eventFilter,
34
36
  sdkName = "logbrew-next-client",
35
- sdkVersion = "0.1.18",
37
+ sdkVersion = "0.1.19",
36
38
  maxQueueSize,
37
39
  maxRetries = 2,
38
40
  onEventDropped,
@@ -82,8 +84,9 @@ export function captureNextClientError(client, error, { digest, routeTemplate, f
82
84
 
83
85
  // Report uncaught browser errors and unhandled rejections, and flush queued events on pagehide.
84
86
  // Console, fetch, XHR, and route-change breadcrumbs ride along with each issue; breadcrumbs: false turns them off.
87
+ // Each issue carries the route template of the latest page view, or the one routeTemplate(pathname) returns.
85
88
  // Web Vitals go out as metrics when the page is first hidden; webVitals: false turns them off.
86
- export function installLogBrewNextClientErrorCapture({ breadcrumbs = true, browserWindow = globalThis.window, client, webVitals = true } = {}) {
89
+ export function installLogBrewNextClientErrorCapture({ breadcrumbs = true, browserWindow = globalThis.window, client, routeTemplate, webVitals = true } = {}) {
87
90
  if (!client || !browserWindow || typeof browserWindow.addEventListener !== "function") {
88
91
  throw new SdkError("configuration_error", "installLogBrewNextClientErrorCapture requires a client and a browser window");
89
92
  }
@@ -94,7 +97,10 @@ export function installLogBrewNextClientErrorCapture({ breadcrumbs = true, brows
94
97
  mechanism,
95
98
  runtime: "browser",
96
99
  source: mechanism,
97
- metadata: { framework: "nextjs" }
100
+ metadata: compactMetadata({
101
+ framework: "nextjs",
102
+ routeTemplate: browserErrorRouteTemplate(client, browserWindow, routeTemplate)
103
+ })
98
104
  }));
99
105
  } catch {
100
106
  // Capture failures never reach the page.
@@ -369,6 +375,7 @@ export function captureNextNavigation(client, input = {}) {
369
375
  return undefined;
370
376
  }
371
377
  client.span(event.id, event.timestamp, event.attributes);
378
+ currentRouteTemplates.set(client, event.attributes.metadata.routeTemplate);
372
379
  if (!landingRouteTemplates.has(client)) {
373
380
  landingRouteTemplates.set(client, event.attributes.metadata.routeTemplate);
374
381
  }
@@ -411,6 +418,23 @@ export function useLogBrewNextNavigation(options = {}) {
411
418
  });
412
419
  }
413
420
 
421
+ // The app's resolver reads the current path, so it also names errors raised before the first
422
+ // page view, such as hydration errors. Otherwise the latest page view names the route.
423
+ function browserErrorRouteTemplate(client, browserWindow, resolveRouteTemplate) {
424
+ if (typeof resolveRouteTemplate === "function") {
425
+ try {
426
+ const pathname = pathnameOnly(browserWindow.location?.pathname);
427
+ const resolved = pathname ? normalizeRouteTemplate(resolveRouteTemplate(pathname)) : undefined;
428
+ if (resolved) {
429
+ return resolved;
430
+ }
431
+ } catch {
432
+ // A failing resolver never stops the error report.
433
+ }
434
+ }
435
+ return currentRouteTemplates.get(client);
436
+ }
437
+
414
438
  function compactMetadata(metadata) {
415
439
  const compacted = {};
416
440
  for (const [key, value] of Object.entries(metadata)) {
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.18",
28
+ sdkVersion: options.sdkVersion ?? "0.1.19",
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.18") {
27
+ if (!event || event.attributes.metadata.routeTemplate !== "/projects/[projectId]/settings" || event.attributes.metadata.operation !== "browser.navigation" || payload.sdk.version !== "0.1.19") {
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.18",
15
+ sdkVersion: "0.1.19",
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.18",
15
+ sdkVersion: "0.1.19",
16
16
  maxRetries: 1,
17
17
  transport
18
18
  }
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.18",
26
+ sdkVersion = "0.1.19",
27
27
  maxRetries = 2
28
28
  } = {}) {
29
29
  const authKey = serverApiKey ?? apiKey ?? readEnvServerApiKey() ?? readEnvApiKey();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/next",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Next.js App Router helpers for the public LogBrew JavaScript SDK.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",