@belvador/tanstack-start 0.1.0 → 0.3.0

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
@@ -42,13 +42,69 @@ export const startInstance = createStart(() => ({
42
42
  ```
43
43
 
44
44
  Server functions and server routes are reported with their server stack; redirects,
45
- `notFound()` and errors with a status below 500 are not. Needs `nodejs_compat` and the
46
- `BELVADOR_DSN` secret on the server.
45
+ `notFound()`, errors with a status below 500 and requests the visitor cancelled (`AbortError`,
46
+ or a failure after the client disconnected — `captureAborted: true` reports them) are not.
47
+ Needs `nodejs_compat` and the `BELVADOR_DSN` secret on the server.
48
+
49
+ ## Monitor background work
50
+
51
+ Errors alone cannot tell you that a job never ran. Wrap scheduled and queued work in
52
+ `withMonitor` (Sentry-compatible check-ins): Belvador sees each run start and finish, and
53
+ opens an incident when a run fails, times out or never happens.
54
+
55
+ ```ts
56
+ // src/routes/api/jobs/nightly-invoices.ts — called by your scheduler
57
+ import { createFileRoute } from "@tanstack/react-router";
58
+ import { withMonitor } from "@belvador/tanstack-start/server";
59
+
60
+ export const Route = createFileRoute("/api/jobs/nightly-invoices")({
61
+ server: {
62
+ handlers: {
63
+ POST: async () => {
64
+ const sent = await withMonitor(
65
+ "nightly-invoices",
66
+ async (run) => {
67
+ const due = await loadDueInvoices();
68
+ if (due.length === 0) run.skip("nothing_due");
69
+ return sendInvoices(due);
70
+ },
71
+ { schedule: { type: "crontab", value: "0 2 * * *" }, timezone: "Europe/Berlin" },
72
+ );
73
+ return Response.json({ sent });
74
+ },
75
+ },
76
+ },
77
+ });
78
+ ```
79
+
80
+ Your function's result and errors come back unchanged (a synchronous function stays
81
+ synchronous); an error is also reported as a normal issue with the monitor's slug. For queue
82
+ consumers pass `runId` (your message id), `attempt` and `willRetry` so retries count as one
83
+ run. `captureCheckIn()` and `heartbeat()` cover manual start/finish and "still alive" checks.
84
+ Check-ins are sent only from server code. See https://belvador.dev/docs/monitors/setup
85
+
86
+ ## Link requests with one trace
87
+
88
+ Off by default. `tracePropagation: { targets: [/^\/api\//, "https://api.example.com"] }` (in
89
+ `init` and in the `withBelvador` options) adds `traceparent` and `sentry-trace` headers to
90
+ `fetch` calls to those URLs, so the browser error, the server error and the job's check-ins
91
+ behind one request share a trace id. An incoming
92
+ `traceparent` (or `sentry-trace`) is continued. No spans or transactions are sent; `baggage`
93
+ only with `baggage: true`. See https://belvador.dev/docs/sdk/tracing
94
+
95
+ ## Check the connection
96
+
97
+ "No errors" is not proof that errors arrive. Call `verifyIntegration()` once from the browser
98
+ (`@belvador/tanstack-start/client`) and once from a server route (`@belvador/tanstack-start/server`):
99
+ each sends one marked test error (never an issue), reads it back and resolves to
100
+ `{ outcome: "verified" | "problem" | "unconfirmed", checks, docsUrl, … }`. It never throws. See
101
+ https://belvador.dev/docs/sdk/verify
47
102
 
48
103
  ## What it sends
49
104
 
50
- Errors only (exceptions, messages, breadcrumbs you turn on, attachments if you enable them).
51
- No tracing, session replay, logs or profiling — those items are dropped inside your app.
105
+ Errors (exceptions, messages, breadcrumbs you turn on, attachments if you enable them) and
106
+ the job check-ins you send with `withMonitor`. No spans, session replay, logs or profiling —
107
+ those items are dropped inside your app.
52
108
 
53
109
  Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
54
110
  headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ReactOptions } from "@belvador/react";
2
- export { ErrorBoundary, SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, type ErrorBoundaryProps, type ReactOptions, } from "@belvador/react";
2
+ export { ErrorBoundary, SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, verifyIntegration, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type ErrorBoundaryProps, type ReactOptions, type VerificationResult, type VerifyOptions, } from "@belvador/react";
3
3
  export { belvadorOnCatch } from "./index.js";
4
4
  /** Starts error tracking in the browser; returns whether it is running. Never throws. */
5
5
  export declare function init(options: ReactOptions): boolean;
package/dist/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { initReact } from "@belvador/react/internal";
2
- export { ErrorBoundary, SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, } from "@belvador/react";
2
+ export { ErrorBoundary, SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, reactErrorHandler, setContext, setTag, setTags, setUser, withErrorBoundary, withScope, verifyIntegration, } from "@belvador/react";
3
3
  export { belvadorOnCatch } from "./index.js";
4
4
  /** Starts error tracking in the browser; returns whether it is running. Never throws. */
5
5
  export function init(options) {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export { SDK_VERSION } from "@belvador/core";
2
2
  /**
3
3
  * Control flow, not failures: redirects, not-found, thrown Responses and
4
- * anything carrying an HTTP status below 500 are never reported.
4
+ * anything carrying an HTTP status below 500 (499 "client closed" included) are
5
+ * never reported. Client cancellations (AbortError, or a failure after the visitor
6
+ * disconnected) are dropped by the SDK itself unless `captureAborted` is on.
5
7
  */
6
8
  export declare function isExpectedError(error: unknown): boolean;
7
9
  /**
package/dist/index.js CHANGED
@@ -3,11 +3,13 @@
3
3
  // bundles: it only calls the runtime-neutral capture API.
4
4
  import { isNotFound, isRedirect } from "@tanstack/react-router";
5
5
  import { createMiddleware } from "@tanstack/react-start";
6
- import { captureException } from "@belvador/core";
6
+ import { captureException, markHooked, noteClientAbort } from "@belvador/core";
7
7
  export { SDK_VERSION } from "@belvador/core";
8
8
  /**
9
9
  * Control flow, not failures: redirects, not-found, thrown Responses and
10
- * anything carrying an HTTP status below 500 are never reported.
10
+ * anything carrying an HTTP status below 500 (499 "client closed" included) are
11
+ * never reported. Client cancellations (AbortError, or a failure after the visitor
12
+ * disconnected) are dropped by the SDK itself unless `captureAborted` is on.
11
13
  */
12
14
  export function isExpectedError(error) {
13
15
  try {
@@ -40,21 +42,25 @@ function report(error, kind) {
40
42
  * `requestMiddleware` (closest to the handler) so it sees errors before an
41
43
  * error-page middleware turns them into a response.
42
44
  */
43
- export const belvadorRequestMiddleware = createMiddleware().server(async ({ next }) => {
45
+ export const belvadorRequestMiddleware = createMiddleware().server(async ({ next, request }) => {
46
+ markHooked("middleware");
44
47
  try {
45
48
  return await next();
46
49
  }
47
50
  catch (error) {
51
+ noteClientAbort(error, request?.signal);
48
52
  report(error, "request");
49
53
  throw error;
50
54
  }
51
55
  });
52
56
  /** Server-function middleware: same contract, put it LAST in `functionMiddleware`. */
53
- export const belvadorFunctionMiddleware = createMiddleware({ type: "function" }).server(async ({ next }) => {
57
+ export const belvadorFunctionMiddleware = createMiddleware({ type: "function" }).server(async ({ next, signal }) => {
58
+ markHooked("middleware");
54
59
  try {
55
60
  return await next();
56
61
  }
57
62
  catch (error) {
63
+ noteClientAbort(error, signal);
58
64
  report(error, "server_function");
59
65
  throw error;
60
66
  }
package/dist/server.d.ts CHANGED
@@ -1,7 +1,16 @@
1
1
  import { type WorkerOptions } from "@belvador/cloudflare";
2
- export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, setContext, setTag, setTags, setUser, withScope, type BelvadorEnv, type WorkerOptions, } from "@belvador/cloudflare";
2
+ import { type VerificationResult, type VerifyOptions } from "@belvador/core";
3
+ export { SDK_VERSION, addBreadcrumb, captureCheckIn, captureException, captureMessage, flush, heartbeat, withMonitor, getDiagnostics, setContext, setTag, setTags, setUser, withScope, type BelvadorEnv, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type CheckInInput, type MonitorConfigInput, type MonitorSchedule, type RunHandle, type TracePropagationOptions, type WithMonitorOptions, type WorkerOptions, } from "@belvador/cloudflare";
4
+ export type { VerificationResult, VerifyOptions } from "@belvador/core";
3
5
  /**
4
6
  * `export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), { fetch })`:
5
7
  * one client per request, errors reported and re-thrown, the response untouched.
6
8
  */
7
9
  export declare function withBelvador<Env, H>(optionsCallback: (env: Env) => WorkerOptions | undefined, handler: H): H;
10
+ /**
11
+ * Proves the server reports to Belvador. Call it inside a server function or server
12
+ * route (for example a temporary `/api/verify-belvador` route): it checks that the call
13
+ * runs inside belvadorRequestMiddleware/belvadorFunctionMiddleware, sends one
14
+ * verification error and reads it back. Never automatic; always resolves.
15
+ */
16
+ export declare function verifyIntegration(options?: VerifyOptions): Promise<VerificationResult>;
package/dist/server.js CHANGED
@@ -1,7 +1,8 @@
1
1
  // @belvador/tanstack-start/server — Workers side. Wrap the default export of
2
2
  // src/server.ts; add the middleware from "@belvador/tanstack-start" to src/start.ts.
3
3
  import { wrapHandler } from "@belvador/cloudflare";
4
- export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, setContext, setTag, setTags, setUser, withScope, } from "@belvador/cloudflare";
4
+ import { currentHooks, runVerification, } from "@belvador/core";
5
+ export { SDK_VERSION, addBreadcrumb, captureCheckIn, captureException, captureMessage, flush, heartbeat, withMonitor, getDiagnostics, setContext, setTag, setTags, setUser, withScope, } from "@belvador/cloudflare";
5
6
  /**
6
7
  * `export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), { fetch })`:
7
8
  * one client per request, errors reported and re-thrown, the response untouched.
@@ -9,3 +10,12 @@ export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, flush, se
9
10
  export function withBelvador(optionsCallback, handler) {
10
11
  return wrapHandler(optionsCallback, handler, "tanstack-start");
11
12
  }
13
+ /**
14
+ * Proves the server reports to Belvador. Call it inside a server function or server
15
+ * route (for example a temporary `/api/verify-belvador` route): it checks that the call
16
+ * runs inside belvadorRequestMiddleware/belvadorFunctionMiddleware, sends one
17
+ * verification error and reads it back. Never automatic; always resolves.
18
+ */
19
+ export function verifyIntegration(options) {
20
+ return runVerification({ surface: "server", hook: () => ({ ok: currentHooks().has("middleware") }) }, options);
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@belvador/tanstack-start",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Belvador error tracking for TanStack Start on Cloudflare Workers: client, server entry and middleware.",
5
5
  "license": "MIT",
6
6
  "author": "Belvador (https://belvador.dev)",
@@ -42,9 +42,9 @@
42
42
  "node": ">=18"
43
43
  },
44
44
  "dependencies": {
45
- "@belvador/cloudflare": "0.1.0",
46
- "@belvador/core": "0.1.0",
47
- "@belvador/react": "0.1.0"
45
+ "@belvador/cloudflare": "0.3.0",
46
+ "@belvador/core": "0.3.0",
47
+ "@belvador/react": "0.3.0"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public",