@shivaedev/server 0.23.0 → 0.24.1
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/CHANGELOG.md +25 -0
- package/README.md +13 -18
- package/dist/adapters/localTraceDatabase.d.ts +6 -0
- package/dist/adapters/localTraceDatabase.d.ts.map +1 -0
- package/dist/adapters/localTraceDatabase.js +75 -0
- package/dist/adapters/localTraceDatabase.js.map +1 -0
- package/dist/development.js +1 -1
- package/dist/development.js.map +1 -1
- package/dist/localTraceRow.d.ts +29 -0
- package/dist/localTraceRow.d.ts.map +1 -0
- package/dist/localTraceRow.js +51 -0
- package/dist/localTraceRow.js.map +1 -0
- package/dist/localTracing.d.ts +10 -0
- package/dist/localTracing.d.ts.map +1 -0
- package/dist/localTracing.js +44 -0
- package/dist/localTracing.js.map +1 -0
- package/dist/otlpTracing.d.ts.map +1 -1
- package/dist/otlpTracing.js +14 -1
- package/dist/otlpTracing.js.map +1 -1
- package/package.json +20 -20
- package/src/adapters/localTraceDatabase.ts +74 -0
- package/src/development.ts +1 -1
- package/src/localTraceRow.ts +58 -0
- package/src/localTracing.ts +63 -0
- package/src/otlpTracing.ts +18 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.24.1 - 2026-11-04
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Update `@shivaedev/admin` from 0.20.0 to 0.20.1.
|
|
8
|
+
- Update `@shivaedev/identity` from 0.24.0 to 0.25.0.
|
|
9
|
+
- Update `@shivaedev/local-postgres` from 0.13.0 to 0.14.0.
|
|
10
|
+
- Update `@shivaedev/sql` from 0.37.0 to 0.38.0.
|
|
11
|
+
- Update `@shivaedev/test-sql` from 0.20.0 to 0.21.0.
|
|
12
|
+
|
|
13
|
+
## 0.24.0 - 2026-11-04
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Announce the host's configured build version over native live RPC so loaded tabs detect a deploy without polling health.
|
|
18
|
+
- Record development spans and correlated logs in a local SQLite store without an OpenTelemetry collector, using the host redaction policy. Configure indexed attributes and compose `localTracing` directly with scoped flushing and run retention.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Start development server and worker processes with `NODE_ENV=development`. Hosts without an OTLP endpoint record locally in this mode.
|
|
23
|
+
|
|
24
|
+
### Breaking
|
|
25
|
+
|
|
26
|
+
- TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
|
|
27
|
+
|
|
3
28
|
## 0.23.0 - 2026-11-04
|
|
4
29
|
|
|
5
30
|
### Added
|
package/README.md
CHANGED
|
@@ -211,7 +211,7 @@ const host = appHost({
|
|
|
211
211
|
|
|
212
212
|
Construct Better Auth inside `application`, since its constructor starts schema validation. Keep validation enabled so a current migration ledger with missing auth columns still reports drift. The starter uses this form after its pre-deploy migrations.
|
|
213
213
|
|
|
214
|
-
Railway tracing is the default error and trace destination. The starter enables tracing for both services in `.railway/railway.ts`; Railway injects the endpoint, authentication headers and service identity. `appHost` exports through the redacting Effect OTLP/HTTP pipeline. Leave exporter endpoints unset on Railway so its injected configuration takes effect.
|
|
214
|
+
Railway tracing is the default error and trace destination. The starter enables tracing for both services in `.railway/railway.ts`; Railway injects the endpoint, authentication headers and service identity. `appHost` exports through the redacting Effect OTLP/HTTP pipeline. Leave exporter endpoints unset on Railway so its injected configuration takes effect. Outside development mode, without an endpoint, no exporter or export loop is built, even when service metadata is set. The `http/protobuf` default follows the [OpenTelemetry recommendation](https://opentelemetry.io/docs/specs/otel/protocol/exporter/#specify-protocol); unsupported protocols, including `grpc`, fail startup with a `ConfigError` naming the value. Header and resource-attribute values are `key=value` pairs with URL-encoded values. Configuration is read through Effect Config.
|
|
215
215
|
|
|
216
216
|
The supported tracing variables and defaults are:
|
|
217
217
|
|
|
@@ -240,25 +240,17 @@ For existing Railway services, enable manual tracing per service and environment
|
|
|
240
240
|
Set `browserErrors: { log: true, includeUserId: true, requireSession: true }` on `appHost` for the recommended signed-in application setting. `log` writes one Error log with the masked message and stack per accepted report, including when OTLP export is off. `includeUserId` resolves the session and adds `user.id` to the HTTP span and error report when signed in. `requireSession` rejects signed-out reports with 401; a session-provider outage returns 503. Session lookups use the host's session and origin policy. With no session policy, requiring a session rejects reports. All three options default to false, preserving reports before sign-in without session lookups or an extra log line. `browserErrorRoute(trustedProxy?, options?)` accepts the same options when composed directly.
|
|
241
241
|
|
|
242
242
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
exporters:
|
|
252
|
-
debug:
|
|
253
|
-
verbosity: detailed
|
|
254
|
-
service:
|
|
255
|
-
pipelines:
|
|
256
|
-
traces:
|
|
257
|
-
receivers: [ otlp ]
|
|
258
|
-
exporters: [ debug ]
|
|
243
|
+
With `NODE_ENV=development` and no OTLP endpoint, `appHost` and `otlpTracing` record to `.platform/traces.db` using Node's SQLite support. `runDevelopment` sets this mode for its child processes. Add `.platform/` to the application's ignore file. Set `PLATFORM_TRACE_STORE` to choose another file and `PLATFORM_TRACE_INDEXED_ATTRIBUTES=orderId,projectId` to index application attributes. Indexed values use the same redaction as the stored spans. An explicit OTLP endpoint takes precedence; other modes without an endpoint keep export disabled.
|
|
244
|
+
|
|
245
|
+
Records flush every second on a live maintenance clock and when their scope closes. Application clock jumps do not replay flush intervals. The store retains the latest five completed recorder runs, deleting older spans, logs and attribute indexes when a recorder closes. Active recorders remain writable until their scopes close. Logs use the existing `effect.log` diagnostic spans; the `logs` view exposes their parent span ID and trace ID. Open the file with any SQLite viewer, or inspect it directly:
|
|
246
|
+
|
|
247
|
+
```sh
|
|
248
|
+
sqlite3 .platform/traces.db "SELECT name, trace_id, span_id, data FROM spans ORDER BY started_at_millis DESC LIMIT 20"
|
|
249
|
+
sqlite3 .platform/traces.db "SELECT trace_id, span_id, data FROM logs ORDER BY at_millis DESC LIMIT 20"
|
|
250
|
+
sqlite3 .platform/traces.db "SELECT span_id FROM span_attributes WHERE key = 'orderId' AND value = 'order-42'"
|
|
259
251
|
```
|
|
260
252
|
|
|
261
|
-
|
|
253
|
+
For explicit composition, provide `localTracing({ path, indexedAttributes, retainedRuns, flushInterval, clock })` from `@shivaedev/server/localTracing.ts` to the application's Layer. All options are optional; `flushInterval` is milliseconds, and `retainedRuns` is a positive integer. Supply a native `clock` to control flush timing in stories; span timestamps still follow the application clock. It uses `RedactionPolicy`, including host schema sensitivity, and preserves the application's installed tracer and console loggers. Local recording and OTLP export are alternative sinks; compose one per application scope.
|
|
262
254
|
|
|
263
255
|
Exported HTTP server spans use `{method} {route}` with `http.route` for matched RPC and router paths, including parameter templates; unmatched requests use the method alone. `appHost` continues incoming W3C `traceparent` context in RPC handling, including one sent by an edge proxy, whether or not an exporter is configured.
|
|
264
256
|
|
|
@@ -274,6 +266,8 @@ To pass worker-release time in a story, build `hostTime()` from `@shivaedev/serv
|
|
|
274
266
|
|
|
275
267
|
For a deployment behind a proxy, set `HOST=0.0.0.0` and `TRUSTED_PROXY` to a comma-separated list of proxy peer IPs or CIDR ranges (IPv4 or IPv6), or use `config.host` and `config.trustedProxy`. Only matching peers may supply `X-Forwarded-Host` and `X-Forwarded-Proto` (`http` or `https`) for the guard's same-origin check; the proxy must overwrite both headers and preserve Origin. A single authority is required, and comma-separated forwarding chains are refused. IPv4-mapped IPv6 peers match their IPv4 address. A session host bound to a non-loopback address refuses to boot without `TRUSTED_PROXY` or `config.trustedProxy`, with a typed `TrustedProxyRequired` error from `@shivaedev/server/TrustedProxyRequired.ts` naming both settings and how to supply proxy peer addresses or CIDR ranges. Local loopback hosts keep working without proxy trust; `policy: "loopback"` does not use proxy trust. Malformed addresses or ranges fail `appHost` startup with a typed `ConfigError`. The starter's Railway deployment works out of the box: its web configuration supplies `TRUSTED_PROXY=100.64.0.0/10` and `AUTH_CLIENT_IP_HEADER=x-real-ip`, so matching peers supply forwarded client IPs for auth and the HTTPS authority for RPC origin checks. Set `PUBLIC_URL` to the app's HTTPS URL for secure session cookies. NDJSON and the application's session Origin policy still apply. See the [deployment quickstart](https://github.com/ShivaeDev/platform/blob/main/docs/framework/quickstart.md#deploy).
|
|
276
268
|
|
|
269
|
+
When mounting Better Auth routes yourself on Railway, use `betterAuthMount(authOptions, { clientIp: "railway" })` from `@shivaedev/identity/server/better-auth/adapters/mount.ts` with `TRUSTED_PROXY=100.64.0.0/10`. The `clientIp` preset selects `X-Real-IP` for auth and ignores spoofed `X-Forwarded-For`, overriding `AUTH_CLIENT_IP_HEADER`. Untrusted peers and requests without `X-Real-IP` use the connection address.
|
|
270
|
+
|
|
277
271
|
Build application handlers with `Api.application.toLayer(...)` (and `Api.application.of(...)` for an Effect-built handler map), then pass the full `Api` to the host and client. `Api.application` is the native RPC group without the reserved `$changes` stream; the host supplies that handler. The explicit `Api.omit("<namespace>.$changes")` form also works.
|
|
278
272
|
|
|
279
273
|
Set `LISTEN_DATABASE_URL` to a direct or session-mode connection when `DATABASE_URL` uses a transaction pooler. `config.listenDatabaseUrl` overrides that setting; when neither is set, the listener shares the application pool. Both URLs must reach the same database. A separate listener pool reserves one connection; the application pool continues to own migrations, writes and heartbeat publication. Startup waits for the listener to receive its own heartbeat. A timeout fails the host with `PostgresListenerError` from `@shivaedev/sql/PostgresListenerError.ts`, naming the selected connection setting. Fix the URL before restarting; a startup timeout does not fall back to periodic reconnects. Established listeners retain their reconnect and Resync behavior.
|
|
@@ -499,6 +493,7 @@ Import the module that defines the name; there is no package-root entry. Paths b
|
|
|
499
493
|
| `setupDatabases.ts` | `setupDatabases()`: prepare the local development and test databases. |
|
|
500
494
|
| `development.ts` | `development({ server, worker, conditions? })`, `runDevelopment(options)`: run the server, worker and Vite in watch mode. |
|
|
501
495
|
| `rpc-server/publicConfigLayer.ts` | `publicConfigLayer(declaration, path?)`: serve a `publicConfig` declaration from native Config. |
|
|
496
|
+
| `localTracing.ts` | `localTracing(options?)`: scoped local SQLite spans and correlated logs with configurable attribute indexes and run retention. |
|
|
502
497
|
| `otlpTracing.ts` | `otlpTracing`: redacting Railway OTLP export for worker spans, logs and error reports. |
|
|
503
498
|
| `RedactionPolicy.ts` | `RedactionPolicy`: provide the app's diagnostic key predicate derived by errors. |
|
|
504
499
|
| `redactingDiagnostics.ts`, `redactingTracer.ts`, `redactingRpcSerialization.ts` | `redactingDiagnostics(sensitive)`, `redactingTracer(sensitive)`, `redactingRpcSerialization(wire, sensitive)`: compose native diagnostic and NDJSON boundaries. |
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type LocalTraceRow } from "#localTraceRow.ts";
|
|
2
|
+
export declare function localTraceDatabase(path: string, retainedRuns: number, indexedAttributes: readonly string[], startedAtMillis: number): {
|
|
3
|
+
close: () => void;
|
|
4
|
+
write: (rows: readonly LocalTraceRow[]) => void;
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=localTraceDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localTraceDatabase.d.ts","sourceRoot":"","sources":["../../src/adapters/localTraceDatabase.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAa,MAAM,mBAAmB,CAAC;AAElE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,SAAS,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM;;kBAkDnH,SAAS,aAAa,EAAE;EAiBxC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { traceJson } from "#localTraceRow.ts";
|
|
6
|
+
export function localTraceDatabase(path, retainedRuns, indexedAttributes, startedAtMillis) {
|
|
7
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
8
|
+
const db = new DatabaseSync(path, { timeout: 1000 });
|
|
9
|
+
try {
|
|
10
|
+
db.exec(`
|
|
11
|
+
PRAGMA journal_mode = WAL;
|
|
12
|
+
PRAGMA foreign_keys = ON;
|
|
13
|
+
CREATE TABLE IF NOT EXISTS runs (id TEXT PRIMARY KEY, started_at_millis INTEGER NOT NULL, completed INTEGER NOT NULL DEFAULT 0);
|
|
14
|
+
CREATE TABLE IF NOT EXISTS spans (
|
|
15
|
+
run_id TEXT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
|
|
16
|
+
span_id TEXT PRIMARY KEY, trace_id TEXT NOT NULL, parent_span_id TEXT,
|
|
17
|
+
name TEXT NOT NULL, started_at_millis INTEGER NOT NULL, data TEXT NOT NULL
|
|
18
|
+
);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS spans_trace ON spans(trace_id, started_at_millis);
|
|
20
|
+
CREATE TABLE IF NOT EXISTS span_attributes (
|
|
21
|
+
span_id TEXT NOT NULL REFERENCES spans(span_id) ON DELETE CASCADE,
|
|
22
|
+
key TEXT NOT NULL, value TEXT NOT NULL
|
|
23
|
+
);
|
|
24
|
+
CREATE INDEX IF NOT EXISTS span_attributes_lookup ON span_attributes(key, value, span_id);
|
|
25
|
+
CREATE VIEW IF NOT EXISTS logs AS
|
|
26
|
+
SELECT run_id, trace_id, parent_span_id AS span_id, started_at_millis AS at_millis,
|
|
27
|
+
json_extract(data, '$.events[0].attributes') AS data FROM spans WHERE name = 'effect.log';
|
|
28
|
+
`);
|
|
29
|
+
const runId = randomUUID();
|
|
30
|
+
db.prepare("INSERT INTO runs(id, started_at_millis) VALUES (?, ?)").run(runId, startedAtMillis);
|
|
31
|
+
const complete = db.prepare("UPDATE runs SET completed = (SELECT coalesce(max(completed), 0) + 1 FROM runs) WHERE id = ?");
|
|
32
|
+
const prune = db.prepare("DELETE FROM runs WHERE completed > 0 AND id NOT IN (SELECT id FROM runs WHERE completed > 0 ORDER BY completed DESC LIMIT ?)");
|
|
33
|
+
const insert = db.prepare("INSERT INTO spans VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
34
|
+
const index = db.prepare("INSERT INTO span_attributes VALUES (?, ?, ?)");
|
|
35
|
+
const indexed = new Set(indexedAttributes);
|
|
36
|
+
function append(row) {
|
|
37
|
+
insert.run(runId, row.spanId, row.traceId, row.parentSpanId, row.name, row.startedAtMillis, traceJson(row));
|
|
38
|
+
for (const key of indexed) {
|
|
39
|
+
const value = row.attributes[key];
|
|
40
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
41
|
+
index.run(row.spanId, key, String(value));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
close: () => {
|
|
47
|
+
try {
|
|
48
|
+
complete.run(runId);
|
|
49
|
+
prune.run(retainedRuns);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
db.close();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
write: (rows) => {
|
|
56
|
+
db.exec("BEGIN");
|
|
57
|
+
try {
|
|
58
|
+
for (const row of rows) {
|
|
59
|
+
append(row);
|
|
60
|
+
}
|
|
61
|
+
db.exec("COMMIT");
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
db.exec("ROLLBACK");
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
db.close();
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=localTraceDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localTraceDatabase.js","sourceRoot":"","sources":["../../src/ad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;IACb,CAAC;AACF,CAAC"}
|
package/dist/development.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Effect } from "effect";
|
|
|
5
5
|
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
6
6
|
export const development = Effect.fn("Platform.development")(function* ({ server, worker, conditions = [] }) {
|
|
7
7
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
8
|
-
const options = { stderr: "inherit", stdout: "inherit" };
|
|
8
|
+
const options = { env: { "NODE_ENV": "development" }, extendEnv: true, stderr: "inherit", stdout: "inherit" };
|
|
9
9
|
const args = [...conditions.map((condition) => `--conditions=${condition}`), "--watch"];
|
|
10
10
|
return yield* Effect.raceAll([
|
|
11
11
|
spawner.exitCode(ChildProcess.make(process.execPath, [...args, server], options)),
|
package/dist/development.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"development.js","sourceRoot":"","sources":["../src/development.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,WAAW,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,YAAY,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAQnE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,EAAE,EAAsB;IAC9H,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,mBAAmB,CAAC;IAC/D,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"development.js","sourceRoot":"","sources":["../src/development.ts"],"names":[],"mappings":"AAAA,OAAO,OA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,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc,CAAC,OAA2B;IACzD,WAAW,CAAC,OAAO,CAClB,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,CACxB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACnB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;QAChB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC,CAAC,CACF,EACD,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAClC,CACD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Tracer } from "effect";
|
|
2
|
+
import { type HostRedactionPolicy } from "#RedactionPolicy.ts";
|
|
3
|
+
export type LocalTraceEvent = readonly [name: string, time: bigint, attributes: Record<string, unknown>];
|
|
4
|
+
export declare function localTraceRow(span: Tracer.Span, events: readonly LocalTraceEvent[], policy: HostRedactionPolicy): {
|
|
5
|
+
attributes: Record<string, unknown>;
|
|
6
|
+
durationNanos: string;
|
|
7
|
+
endedAtMillis: number;
|
|
8
|
+
error: string | null;
|
|
9
|
+
events: {
|
|
10
|
+
attributes: Record<string, unknown>;
|
|
11
|
+
name: string;
|
|
12
|
+
time: string;
|
|
13
|
+
}[];
|
|
14
|
+
kind: Tracer.SpanKind;
|
|
15
|
+
links: {
|
|
16
|
+
attributes: Record<string, unknown>;
|
|
17
|
+
spanId: string;
|
|
18
|
+
traceId: string;
|
|
19
|
+
}[];
|
|
20
|
+
name: string;
|
|
21
|
+
parentSpanId: string | null;
|
|
22
|
+
spanId: string;
|
|
23
|
+
startedAtMillis: number;
|
|
24
|
+
status: string;
|
|
25
|
+
traceId: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
export type LocalTraceRow = NonNullable<ReturnType<typeof localTraceRow>>;
|
|
28
|
+
export declare function traceJson(value: unknown): string;
|
|
29
|
+
//# sourceMappingURL=localTraceRow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localTraceRow.d.ts","sourceRoot":"","sources":["../src/localTraceRow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI1D,OAAO,EAAE,KAAK,mBAAmB,EAAmB,MAAM,qBAAqB,CAAC;AAEhF,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAczG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,eAAe,EAAE,EAAE,MAAM,EAAE,mBAAmB;;;;;;;;;;;;;;;;;;;;;;cA+B/G;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC;AAE1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Cause, Exit, Option } from "effect";
|
|
2
|
+
import { redactRecord } from "@shivaedev/errors/redact.ts";
|
|
3
|
+
import { redactDiagnosticCause } from "@shivaedev/errors/redactCause.ts";
|
|
4
|
+
import { redactText } from "@shivaedev/errors/sensitive.ts";
|
|
5
|
+
import { redactionForRpc } from "#RedactionPolicy.ts";
|
|
6
|
+
function rpcMethod(span) {
|
|
7
|
+
const method = span.attributes.get("rpc.method");
|
|
8
|
+
const parent = Option.getOrUndefined(span.parent);
|
|
9
|
+
return method ?? (parent?._tag === "Span" ? rpcMethod(parent) : undefined);
|
|
10
|
+
}
|
|
11
|
+
function traceError(cause, sensitive) {
|
|
12
|
+
return Cause.prettyErrors(cause)
|
|
13
|
+
.map((error) => Cause.pretty(redactDiagnosticCause(Cause.fail(error), sensitive)))
|
|
14
|
+
.join("\n");
|
|
15
|
+
}
|
|
16
|
+
export function localTraceRow(span, events, policy) {
|
|
17
|
+
if (span.status._tag !== "Ended" || !span.sampled) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const sensitive = redactionForRpc(policy, rpcMethod(span));
|
|
21
|
+
const { startTime, endTime, exit } = span.status;
|
|
22
|
+
const attributes = redactRecord(Object.fromEntries(span.attributes), sensitive);
|
|
23
|
+
const failedStatus = Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause) ? "interrupted" : "failure";
|
|
24
|
+
return {
|
|
25
|
+
attributes,
|
|
26
|
+
durationNanos: String(endTime - startTime),
|
|
27
|
+
endedAtMillis: Number.parseInt(String(endTime / 1000000n), 10),
|
|
28
|
+
error: Exit.isFailure(exit) ? redactText(traceError(exit.cause, sensitive), sensitive) : null,
|
|
29
|
+
events: events.map(([name, time, values]) => ({
|
|
30
|
+
attributes: redactRecord(values, sensitive),
|
|
31
|
+
name: redactText(name, sensitive),
|
|
32
|
+
time: String(time),
|
|
33
|
+
})),
|
|
34
|
+
kind: span.kind,
|
|
35
|
+
links: span.links.map(({ span: linked, attributes: values }) => ({
|
|
36
|
+
attributes: redactRecord(values, sensitive),
|
|
37
|
+
spanId: linked.spanId,
|
|
38
|
+
traceId: linked.traceId,
|
|
39
|
+
})),
|
|
40
|
+
name: redactText(span.name, sensitive),
|
|
41
|
+
parentSpanId: Option.getOrUndefined(span.parent)?.spanId ?? null,
|
|
42
|
+
spanId: span.spanId,
|
|
43
|
+
startedAtMillis: Number.parseInt(String(startTime / 1000000n), 10),
|
|
44
|
+
status: Exit.isSuccess(exit) ? "success" : failedStatus,
|
|
45
|
+
traceId: span.traceId,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function traceJson(value) {
|
|
49
|
+
return JSON.stringify(value, (_key, nested) => (typeof nested === "bigint" ? String(nested) : nested));
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=localTraceRow.js.map
|
|
@@ -0,0 +1 @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U,EAAE,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC;YAC3C,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;SACvB,CAAC,CAAC;QACH,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC;QACtC,YAAY,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,IAAI;QAChE,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,eAAe,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,GAAG,QAAU,CAAC,EAAE,EAAE,CAAC;QACpE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY;QACvD,OAAO,EAAE,IAAI,CAAC,OAAO;KACrB,CAAC;AACH,CAAC;AAID,MAAM,UAAU,SAAS,CAAC,KAAc;IACvC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAe,EAAE,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACjH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Clock, Layer } from "effect";
|
|
2
|
+
export interface LocalTracingOptions {
|
|
3
|
+
readonly clock?: Clock.Clock;
|
|
4
|
+
readonly flushInterval?: number;
|
|
5
|
+
readonly indexedAttributes?: readonly string[];
|
|
6
|
+
readonly path?: string;
|
|
7
|
+
readonly retainedRuns?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function localTracing({ clock, path, indexedAttributes, retainedRuns, flushInterval, }?: LocalTracingOptions): Layer.Layer<never, import("effect/Cause").UnknownError, never>;
|
|
10
|
+
//# sourceMappingURL=localTracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localTracing.d.ts","sourceRoot":"","sources":["../src/localTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAU,KAAK,EAAU,MAAM,QAAQ,CAAC;AAOtD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,YAAY,CAAC,EAC5B,KAAkC,EAClC,IAA4B,EAC5B,iBAAsB,EACtB,YAAgB,EAChB,aAAoB,GACpB,GAAE,mBAAwB,kEAyC1B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Clock, Effect, Layer, Tracer } from "effect";
|
|
2
|
+
import { localTraceDatabase } from "#adapters/localTraceDatabase.ts";
|
|
3
|
+
import { traceDiagnostics } from "#adapters/traceDiagnostics.ts";
|
|
4
|
+
import { localTraceRow } from "#localTraceRow.ts";
|
|
5
|
+
import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
6
|
+
import { redactingDiagnostics } from "#redactingDiagnostics.ts";
|
|
7
|
+
export function localTracing({ clock = Clock.Clock.defaultValue(), path = ".platform/traces.db", indexedAttributes = [], retainedRuns = 5, flushInterval = 1000, } = {}) {
|
|
8
|
+
return Layer.unwrap(Effect.gen(function* () {
|
|
9
|
+
const policy = yield* RedactionPolicy;
|
|
10
|
+
const underlying = yield* Tracer.Tracer;
|
|
11
|
+
const startedAtMillis = yield* Clock.currentTimeMillis;
|
|
12
|
+
const database = yield* Effect.acquireRelease(Effect.try(() => localTraceDatabase(path, retainedRuns, indexedAttributes, startedAtMillis)), (db) => Effect.sync(() => db.close()));
|
|
13
|
+
let pending = [];
|
|
14
|
+
const flush = Effect.sync(() => {
|
|
15
|
+
database.write(pending);
|
|
16
|
+
pending = [];
|
|
17
|
+
});
|
|
18
|
+
yield* Effect.addFinalizer(() => flush);
|
|
19
|
+
yield* Effect.sleep(flushInterval).pipe(Effect.andThen(flush), Effect.forever, Effect.provideService(Clock.Clock, clock), Effect.forkScoped);
|
|
20
|
+
const tracer = Tracer.make({
|
|
21
|
+
...underlying,
|
|
22
|
+
span: (options) => {
|
|
23
|
+
const span = underlying.span(options);
|
|
24
|
+
const events = [];
|
|
25
|
+
const event = span.event.bind(span);
|
|
26
|
+
const end = span.end.bind(span);
|
|
27
|
+
span.event = (name, time, attributes) => {
|
|
28
|
+
events.push([name, time, attributes ?? {}]);
|
|
29
|
+
event(name, time, attributes);
|
|
30
|
+
};
|
|
31
|
+
span.end = (time, exit) => {
|
|
32
|
+
end(time, exit);
|
|
33
|
+
const row = localTraceRow(span, events, policy);
|
|
34
|
+
if (row !== undefined) {
|
|
35
|
+
pending.push(row);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return span;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return redactingDiagnostics(policy).pipe(Layer.provideMerge(traceDiagnostics), Layer.provideMerge(Layer.succeed(Tracer.Tracer, tracer)));
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=localTracing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localTracing.js","sourceRoot":"","sources":["../src/localTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAA4C,aAAa,EAAE,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,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1I,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlpTracing.d.ts","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"otlpTracing.d.ts","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmC,KAAK,EAAU,MAAM,QAAQ,CAAC;AAYhF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CA0E9D,CAAC"}
|
package/dist/otlpTracing.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Config, Context, Effect, Layer, Schema } from "effect";
|
|
1
|
+
import { Config, ConfigProvider, Context, Effect, Layer, Schema } from "effect";
|
|
2
2
|
import { OtlpSerialization, OtlpTracer } from "effect/observability";
|
|
3
3
|
import { traceDiagnostics } from "#adapters/traceDiagnostics.ts";
|
|
4
|
+
import { localTracing } from "#localTracing.ts";
|
|
4
5
|
import { otlpHttpClient } from "#otlpHttpClient.ts";
|
|
5
6
|
import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
6
7
|
import { redactingDiagnostics } from "#redactingDiagnostics.ts";
|
|
@@ -15,6 +16,18 @@ export const otlpTracing = Layer.effectContext(Effect.gen(function* () {
|
|
|
15
16
|
return url;
|
|
16
17
|
}), Config.withDefault(undefined)));
|
|
17
18
|
if (endpoint === undefined) {
|
|
19
|
+
const mode = yield* Config.String("NODE_ENV").pipe(Config.withDefault("production"));
|
|
20
|
+
if (mode === "development") {
|
|
21
|
+
const path = yield* Config.String("PLATFORM_TRACE_STORE").pipe(Config.withDefault(".platform/traces.db"));
|
|
22
|
+
const indexed = yield* Config.String("PLATFORM_TRACE_INDEXED_ATTRIBUTES").pipe(Config.withDefault(""));
|
|
23
|
+
return yield* Layer.build(localTracing({
|
|
24
|
+
indexedAttributes: indexed
|
|
25
|
+
.split(",")
|
|
26
|
+
.map((key) => key.trim())
|
|
27
|
+
.filter(Boolean),
|
|
28
|
+
path,
|
|
29
|
+
})).pipe(Effect.mapError((cause) => new Config.ConfigError(new ConfigProvider.SourceError({ cause, message: "Cannot open local trace store" }))));
|
|
30
|
+
}
|
|
18
31
|
return Context.empty();
|
|
19
32
|
}
|
|
20
33
|
const configuredProtocol = yield* Config.String("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL").pipe(Config.orElse(() => Config.String("OTEL_EXPORTER_OTLP_PROTOCOL")), Config.withDefault("http/protobuf"));
|
package/dist/otlpTracing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlpTracing.js","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"otlpTracing.js","sourceRoot":"","sources":["../src/otlpTracing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MA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E,CACD,CAAC;AACH,CAAC,CAAC,CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
4
4
|
"description": "The Effect application host: HTTP and RPC serving, health, OTLP export, database and migrations, and development mode",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"imports": {
|
|
21
21
|
"#test/*": "./src/test-support/*",
|
|
22
22
|
"#*.ts": {
|
|
23
|
-
"source": "./src/*.ts",
|
|
23
|
+
"@shivaedev/source": "./src/*.ts",
|
|
24
24
|
"types": "./dist/*.d.ts",
|
|
25
25
|
"default": "./dist/*.js"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
"./*.ts": {
|
|
30
|
-
"source": "./src/*.ts",
|
|
30
|
+
"@shivaedev/source": "./src/*.ts",
|
|
31
31
|
"types": "./dist/*.d.ts",
|
|
32
32
|
"default": "./dist/*.js"
|
|
33
33
|
},
|
|
@@ -45,26 +45,26 @@
|
|
|
45
45
|
"README.md"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@shivaedev/changes": "0.
|
|
49
|
-
"@shivaedev/contract": "0.
|
|
50
|
-
"@shivaedev/errors": "0.
|
|
51
|
-
"@shivaedev/http": "0.
|
|
52
|
-
"@shivaedev/identity": "0.
|
|
53
|
-
"@shivaedev/local-postgres": "0.
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
48
|
+
"@shivaedev/changes": "0.10.0",
|
|
49
|
+
"@shivaedev/contract": "0.36.0",
|
|
50
|
+
"@shivaedev/errors": "0.9.0",
|
|
51
|
+
"@shivaedev/http": "0.6.0",
|
|
52
|
+
"@shivaedev/identity": "0.25.0",
|
|
53
|
+
"@shivaedev/local-postgres": "0.14.0",
|
|
54
|
+
"@shivaedev/sql": "0.38.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@effect/platform-node": "4.0.6",
|
|
58
58
|
"@effect/sql-pg": "4.0.6",
|
|
59
59
|
"@effect/vitest": "4.0.6",
|
|
60
|
-
"@shivaedev/access": "0.
|
|
61
|
-
"@shivaedev/admin": "0.
|
|
62
|
-
"@shivaedev/jobs": "0.
|
|
63
|
-
"@shivaedev/quality": "0.
|
|
64
|
-
"@shivaedev/rate-limit": "0.
|
|
65
|
-
"@shivaedev/test-kits": "0.
|
|
66
|
-
"@shivaedev/test-sql": "0.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
60
|
+
"@shivaedev/access": "0.5.0",
|
|
61
|
+
"@shivaedev/admin": "0.20.1",
|
|
62
|
+
"@shivaedev/jobs": "0.35.1",
|
|
63
|
+
"@shivaedev/quality": "0.61.0",
|
|
64
|
+
"@shivaedev/rate-limit": "0.5.0",
|
|
65
|
+
"@shivaedev/test-kits": "0.3.1",
|
|
66
|
+
"@shivaedev/test-sql": "0.21.0",
|
|
67
|
+
"@shivaedev/test-story": "0.39.0",
|
|
68
68
|
"@types/node": "24.19.2",
|
|
69
69
|
"better-auth": "1.7.14",
|
|
70
70
|
"effect": "4.0.6",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"@effect/platform-node": "4.0.6",
|
|
77
77
|
"@effect/sql-pg": "4.0.6",
|
|
78
78
|
"@effect/vitest": "4.0.6",
|
|
79
|
-
"@shivaedev/admin": "0.
|
|
80
|
-
"@shivaedev/test-sql": "0.
|
|
79
|
+
"@shivaedev/admin": "0.20.1",
|
|
80
|
+
"@shivaedev/test-sql": "0.21.0",
|
|
81
81
|
"better-auth": "1.7.14",
|
|
82
82
|
"effect": "4.0.6"
|
|
83
83
|
},
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { type LocalTraceRow, traceJson } from "#localTraceRow.ts";
|
|
6
|
+
|
|
7
|
+
export function localTraceDatabase(path: string, retainedRuns: number, indexedAttributes: readonly string[], startedAtMillis: number) {
|
|
8
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
9
|
+
const db = new DatabaseSync(path, { timeout: 1000 });
|
|
10
|
+
try {
|
|
11
|
+
db.exec(`
|
|
12
|
+
PRAGMA journal_mode = WAL;
|
|
13
|
+
PRAGMA foreign_keys = ON;
|
|
14
|
+
CREATE TABLE IF NOT EXISTS runs (id TEXT PRIMARY KEY, started_at_millis INTEGER NOT NULL, completed INTEGER NOT NULL DEFAULT 0);
|
|
15
|
+
CREATE TABLE IF NOT EXISTS spans (
|
|
16
|
+
run_id TEXT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
|
|
17
|
+
span_id TEXT PRIMARY KEY, trace_id TEXT NOT NULL, parent_span_id TEXT,
|
|
18
|
+
name TEXT NOT NULL, started_at_millis INTEGER NOT NULL, data TEXT NOT NULL
|
|
19
|
+
);
|
|
20
|
+
CREATE INDEX IF NOT EXISTS spans_trace ON spans(trace_id, started_at_millis);
|
|
21
|
+
CREATE TABLE IF NOT EXISTS span_attributes (
|
|
22
|
+
span_id TEXT NOT NULL REFERENCES spans(span_id) ON DELETE CASCADE,
|
|
23
|
+
key TEXT NOT NULL, value TEXT NOT NULL
|
|
24
|
+
);
|
|
25
|
+
CREATE INDEX IF NOT EXISTS span_attributes_lookup ON span_attributes(key, value, span_id);
|
|
26
|
+
CREATE VIEW IF NOT EXISTS logs AS
|
|
27
|
+
SELECT run_id, trace_id, parent_span_id AS span_id, started_at_millis AS at_millis,
|
|
28
|
+
json_extract(data, '$.events[0].attributes') AS data FROM spans WHERE name = 'effect.log';
|
|
29
|
+
`);
|
|
30
|
+
const runId = randomUUID();
|
|
31
|
+
db.prepare("INSERT INTO runs(id, started_at_millis) VALUES (?, ?)").run(runId, startedAtMillis);
|
|
32
|
+
const complete = db.prepare("UPDATE runs SET completed = (SELECT coalesce(max(completed), 0) + 1 FROM runs) WHERE id = ?");
|
|
33
|
+
const prune = db.prepare(
|
|
34
|
+
"DELETE FROM runs WHERE completed > 0 AND id NOT IN (SELECT id FROM runs WHERE completed > 0 ORDER BY completed DESC LIMIT ?)",
|
|
35
|
+
);
|
|
36
|
+
const insert = db.prepare("INSERT INTO spans VALUES (?, ?, ?, ?, ?, ?, ?)");
|
|
37
|
+
const index = db.prepare("INSERT INTO span_attributes VALUES (?, ?, ?)");
|
|
38
|
+
const indexed = new Set(indexedAttributes);
|
|
39
|
+
function append(row: LocalTraceRow) {
|
|
40
|
+
insert.run(runId, row.spanId, row.traceId, row.parentSpanId, row.name, row.startedAtMillis, traceJson(row));
|
|
41
|
+
for (const key of indexed) {
|
|
42
|
+
const value = row.attributes[key];
|
|
43
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
44
|
+
index.run(row.spanId, key, String(value));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
close: () => {
|
|
50
|
+
try {
|
|
51
|
+
complete.run(runId);
|
|
52
|
+
prune.run(retainedRuns);
|
|
53
|
+
} finally {
|
|
54
|
+
db.close();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
write: (rows: readonly LocalTraceRow[]) => {
|
|
58
|
+
db.exec("BEGIN");
|
|
59
|
+
try {
|
|
60
|
+
for (const row of rows) {
|
|
61
|
+
append(row);
|
|
62
|
+
}
|
|
63
|
+
db.exec("COMMIT");
|
|
64
|
+
} catch (error) {
|
|
65
|
+
db.exec("ROLLBACK");
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
db.close();
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
package/src/development.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface DevelopmentOptions {
|
|
|
12
12
|
|
|
13
13
|
export const development = Effect.fn("Platform.development")(function* ({ server, worker, conditions = [] }: DevelopmentOptions) {
|
|
14
14
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
15
|
-
const options = { stderr: "inherit", stdout: "inherit" } as const;
|
|
15
|
+
const options = { env: { "NODE_ENV": "development" }, extendEnv: true, stderr: "inherit", stdout: "inherit" } as const;
|
|
16
16
|
const args = [...conditions.map((condition) => `--conditions=${condition}`), "--watch"];
|
|
17
17
|
return yield* Effect.raceAll([
|
|
18
18
|
spawner.exitCode(ChildProcess.make(process.execPath, [...args, server], options)),
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Cause, Exit, Option, type Tracer } from "effect";
|
|
2
|
+
import { redactRecord } from "@shivaedev/errors/redact.ts";
|
|
3
|
+
import { redactDiagnosticCause } from "@shivaedev/errors/redactCause.ts";
|
|
4
|
+
import { redactText, type SensitiveKey } from "@shivaedev/errors/sensitive.ts";
|
|
5
|
+
import { type HostRedactionPolicy, redactionForRpc } from "#RedactionPolicy.ts";
|
|
6
|
+
|
|
7
|
+
export type LocalTraceEvent = readonly [name: string, time: bigint, attributes: Record<string, unknown>];
|
|
8
|
+
|
|
9
|
+
function rpcMethod(span: Tracer.Span): unknown {
|
|
10
|
+
const method = span.attributes.get("rpc.method");
|
|
11
|
+
const parent = Option.getOrUndefined(span.parent);
|
|
12
|
+
return method ?? (parent?._tag === "Span" ? rpcMethod(parent) : undefined);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function traceError(cause: Cause.Cause<unknown>, sensitive: SensitiveKey): string {
|
|
16
|
+
return Cause.prettyErrors(cause)
|
|
17
|
+
.map((error) => Cause.pretty(redactDiagnosticCause(Cause.fail(error), sensitive)))
|
|
18
|
+
.join("\n");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function localTraceRow(span: Tracer.Span, events: readonly LocalTraceEvent[], policy: HostRedactionPolicy) {
|
|
22
|
+
if (span.status._tag !== "Ended" || !span.sampled) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const sensitive = redactionForRpc(policy, rpcMethod(span));
|
|
26
|
+
const { startTime, endTime, exit } = span.status;
|
|
27
|
+
const attributes = redactRecord(Object.fromEntries(span.attributes), sensitive);
|
|
28
|
+
const failedStatus = Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause) ? "interrupted" : "failure";
|
|
29
|
+
return {
|
|
30
|
+
attributes,
|
|
31
|
+
durationNanos: String(endTime - startTime),
|
|
32
|
+
endedAtMillis: Number.parseInt(String(endTime / 1_000_000n), 10),
|
|
33
|
+
error: Exit.isFailure(exit) ? redactText(traceError(exit.cause, sensitive), sensitive) : null,
|
|
34
|
+
events: events.map(([name, time, values]) => ({
|
|
35
|
+
attributes: redactRecord(values, sensitive),
|
|
36
|
+
name: redactText(name, sensitive),
|
|
37
|
+
time: String(time),
|
|
38
|
+
})),
|
|
39
|
+
kind: span.kind,
|
|
40
|
+
links: span.links.map(({ span: linked, attributes: values }) => ({
|
|
41
|
+
attributes: redactRecord(values, sensitive),
|
|
42
|
+
spanId: linked.spanId,
|
|
43
|
+
traceId: linked.traceId,
|
|
44
|
+
})),
|
|
45
|
+
name: redactText(span.name, sensitive),
|
|
46
|
+
parentSpanId: Option.getOrUndefined(span.parent)?.spanId ?? null,
|
|
47
|
+
spanId: span.spanId,
|
|
48
|
+
startedAtMillis: Number.parseInt(String(startTime / 1_000_000n), 10),
|
|
49
|
+
status: Exit.isSuccess(exit) ? "success" : failedStatus,
|
|
50
|
+
traceId: span.traceId,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type LocalTraceRow = NonNullable<ReturnType<typeof localTraceRow>>;
|
|
55
|
+
|
|
56
|
+
export function traceJson(value: unknown): string {
|
|
57
|
+
return JSON.stringify(value, (_key, nested: unknown) => (typeof nested === "bigint" ? String(nested) : nested));
|
|
58
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Clock, Effect, Layer, Tracer } from "effect";
|
|
2
|
+
import { localTraceDatabase } from "#adapters/localTraceDatabase.ts";
|
|
3
|
+
import { traceDiagnostics } from "#adapters/traceDiagnostics.ts";
|
|
4
|
+
import { type LocalTraceEvent, type LocalTraceRow, localTraceRow } from "#localTraceRow.ts";
|
|
5
|
+
import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
6
|
+
import { redactingDiagnostics } from "#redactingDiagnostics.ts";
|
|
7
|
+
|
|
8
|
+
export interface LocalTracingOptions {
|
|
9
|
+
readonly clock?: Clock.Clock;
|
|
10
|
+
readonly flushInterval?: number;
|
|
11
|
+
readonly indexedAttributes?: readonly string[];
|
|
12
|
+
readonly path?: string;
|
|
13
|
+
readonly retainedRuns?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function localTracing({
|
|
17
|
+
clock = Clock.Clock.defaultValue(),
|
|
18
|
+
path = ".platform/traces.db",
|
|
19
|
+
indexedAttributes = [],
|
|
20
|
+
retainedRuns = 5,
|
|
21
|
+
flushInterval = 1000,
|
|
22
|
+
}: LocalTracingOptions = {}) {
|
|
23
|
+
return Layer.unwrap(
|
|
24
|
+
Effect.gen(function* () {
|
|
25
|
+
const policy = yield* RedactionPolicy;
|
|
26
|
+
const underlying = yield* Tracer.Tracer;
|
|
27
|
+
const startedAtMillis = yield* Clock.currentTimeMillis;
|
|
28
|
+
const database = yield* Effect.acquireRelease(
|
|
29
|
+
Effect.try(() => localTraceDatabase(path, retainedRuns, indexedAttributes, startedAtMillis)),
|
|
30
|
+
(db) => Effect.sync(() => db.close()),
|
|
31
|
+
);
|
|
32
|
+
let pending: LocalTraceRow[] = [];
|
|
33
|
+
const flush = Effect.sync(() => {
|
|
34
|
+
database.write(pending);
|
|
35
|
+
pending = [];
|
|
36
|
+
});
|
|
37
|
+
yield* Effect.addFinalizer(() => flush);
|
|
38
|
+
yield* Effect.sleep(flushInterval).pipe(Effect.andThen(flush), Effect.forever, Effect.provideService(Clock.Clock, clock), Effect.forkScoped);
|
|
39
|
+
const tracer = Tracer.make({
|
|
40
|
+
...underlying,
|
|
41
|
+
span: (options) => {
|
|
42
|
+
const span = underlying.span(options);
|
|
43
|
+
const events: LocalTraceEvent[] = [];
|
|
44
|
+
const event = span.event.bind(span);
|
|
45
|
+
const end = span.end.bind(span);
|
|
46
|
+
span.event = (name, time, attributes) => {
|
|
47
|
+
events.push([name, time, attributes ?? {}]);
|
|
48
|
+
event(name, time, attributes);
|
|
49
|
+
};
|
|
50
|
+
span.end = (time, exit) => {
|
|
51
|
+
end(time, exit);
|
|
52
|
+
const row = localTraceRow(span, events, policy);
|
|
53
|
+
if (row !== undefined) {
|
|
54
|
+
pending.push(row);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return span;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
return redactingDiagnostics(policy).pipe(Layer.provideMerge(traceDiagnostics), Layer.provideMerge(Layer.succeed(Tracer.Tracer, tracer)));
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
}
|
package/src/otlpTracing.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Config, Context, Effect, Layer, Schema } from "effect";
|
|
1
|
+
import { Config, ConfigProvider, Context, Effect, Layer, Schema } from "effect";
|
|
2
2
|
import { OtlpSerialization, OtlpTracer } from "effect/observability";
|
|
3
3
|
import { traceDiagnostics } from "#adapters/traceDiagnostics.ts";
|
|
4
|
+
import { localTracing } from "#localTracing.ts";
|
|
4
5
|
import { otlpHttpClient } from "#otlpHttpClient.ts";
|
|
5
6
|
import { RedactionPolicy } from "#RedactionPolicy.ts";
|
|
6
7
|
import { redactingDiagnostics } from "#redactingDiagnostics.ts";
|
|
@@ -22,6 +23,22 @@ export const otlpTracing: Layer.Layer<never, Config.ConfigError> = Layer.effectC
|
|
|
22
23
|
Config.withDefault(undefined),
|
|
23
24
|
));
|
|
24
25
|
if (endpoint === undefined) {
|
|
26
|
+
const mode = yield* Config.String("NODE_ENV").pipe(Config.withDefault("production"));
|
|
27
|
+
if (mode === "development") {
|
|
28
|
+
const path = yield* Config.String("PLATFORM_TRACE_STORE").pipe(Config.withDefault(".platform/traces.db"));
|
|
29
|
+
const indexed = yield* Config.String("PLATFORM_TRACE_INDEXED_ATTRIBUTES").pipe(Config.withDefault(""));
|
|
30
|
+
return yield* Layer.build(
|
|
31
|
+
localTracing({
|
|
32
|
+
indexedAttributes: indexed
|
|
33
|
+
.split(",")
|
|
34
|
+
.map((key) => key.trim())
|
|
35
|
+
.filter(Boolean),
|
|
36
|
+
path,
|
|
37
|
+
}),
|
|
38
|
+
).pipe(
|
|
39
|
+
Effect.mapError((cause) => new Config.ConfigError(new ConfigProvider.SourceError({ cause, message: "Cannot open local trace store" }))),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
25
42
|
return Context.empty();
|
|
26
43
|
}
|
|
27
44
|
const configuredProtocol = yield* Config.String("OTEL_EXPORTER_OTLP_TRACES_PROTOCOL").pipe(
|