@belvador/cloudflare 0.2.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 +37 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,8 +30,9 @@ response (status, headers, streamed body) is returned unchanged and sending fini
|
|
|
30
30
|
|
|
31
31
|
## What it sends
|
|
32
32
|
|
|
33
|
-
Errors
|
|
34
|
-
No
|
|
33
|
+
Errors (exceptions, messages, breadcrumbs you turn on, attachments if you enable them) and
|
|
34
|
+
the job check-ins you send with `withMonitor`. No spans, session replay, logs or profiling —
|
|
35
|
+
those items are dropped inside your app.
|
|
35
36
|
|
|
36
37
|
Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
|
|
37
38
|
headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
|
|
@@ -44,6 +45,40 @@ each attempt times out after 10 s, failed sends retry at most 5 times, `429` rat
|
|
|
44
45
|
respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
|
|
45
46
|
Every public function catches its own errors.
|
|
46
47
|
|
|
48
|
+
## Monitor background work
|
|
49
|
+
|
|
50
|
+
Errors alone cannot tell you that a job never ran. Wrap scheduled and queued work in
|
|
51
|
+
`withMonitor` (Sentry-compatible check-ins): Belvador sees each run start and finish, and
|
|
52
|
+
opens an incident when a run fails, times out or never happens.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { withMonitor } from "@belvador/cloudflare";
|
|
56
|
+
|
|
57
|
+
export default withBelvador((env) => ({ release: env.BELVADOR_RELEASE }), {
|
|
58
|
+
async scheduled(controller, env, ctx) {
|
|
59
|
+
await withMonitor("nightly-invoices", async (run) => {
|
|
60
|
+
const due = await loadDueInvoices(env);
|
|
61
|
+
if (due.length === 0) return run.skip("nothing_due");
|
|
62
|
+
await sendInvoices(env, due);
|
|
63
|
+
}, { schedule: { type: "crontab", value: "0 2 * * *" }, timezone: "Europe/Berlin" });
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Your function's result and errors come back unchanged (a synchronous function stays
|
|
69
|
+
synchronous); an error is also reported as a normal issue with the monitor's slug. For queue
|
|
70
|
+
consumers pass `runId` (your message id), `attempt` and `willRetry` so retries count as one
|
|
71
|
+
run. `captureCheckIn()` and `heartbeat()` cover manual start/finish and "still alive" checks.
|
|
72
|
+
Check-ins are sent only from server code. See https://belvador.dev/docs/monitors/setup
|
|
73
|
+
|
|
74
|
+
## Link requests with one trace
|
|
75
|
+
|
|
76
|
+
Off by default. `tracePropagation: { targets: ["https://api.example.com"] }` adds
|
|
77
|
+
`traceparent` and `sentry-trace` headers to `fetch` calls to those URLs, so an error in the
|
|
78
|
+
called service and its job check-ins show up with the same trace id. An incoming
|
|
79
|
+
`traceparent` (or `sentry-trace`) is continued. No spans or transactions are sent; `baggage`
|
|
80
|
+
only with `baggage: true`. See https://belvador.dev/docs/sdk/tracing
|
|
81
|
+
|
|
47
82
|
## Check the connection
|
|
48
83
|
|
|
49
84
|
"No errors" is not proof that errors arrive. Call `verifyIntegration()` from `@belvador/cloudflare` inside a request handled by `withBelvador`:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CloudflareOptions as EngineCloudflareOptions } from "@sentry/cloudflare";
|
|
2
2
|
import { type BelvadorOptions, type VerificationResult, type VerifyOptions } from "@belvador/core";
|
|
3
|
-
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, type BelvadorBreadcrumb, type BelvadorEvent, type BelvadorEventHint, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type Scope, type SeverityLevel, type VerificationResult, type VerifyOptions, } from "@belvador/core";
|
|
3
|
+
export { SDK_VERSION, addBreadcrumb, captureCheckIn, captureException, captureMessage, close, flush, heartbeat, withMonitor, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, type BelvadorBreadcrumb, type BelvadorEvent, type BelvadorEventHint, type CheckInInput, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type MonitorConfigInput, type MonitorSchedule, type RunHandle, type Scope, type SeverityLevel, type TracePropagationOptions, type VerificationResult, type VerifyOptions, type WithMonitorOptions, } from "@belvador/core";
|
|
4
4
|
export type WorkerOptions = Omit<BelvadorOptions, "dsn"> & {
|
|
5
5
|
/** Defaults to the BELVADOR_DSN binding. */
|
|
6
6
|
dsn?: string;
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// privacy and sending rules. Needs the `nodejs_compat` (or `nodejs_als`)
|
|
4
4
|
// compatibility flag so every request gets its own scope.
|
|
5
5
|
import { consoleIntegration, dedupeIntegration, eventFiltersIntegration, fetchIntegration, linkedErrorsIntegration, requestDataIntegration, withSentry, } from "@sentry/cloudflare";
|
|
6
|
-
import { buildEngineOptions, currentHooks, markHooked, noteClientAbort, runVerification, } from "@belvador/core";
|
|
7
|
-
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, } from "@belvador/core";
|
|
6
|
+
import { TRACE_OPTION, buildEngineOptions, currentHooks, installTracePropagation, markHooked, noteClientAbort, runVerification, withIncomingTraceparent, } from "@belvador/core";
|
|
7
|
+
export { SDK_VERSION, addBreadcrumb, captureCheckIn, captureException, captureMessage, close, flush, heartbeat, withMonitor, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, } from "@belvador/core";
|
|
8
8
|
function binding(env, name) {
|
|
9
9
|
if (env === null || typeof env !== "object")
|
|
10
10
|
return undefined;
|
|
@@ -76,8 +76,11 @@ export function workerEngineOptions(options, env, runtime = "cloudflare") {
|
|
|
76
76
|
];
|
|
77
77
|
if (o.instrument?.console === true)
|
|
78
78
|
integrations.push(consoleIntegration());
|
|
79
|
+
// Breadcrumbs only: trace headers come from Belvador's own hook, never the engine's.
|
|
79
80
|
if (o.instrument?.fetch === true)
|
|
80
|
-
integrations.push(fetchIntegration({ breadcrumbs: true }));
|
|
81
|
+
integrations.push(fetchIntegration({ breadcrumbs: true, shouldCreateSpanForRequest: () => false }));
|
|
82
|
+
if (base[TRACE_OPTION])
|
|
83
|
+
installTracePropagation();
|
|
81
84
|
return {
|
|
82
85
|
...base,
|
|
83
86
|
// 0, not undefined: an undefined value would let SENTRY_TRACES_SAMPLE_RATE turn tracing on.
|
|
@@ -140,7 +143,7 @@ function isThenable(value) {
|
|
|
140
143
|
}
|
|
141
144
|
/** Shared with @belvador/tanstack-start so its server events carry its own SDK name. */
|
|
142
145
|
export function wrapHandler(optionsCallback, handler, runtime) {
|
|
143
|
-
|
|
146
|
+
const wrapped = withSentry((env) => {
|
|
144
147
|
let options;
|
|
145
148
|
try {
|
|
146
149
|
options = optionsCallback(env);
|
|
@@ -150,6 +153,24 @@ export function wrapHandler(optionsCallback, handler, runtime) {
|
|
|
150
153
|
}
|
|
151
154
|
return workerEngineOptions(options, env, runtime);
|
|
152
155
|
}, marked(handler));
|
|
156
|
+
return incomingTrace(wrapped);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Spec 06 §5: an incoming W3C `traceparent` (without `sentry-trace`) continues the same
|
|
160
|
+
* trace; the request is otherwise passed through untouched.
|
|
161
|
+
*/
|
|
162
|
+
function incomingTrace(handler) {
|
|
163
|
+
if (handler === null || typeof handler !== "object")
|
|
164
|
+
return handler;
|
|
165
|
+
const fetch = handler["fetch"];
|
|
166
|
+
if (typeof fetch !== "function")
|
|
167
|
+
return handler;
|
|
168
|
+
return {
|
|
169
|
+
...handler,
|
|
170
|
+
fetch(request, ...rest) {
|
|
171
|
+
return fetch.call(handler, withIncomingTraceparent(request), ...rest);
|
|
172
|
+
},
|
|
173
|
+
};
|
|
153
174
|
}
|
|
154
175
|
/**
|
|
155
176
|
* Wraps a Worker's exported handler (fetch, scheduled, queue, email, tail):
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@belvador/cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Belvador error tracking for Cloudflare Workers: per-request scope, errors only, private by default.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Belvador (https://belvador.dev)",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"node": ">=18"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@belvador/core": "0.
|
|
35
|
+
"@belvador/core": "0.3.0",
|
|
36
36
|
"@sentry/cloudflare": "10.76.2"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|