ezlogs-nextjs 0.3.1 → 0.4.2
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 +149 -30
- package/bin/install-triggers.cjs +7 -2
- package/dist/actors/index.cjs +4 -4
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/actors/index.js +1 -1
- package/dist/{chunk-C5OSM557.js → chunk-FCFVIRQF.js} +7 -0
- package/dist/chunk-GI6BM4MR.js +443 -0
- package/dist/{chunk-YX2XPLOA.cjs → chunk-GMHOUAKD.cjs} +63 -34
- package/dist/{chunk-CU45I2WR.js → chunk-MHBS5FEP.js} +48 -20
- package/dist/chunk-MMLQXSSD.cjs +461 -0
- package/dist/{chunk-CE3R7DVB.js → chunk-NINIAL7M.js} +60 -384
- package/dist/{chunk-Y5NSHKWQ.cjs → chunk-NX4EL7BY.cjs} +57 -7
- package/dist/chunk-PS4U2GFJ.cjs +52 -0
- package/dist/chunk-R6IWVTX3.cjs +212 -0
- package/dist/{chunk-V5YNKKTG.cjs → chunk-TWTG5ILJ.cjs} +7 -0
- package/dist/chunk-U22T7QYY.js +200 -0
- package/dist/chunk-YMIGZYFH.js +48 -0
- package/dist/{chunk-WASXTDLW.cjs → chunk-YXZZNZG6.cjs} +71 -403
- package/dist/{chunk-DKRNNI4I.js → chunk-Z2TM3LGG.js} +53 -3
- package/dist/{configuration-OHLNivON.d.ts → configuration-CJ5yKVlP.d.cts} +14 -8
- package/dist/{configuration-OHLNivON.d.cts → configuration-CJ5yKVlP.d.ts} +14 -8
- package/dist/db/drizzle.cjs +5 -4
- package/dist/db/drizzle.js +3 -2
- package/dist/db/postgres-js.cjs +98 -0
- package/dist/db/postgres-js.d.cts +11 -0
- package/dist/db/postgres-js.d.ts +11 -0
- package/dist/db/postgres-js.js +95 -0
- package/dist/db/prisma.cjs +21 -20
- package/dist/db/prisma.d.cts +19 -2
- package/dist/db/prisma.d.ts +19 -2
- package/dist/db/prisma.js +6 -5
- package/dist/db/supabase.cjs +19 -12
- package/dist/db/supabase.d.cts +3 -2
- package/dist/db/supabase.d.ts +3 -2
- package/dist/db/supabase.js +11 -4
- package/dist/index.cjs +596 -165
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +492 -62
- package/dist/jobs/bullmq.cjs +63 -18
- package/dist/jobs/bullmq.d.cts +0 -4
- package/dist/jobs/bullmq.d.ts +0 -4
- package/dist/jobs/bullmq.js +59 -14
- package/dist/jobs/inngest.cjs +61 -24
- package/dist/jobs/inngest.d.cts +5 -1
- package/dist/jobs/inngest.d.ts +5 -1
- package/dist/jobs/inngest.js +55 -18
- package/dist/jobs/supabase-queues.cjs +17 -15
- package/dist/jobs/supabase-queues.d.cts +1 -1
- package/dist/jobs/supabase-queues.d.ts +1 -1
- package/dist/jobs/supabase-queues.js +15 -13
- package/dist/jobs/trigger.cjs +11 -12
- package/dist/jobs/trigger.d.cts +4 -3
- package/dist/jobs/trigger.d.ts +4 -3
- package/dist/jobs/trigger.js +7 -8
- package/dist/jobs/upstash-workflow.cjs +43 -35
- package/dist/jobs/upstash-workflow.d.cts +2 -8
- package/dist/jobs/upstash-workflow.d.ts +2 -8
- package/dist/jobs/upstash-workflow.js +38 -30
- package/dist/nextjs-plugin/index.cjs +39 -3
- package/dist/nextjs-plugin/index.d.cts +8 -1
- package/dist/nextjs-plugin/index.d.ts +8 -1
- package/dist/nextjs-plugin/index.js +39 -3
- package/dist/nextjs-plugin/loader.cjs +41 -3
- package/dist/nextjs-plugin/loader.d.cts +1 -0
- package/dist/nextjs-plugin/loader.d.ts +1 -0
- package/dist/nextjs-plugin/loader.js +42 -4
- package/dist/triggers/index.cjs +145 -92
- package/dist/triggers/index.d.cts +20 -5
- package/dist/triggers/index.d.ts +20 -5
- package/dist/triggers/index.js +125 -82
- package/package.json +11 -1
- package/sql/postgres/00_install.sql +1 -1
- package/dist/chunk-UQHEW6ER.js +0 -119
- package/dist/chunk-UWHYJH4M.cjs +0 -126
package/README.md
CHANGED
|
@@ -46,13 +46,15 @@ import { ezlogs } from "ezlogs-nextjs";
|
|
|
46
46
|
export async function register() {
|
|
47
47
|
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
48
48
|
ezlogs.init({
|
|
49
|
-
serverUrl: process.env.EZLOGS_SERVER_URL!,
|
|
50
49
|
projectToken: process.env.EZLOGS_PROJECT_TOKEN!,
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
```
|
|
55
54
|
|
|
55
|
+
`serverUrl` is optional: it defaults to `process.env.EZLOGS_SERVER_URL`
|
|
56
|
+
if set, otherwise `https://app.ezlogs.io`. Set it only if you self-host.
|
|
57
|
+
|
|
56
58
|
### 2. Wrap your Next config
|
|
57
59
|
|
|
58
60
|
`withEzlogsConfig(...)` is a transparent wrapper around your existing
|
|
@@ -73,15 +75,16 @@ const nextConfig: NextConfig = {
|
|
|
73
75
|
// ⬇ Your existing options (or leave empty {} on a fresh project).
|
|
74
76
|
};
|
|
75
77
|
|
|
76
|
-
export default withEzlogsConfig(
|
|
77
|
-
nextConfig as unknown as Parameters<typeof withEzlogsConfig>[0],
|
|
78
|
-
) as NextConfig;
|
|
78
|
+
export default withEzlogsConfig(nextConfig);
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
**`next.config.mjs`** (
|
|
81
|
+
**`next.config.mjs`** / ESM **`next.config.js`** (also type-checks
|
|
82
|
+
under `checkJs`, e.g. create-t3-app):
|
|
82
83
|
|
|
83
84
|
```js
|
|
84
85
|
import { withEzlogsConfig } from "ezlogs-nextjs/plugin";
|
|
86
|
+
|
|
87
|
+
/** @type {import("next").NextConfig} */
|
|
85
88
|
const nextConfig = { /* your options */ };
|
|
86
89
|
export default withEzlogsConfig(nextConfig);
|
|
87
90
|
```
|
|
@@ -93,17 +96,42 @@ const { withEzlogsConfig } = require("ezlogs-nextjs/plugin");
|
|
|
93
96
|
module.exports = withEzlogsConfig({ /* your options */ });
|
|
94
97
|
```
|
|
95
98
|
|
|
99
|
+
**Already have an `instrumentation.ts` or a wrapped config?** Keep
|
|
100
|
+
yours and add to it:
|
|
101
|
+
|
|
102
|
+
- `instrumentation.ts`: put the `ezlogs.init({...})` call inside your
|
|
103
|
+
existing `register()`, in the `NEXT_RUNTIME === "nodejs"` branch
|
|
104
|
+
(next to Sentry / OpenTelemetry setup; the order doesn't matter).
|
|
105
|
+
Export only one `register`.
|
|
106
|
+
- `next.config`: `withEzlogsConfig` returns the config it was given
|
|
107
|
+
(same type), so it composes with other wrappers in either order:
|
|
108
|
+
`export default withNextIntl(withEzlogsConfig(nextConfig))` or
|
|
109
|
+
`withSentryConfig(withEzlogsConfig(nextConfig), { ... })`.
|
|
110
|
+
|
|
96
111
|
### 3. Set env vars, restart, verify
|
|
97
112
|
|
|
98
113
|
```bash
|
|
99
114
|
# .env.local
|
|
100
|
-
EZLOGS_SERVER_URL=https://app.ezlogs.io
|
|
101
115
|
EZLOGS_PROJECT_TOKEN=ezl_your_api_key_here
|
|
102
116
|
```
|
|
103
117
|
|
|
104
|
-
Restart your dev server
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
Restart your dev server and look for this line in the terminal (one
|
|
119
|
+
per server process, at the default log level):
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
[ezlogs] capturing → app.ezlogs.io (key ezl_a1b2c3d4…)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
If `projectToken` is missing you get this instead:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
[ezlogs] not capturing: projectToken missing in ezlogs.init() (check EZLOGS_PROJECT_TOKEN)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Call an API route or submit a Server Action; events appear in your
|
|
132
|
+
EZLogs dashboard within a few seconds. Page views are only recorded when
|
|
133
|
+
the app has a `middleware.ts` (or `proxy.ts` on Next 16), so opening a
|
|
134
|
+
page is not a reliable check.
|
|
107
135
|
|
|
108
136
|
Sending to a local EZLogs server over plain `http://` (development)?
|
|
109
137
|
Events are still sent, but the agent warns on every start; pass
|
|
@@ -120,7 +148,8 @@ need one more step, depending on your stack:
|
|
|
120
148
|
| **Supabase** (supabase-js) | `npm i pg`, set `DATABASE_URL` to the Postgres connection string, run `npx ezlogs-nextjs install-triggers`. Nothing to wrap: the agent tags supabase-js requests and the trigger reads the tag. | Every write (`.from()`, `.rpc()`, bulk) with from→to diffs, linked to its request |
|
|
121
149
|
| **Prisma** on Postgres | triggers (as above) + `new PrismaClient().$extends(ezlogsPrisma())` (below) | Same |
|
|
122
150
|
| **Drizzle** (node-postgres) or raw **`pg`** | triggers (as above). With `DATABASE_URL` set, the agent patches `pg` itself; if your app loads its own copy of `pg` (monorepos), pass it: `ezlogs.init({ ..., patchDatabaseClient: pg })`. | Same |
|
|
123
|
-
| postgres.js
|
|
151
|
+
| **postgres.js** or **Drizzle** on postgres-js | triggers (as above) + `wrapPostgresJs(postgres(url))` (below) | Same |
|
|
152
|
+
| Neon HTTP, scripts | triggers (as above) | Writes show up as their own actions, not linked to the request |
|
|
124
153
|
| MySQL, SQLite, PlanetScale, no trigger access | a per-ORM adapter: `ezlogsPrisma()`, `ezlogsDrizzleLogger`, `wrapSupabase` ([docs/database.md](./docs/database.md)) | New values only, no before-values |
|
|
125
154
|
|
|
126
155
|
```bash
|
|
@@ -135,14 +164,25 @@ isn't installed locally, npx / bunx download whatever version is
|
|
|
135
164
|
published, and the CLI warns. They also download it when your
|
|
136
165
|
lockfile's bin entries predate 0.3.0 (seen with bun and a `file:`
|
|
137
166
|
dependency); the CLI then prints the command that runs your project's
|
|
138
|
-
copy: `node node_modules/ezlogs-nextjs/bin/install-triggers.cjs install-triggers`.
|
|
139
|
-
|
|
167
|
+
copy: `node node_modules/ezlogs-nextjs/bin/install-triggers.cjs install-triggers`.
|
|
168
|
+
The CLI reads `DATABASE_URL` / `POSTGRES_URL` from your shell or from
|
|
169
|
+
`.env`, `.env.local` and `.env.[mode]` (loaded the way Next.js loads
|
|
170
|
+
them, incl. `${VAR}` expansion; a variable already set in the shell
|
|
171
|
+
wins). Migration tables, database internals, the agent's own audit
|
|
172
|
+
table, verification-token tables and session stores (a
|
|
173
|
+
`session(s)`-style name **and** a token, expiry, `sess`, `data`,
|
|
174
|
+
`payload` or `last_activity` column: Auth.js, Lucia, Rails, Laravel,
|
|
175
|
+
connect-pg-simple) are skipped; the output lists each skipped table
|
|
176
|
+
with the reason. A `session` table without such columns (analytics
|
|
177
|
+
visits, bookings) is tracked. If `pg` or the
|
|
140
178
|
audit table is missing at runtime, the agent logs one warning at
|
|
141
179
|
startup and leaves the trigger path off.
|
|
142
180
|
|
|
143
|
-
**Recommended setup for Prisma** (plain `new PrismaClient()`,
|
|
144
|
-
adapter): triggers **plus** the
|
|
145
|
-
the request so DB changes join
|
|
181
|
+
**Recommended setup for Prisma** (plain `new PrismaClient()`, or with
|
|
182
|
+
a driver adapter such as `@prisma/adapter-pg`): triggers **plus** the
|
|
183
|
+
extension, which tags each write with the request so DB changes join
|
|
184
|
+
the right action and actor. (`patchPrismaPgAdapter` /
|
|
185
|
+
`patchPrismaClient` are legacy; see [docs/database.md](./docs/database.md).)
|
|
146
186
|
|
|
147
187
|
```ts
|
|
148
188
|
// lib/prisma.ts
|
|
@@ -153,12 +193,35 @@ export const prisma = new PrismaClient().$extends(ezlogsPrisma());
|
|
|
153
193
|
```
|
|
154
194
|
|
|
155
195
|
Each write inside a captured request runs as
|
|
156
|
-
`$transaction([set_config(correlation id), your query])` (Prisma's
|
|
196
|
+
`$transaction([set_config(correlation id, actor id), your query])` (Prisma's
|
|
157
197
|
documented RLS-extension pattern); reads are untouched. Writes inside
|
|
158
198
|
your own `prisma.$transaction(...)` are not tagged: they still show up,
|
|
159
199
|
as separate actions without an actor. Without the extension, a plain
|
|
160
200
|
PrismaClient's writes are never tagged.
|
|
161
201
|
|
|
202
|
+
**postgres.js / Drizzle on postgres-js** (Vercel Postgres templates,
|
|
203
|
+
`nextjs/saas-starter`): triggers **plus** wrap the `sql` instance once.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// lib/db.ts
|
|
207
|
+
import postgres from "postgres";
|
|
208
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
209
|
+
import { wrapPostgresJs } from "ezlogs-nextjs/postgres";
|
|
210
|
+
|
|
211
|
+
export const sql = wrapPostgresJs(postgres(process.env.DATABASE_URL!));
|
|
212
|
+
export const db = drizzle(sql); // Drizzle: pass the wrapped instance
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Each write inside a captured request (``sql`insert …` ``, `sql.unsafe`,
|
|
216
|
+
Drizzle inserts / updates / deletes) runs as BEGIN; set_config
|
|
217
|
+
(correlation id, actor); your write; COMMIT on one pooled connection,
|
|
218
|
+
and resolves after COMMIT. Inside your own `sql.begin` / Drizzle
|
|
219
|
+
`db.transaction`, the setting is applied once at the start. Reads,
|
|
220
|
+
cursors, `sql.file`, COPY and `sql.reserve()` connections are not
|
|
221
|
+
tagged: those writes show up as their own actions. Each tagged write
|
|
222
|
+
is its own transaction (4 round trips instead of 1), so write latency
|
|
223
|
+
grows with your database round-trip time.
|
|
224
|
+
|
|
162
225
|
**Background workers** (BullMQ and other job processes) are separate
|
|
163
226
|
processes: call `ezlogs.init` there too and build the database client
|
|
164
227
|
the same way (extension for Prisma), or the job's writes show up as
|
|
@@ -174,20 +237,41 @@ values only — Prisma doesn't expose the old row). With triggers it
|
|
|
174
237
|
sends nothing for tracked tables; the trigger rows are the single
|
|
175
238
|
source, so there are no duplicates (also for `@@map`-ed models).
|
|
176
239
|
|
|
177
|
-
**Upgrading:** from 0.2.x
|
|
178
|
-
|
|
240
|
+
**Upgrading:** from 0.2.x or 0.3.x there is nothing to re-run before
|
|
241
|
+
deploying. From 0.1.x, run `npx ezlogs-nextjs install-triggers --tables=none`
|
|
179
242
|
**before** deploying the new agent (functions only, no table locks),
|
|
180
243
|
deploy right after, and later re-run `npx ezlogs-nextjs install-triggers`
|
|
181
244
|
at a quiet moment. Details in [CHANGELOG.md](./CHANGELOG.md).
|
|
182
245
|
|
|
246
|
+
### 5. Name your records
|
|
247
|
+
|
|
248
|
+
Database changes are titled with the record's `name`, `title`,
|
|
249
|
+
`number` or `label` column. Records of people (users, members,
|
|
250
|
+
customers) are never named automatically: an email or a person's name
|
|
251
|
+
would show up on shared links. To name them, say how in `ezlogs.init`:
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
ezlogs.init({
|
|
255
|
+
// ...
|
|
256
|
+
displayNameFor: {
|
|
257
|
+
users: (row) => row.full_name ?? row.username, // a column name also works: users: "username"
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
The key is the table name for trigger-captured changes (`users`) and
|
|
263
|
+
the model name for the per-ORM adapters (`User`). Without it, the
|
|
264
|
+
record shows by its id.
|
|
265
|
+
|
|
183
266
|
---
|
|
184
267
|
|
|
185
268
|
## What gets captured
|
|
186
269
|
|
|
187
270
|
| Source | What | Where it comes from |
|
|
188
271
|
|---|---|---|
|
|
189
|
-
| HTTP | Method, path, status, duration, sanitized params (incl. route params like `[id]`), GraphQL op, the `error` / `message` of a JSON error response | App Router + Pages Router (auto-wrapped) |
|
|
190
|
-
|
|
|
272
|
+
| HTTP | Method, path, status, duration, sanitized params (incl. route params like `[id]`), GraphQL op, the `error` / `message` of a JSON error response; tRPC: the procedure (`trpc` param), its input without the superjson / batch envelope, and the zod field error or message of a failed call, named after the procedure (`post.delete: Not allowed`); a batch where some calls failed (HTTP 207), or a failed call in an `httpBatchStreamLink` stream (create-t3-app's default, HTTP 200), is a failure. A streamed response (tRPC's `httpBatchStreamLink`, AI SDK, SSE) is recorded when its body ends, with the DB writes made while it streamed | App Router + Pages Router (auto-wrapped, incl. Auth.js `export const { GET, POST } = handlers`) |
|
|
273
|
+
| Page views | Page loads (the browser loading a page's HTML). `<Link>` prefetches and client-side navigations are not page views: Next strips their markers before middleware runs, so the two can't be told apart there | `middleware.ts` / Next 16 `proxy.ts` (auto-wrapped) |
|
|
274
|
+
| Server Actions | Action name, args, caller IP, outcome, and where a `redirect()` sent the user (`redirect_to`: same-origin path only, no query, token-like segments masked; external redirects are not recorded). A returned failure is a failure with its message: `{ success: false, error }`, `{ error: "…" }` (no truthy `success` / `ok`, no `data`), and a pure form state `{ errors: { field: [...] } \| [...], message? }` (Next.js `useActionState`), next-safe-action, zsa, Conform, zod `safeParse`. Stay successes: `{ message: "Saved" }`, a database row (`id` / `created_at` / `updatedAt` key) with an `error` column, a partial success like `{ imported: 97, errors: [...] }`. `redirect()` / `notFound()` are not failures | File-level + inline `"use server"` (auto-wrapped) |
|
|
191
275
|
| Database | `model_class`, `operation`, full from→to diffs incl. json leaves (trigger path), record name | Postgres triggers, Prisma, Drizzle, supabase-js |
|
|
192
276
|
| Background jobs | `job_class`, `job_id`, `queue`, `retry_count`, sanitized `arguments`, plus the DB writes the job made | BullMQ, Inngest, Trigger.dev, pgmq, Upstash Workflow |
|
|
193
277
|
|
|
@@ -195,9 +279,23 @@ Every event in one inbound request shares a `correlation_id` so the
|
|
|
195
279
|
server stitches them into a single Action card.
|
|
196
280
|
|
|
197
281
|
**Automatic exclusions** (no config needed):
|
|
198
|
-
`_next`, `_vercel`, `__nextjs_*`,
|
|
199
|
-
|
|
200
|
-
|
|
282
|
+
`_next`, `_vercel`, `__nextjs_*`, health-checks, static assets, and
|
|
283
|
+
auth plumbing: `GET` / `HEAD` on `/api/auth/*` and on any login /
|
|
284
|
+
logout / sign-in / sign-out / signin / signout / `/session*` path
|
|
285
|
+
(page loads, session polls, OAuth and email-link callbacks), plus
|
|
286
|
+
`/api/auth/session`, `/api/auth/csrf`, `/api/auth/providers` and
|
|
287
|
+
`/api/auth/_log` on every method.
|
|
288
|
+
|
|
289
|
+
**Auth events are captured:** `POST`s to sign-in, sign-up, sign-out,
|
|
290
|
+
login and logout routes (NextAuth / Auth.js `/api/auth/*`, custom
|
|
291
|
+
`/api/login`, …) and auth Server Actions, including failed attempts
|
|
292
|
+
(a 4xx response or a returned error). Passwords, tokens and other
|
|
293
|
+
sensitive params are sent as `"[FILTERED]"`; on auth routes and auth
|
|
294
|
+
Server Actions (`signIn`, `verifyOtp`, …) one-time codes and OAuth
|
|
295
|
+
state are too (`code`, `state`, `verification_code`, `otp*`, `pin`,
|
|
296
|
+
`token*`; `code` stays visible on other routes). Secret query params
|
|
297
|
+
inside `callbackUrl` / `redirect` / `from_page` values are masked
|
|
298
|
+
everywhere.
|
|
201
299
|
|
|
202
300
|
## Per-area docs
|
|
203
301
|
|
|
@@ -259,13 +357,15 @@ event. EZLogs is best-effort, not guaranteed delivery.
|
|
|
259
357
|
by the agent before sending. DB values are dropped, not sent as
|
|
260
358
|
`"[FILTERED]"` (that placeholder is for request params and job
|
|
261
359
|
arguments).
|
|
262
|
-
- **Retention of `ezlogs_audit_log`.** Rows are deleted
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
`DELETE
|
|
360
|
+
- **Retention of `ezlogs_audit_log`.** Rows are deleted when the agent
|
|
361
|
+
claims them, before it sends them (best-effort: a rejected token or a
|
|
362
|
+
full buffer loses them). Rows nobody claimed (untagged writes, or
|
|
363
|
+
tagged rows older than 5 minutes) are sent as their own actions by a
|
|
364
|
+
throttled sweep, up to 7 days old. Rows older than 7 days are deleted
|
|
365
|
+
unsent (one warning when a backlog remains). The agent's role needs
|
|
366
|
+
`DELETE` on the table; without it the agent warns once and you must
|
|
367
|
+
schedule
|
|
368
|
+
`DELETE FROM ezlogs_audit_log WHERE captured_at < now() - interval '7 days'`.
|
|
269
369
|
- **Access to `ezlogs_audit_log`.** Row-level security is on and all
|
|
270
370
|
privileges are revoked from `PUBLIC` and Supabase's `anon` /
|
|
271
371
|
`authenticated`, so the table is not reachable through PostgREST.
|
|
@@ -278,6 +378,25 @@ event. EZLogs is best-effort, not guaranteed delivery.
|
|
|
278
378
|
exposes for supabase-js). Untagged writes show up as their own
|
|
279
379
|
actions without an actor. An inbound `x-ezlogs-correlation-id` is
|
|
280
380
|
honored only in the agent's own format and if under an hour old.
|
|
381
|
+
- **A DB change's actor is the one its writer stored.** The agent sets
|
|
382
|
+
the actor id next to the correlation id on tagged writes (`pg`,
|
|
383
|
+
postgres.js, Prisma), so a row keeps its writer's actor even when
|
|
384
|
+
another scope with the same correlation id sends it. supabase-js
|
|
385
|
+
writes store no actor: they join their request, and the request's
|
|
386
|
+
own event carries the actor.
|
|
387
|
+
- **Work that outlives a request.** Async work started inside a
|
|
388
|
+
request (`after()`, `waitUntil`, an un-awaited write) keeps its
|
|
389
|
+
correlation id and actor for 60 seconds after the request's events
|
|
390
|
+
are flushed. After that (a `setInterval`, a long-lived object
|
|
391
|
+
created lazily inside a request) its writes, jobs and fetches are
|
|
392
|
+
unlinked: their own actions, never the old request's. Work a
|
|
393
|
+
background job started ends the same way, 60 seconds after the job.
|
|
394
|
+
- **Don't share one `pg.Client` across concurrent requests.** Use a
|
|
395
|
+
`pg.Pool`. While one request has its own transaction open on a
|
|
396
|
+
shared client, another request's write on it runs inside that
|
|
397
|
+
transaction in Postgres and is recorded under the first request.
|
|
398
|
+
- **Cursors and streams** (`pg-cursor`, `pg-query-stream`, COPY) are
|
|
399
|
+
passed to `pg` untouched; writes made through them are untagged.
|
|
281
400
|
|
|
282
401
|
## Wire-format parity
|
|
283
402
|
|
package/bin/install-triggers.cjs
CHANGED
|
@@ -25,9 +25,14 @@ function installedFromProject() {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
(async () => {
|
|
28
|
-
const { runInstall, parseArgs } = require("../dist/triggers/index.cjs");
|
|
28
|
+
const { runInstall, parseArgs, loadEnvFiles } = require("../dist/triggers/index.cjs");
|
|
29
29
|
const { version } = require("../package.json");
|
|
30
30
|
|
|
31
|
+
// DATABASE_URL usually lives in .env / .env.local: load them the way
|
|
32
|
+
// Next.js does (already-set variables win).
|
|
33
|
+
const envFiles = loadEnvFiles(process.cwd());
|
|
34
|
+
if (envFiles.length > 0) console.log(`[ezlogs] Loaded env from ${envFiles.join(", ")}`);
|
|
35
|
+
|
|
31
36
|
const argv = process.argv.slice(2);
|
|
32
37
|
const command = argv.find((a) => !a.startsWith("-"));
|
|
33
38
|
if (command !== undefined && command !== "install-triggers") {
|
|
@@ -111,7 +116,7 @@ function installedFromProject() {
|
|
|
111
116
|
await client.connect();
|
|
112
117
|
} catch (err) {
|
|
113
118
|
console.error(
|
|
114
|
-
`[ezlogs] Could not connect to ${args.connection}: ${err.message}`,
|
|
119
|
+
`[ezlogs] Could not connect to ${args.connection.replace(/\/\/([^:/@]*):[^@]*@/, "//$1:***@")}: ${err.message}`,
|
|
115
120
|
);
|
|
116
121
|
process.exit(1);
|
|
117
122
|
}
|
package/dist/actors/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTWTG5ILJ_cjs = require('../chunk-TWTG5ILJ.cjs');
|
|
4
4
|
require('../chunk-ZDSQYCYV.cjs');
|
|
5
5
|
|
|
6
6
|
// src/actors/clerk.ts
|
|
@@ -20,7 +20,7 @@ function clerkActor() {
|
|
|
20
20
|
const label = typeof claims.email === "string" && claims.email || typeof claims.name === "string" && claims.name || typeof claims.username === "string" && claims.username || void 0;
|
|
21
21
|
return label ? { id: userId, label } : { id: userId };
|
|
22
22
|
} catch (error) {
|
|
23
|
-
|
|
23
|
+
chunkTWTG5ILJ_cjs.logger.debug(
|
|
24
24
|
`clerkActor: extraction failed (${error instanceof Error ? error.message : String(error)})`
|
|
25
25
|
);
|
|
26
26
|
return null;
|
|
@@ -46,7 +46,7 @@ function nextAuthActor(options) {
|
|
|
46
46
|
const label = typeof user.name === "string" && user.name || typeof user.email === "string" && user.email || void 0;
|
|
47
47
|
return label ? { id, label } : { id };
|
|
48
48
|
} catch (error) {
|
|
49
|
-
|
|
49
|
+
chunkTWTG5ILJ_cjs.logger.debug(
|
|
50
50
|
`nextAuthActor: extraction failed (${error instanceof Error ? error.message : String(error)})`
|
|
51
51
|
);
|
|
52
52
|
return null;
|
|
@@ -66,7 +66,7 @@ function authJsActor(options) {
|
|
|
66
66
|
const label = typeof user.name === "string" && user.name || typeof user.email === "string" && user.email || void 0;
|
|
67
67
|
return label ? { id, label } : { id };
|
|
68
68
|
} catch (error) {
|
|
69
|
-
|
|
69
|
+
chunkTWTG5ILJ_cjs.logger.debug(
|
|
70
70
|
`authJsActor: extraction failed (${error instanceof Error ? error.message : String(error)})`
|
|
71
71
|
);
|
|
72
72
|
return null;
|
package/dist/actors/index.d.cts
CHANGED
package/dist/actors/index.d.ts
CHANGED
package/dist/actors/index.js
CHANGED
|
@@ -32,6 +32,13 @@ function safeWrite(level, message) {
|
|
|
32
32
|
var logger = {
|
|
33
33
|
debug: (message) => safeWrite("debug", message),
|
|
34
34
|
info: (message) => safeWrite("info", message),
|
|
35
|
+
/** An info line that also shows at the default `warn` level (startup confirmation). */
|
|
36
|
+
notice: (message) => {
|
|
37
|
+
try {
|
|
38
|
+
if (shouldLog("warn")) console.log(`[ezlogs] ${message}`);
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
},
|
|
35
42
|
warn: (message) => safeWrite("warn", message),
|
|
36
43
|
error: (message) => safeWrite("error", message)
|
|
37
44
|
};
|