@logbrew/next 0.1.12 → 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 +9 -4
- package/client.cjs +1 -1
- package/client.js +1 -1
- 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 +22 -6
- package/index.d.cts +2 -0
- package/index.d.ts +2 -0
- package/package.json +2 -2
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
|
|
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.
|
|
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,8 @@ 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
|
+
|
|
171
176
|
## App Router Route Handler
|
|
172
177
|
|
|
173
178
|
```js
|
|
@@ -263,7 +268,7 @@ import {
|
|
|
263
268
|
const client = createLogBrewNextBrowserClient({
|
|
264
269
|
clientKey: "LOGBREW_CLIENT_KEY",
|
|
265
270
|
sdkName: "my-next-app",
|
|
266
|
-
sdkVersion: "0.1.
|
|
271
|
+
sdkVersion: "0.1.13"
|
|
267
272
|
});
|
|
268
273
|
|
|
269
274
|
const routePatterns = [
|
|
@@ -340,7 +345,7 @@ import { createLogBrewNextClient } from "@logbrew/next";
|
|
|
340
345
|
const client = createLogBrewNextClient({
|
|
341
346
|
serverApiKey: "LOGBREW_SERVER_API_KEY",
|
|
342
347
|
sdkName: "my-next-app",
|
|
343
|
-
sdkVersion: "0.1.
|
|
348
|
+
sdkVersion: "0.1.13"
|
|
344
349
|
});
|
|
345
350
|
```
|
|
346
351
|
|
package/client.cjs
CHANGED
package/client.js
CHANGED
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.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.
|
|
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
|
|
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.
|
|
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
|
|
94
|
+
await captureRouteResponse(options, { request, response, context, client, owned, transport, startedAt, trace });
|
|
95
95
|
return response;
|
|
96
96
|
} catch (error) {
|
|
97
|
-
|
|
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
|
|
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.
|
|
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.
|
|
96
|
+
"@logbrew/node": "^0.1.24",
|
|
97
97
|
"@logbrew/sdk": "^0.1.32",
|
|
98
98
|
"next": ">=15",
|
|
99
99
|
"react": ">=18",
|