better-schemic 0.1.0-beta.2 → 0.1.0-beta.4

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
@@ -33,6 +33,7 @@ replay into — `npm i -D @surrealdb/node`).
33
33
  | `better-schemic/query` | fragments & procedural SurrealQL |
34
34
  | `better-schemic/plugins/*` | the authoring plugins |
35
35
  | `better-schemic/logger` | the query logger |
36
+ | `better-schemic/otel` | OpenTelemetry tracing (`createOtelLogger`) |
36
37
  | `better-schemic/driver` | the engine entry (CLI/engine-only — pulls in the DDL emitter) |
37
38
 
38
39
  ## Quick start
@@ -549,6 +550,57 @@ import { createQueryLogger } from "better-schemic/logger";
549
550
  const client = betterSchemic(db, { schema, logger: createQueryLogger({ format: "json" }) });
550
551
  ```
551
552
 
553
+ ### OTEL tracing (`better-schemic/otel`)
554
+
555
+ One OpenTelemetry **client span per executor round-trip** — delegates, `$raw`/`$query`/`$unsafe`,
556
+ `fn`, admin, changes, live setup and `.explain()` plans. No plugin and no hook wiring: the OTEL
557
+ logger is a `QueryLogger` on the same executor seam as `better-schemic/logger`, so it observes
558
+ exactly what runs and nothing else.
559
+
560
+ ```bash
561
+ bun add better-schemic @opentelemetry/api
562
+ ```
563
+
564
+ ```ts
565
+ import { createOtelLogger } from "better-schemic/otel";
566
+
567
+ const client = betterSchemic(db, {
568
+ schema,
569
+ logger: createOtelLogger({
570
+ captureQueryText: true, // default; false omits db.query.text entirely
571
+ maxQueryTextLength: 1000, // default
572
+ attributes: { "deployment.environment.name": "production" },
573
+ }),
574
+ });
575
+ ```
576
+
577
+ Register the SDK once in the app entry. `service.name` is a **resource** attribute, not a span
578
+ attribute — the logger never sets it for you:
579
+
580
+ ```ts
581
+ import { NodeSDK } from "@opentelemetry/sdk-node";
582
+ import { resourceFromAttributes } from "@opentelemetry/resources";
583
+
584
+ new NodeSDK({
585
+ resource: resourceFromAttributes({ "service.name": "my-app" }),
586
+ }).start();
587
+ ```
588
+
589
+ Spans use the stable database semantic conventions: `db.system.name` (`surrealdb`),
590
+ `db.operation.name` (`SELECT`, `BATCH SELECT`, `EXPLAIN`, …), `db.collection.name`,
591
+ `db.namespace` (`namespace|database`), `db.query.text` (opt-out), `db.operation.batch.size`, and
592
+ on failure `error.type` + `db.response.status_code`. `error.type` is the error class — the SDK
593
+ `kind` (`"Thrown"`, `"Validation"`, `"Internal"`, ...) or the normalized code (`"ParseError"`,
594
+ `"ValidationError"`, ...) — never a high-cardinality message; `db.response.status_code` is the raw
595
+ SurrealDB code (`-32000`, `ERR_LOCKED`, ...). Binds are **never** captured.
596
+
597
+ > **PII:** `db.query.text` is the compiled SurrealQL. ORM statements are parameterized (`$p0`), but a
598
+ > `$raw`/`$unsafe` statement can contain literals — set `captureQueryText: false` when that matters.
599
+
600
+ - `enabled: false` keeps the option in place while the executor skips every event (zero overhead).
601
+ - It is a normal `logger:` option, so it composes with any custom `QueryLogger`; only one logger can
602
+ be attached per client.
603
+ - OTEL does not auto-`EXPLAIN`; an explicit `.explain()` is traced as its own span.
552
604
 
553
605
  `client.users.$model` is the delegate metadata; `client.repository("user")` looks
554
606
  up by schema key OR physical name; `client.tables` lists the keys; `client.$sdk`
package/lib/cli/index.js CHANGED
@@ -4763,7 +4763,7 @@ import { dirname as dirname5, join as join6, relative as relative5 } from "node:
4763
4763
  import { createInterface as createInterface2 } from "node:readline/promises";
4764
4764
  import { Command, Help, Option } from "commander";
4765
4765
  // package.json
4766
- var version = "0.1.0-beta.2";
4766
+ var version = "0.1.0-beta.4";
4767
4767
 
4768
4768
  // src/surreal/driver.ts
4769
4769
  init_core();
@@ -10982,5 +10982,5 @@ async function bootstrap() {
10982
10982
  }
10983
10983
  bootstrap();
10984
10984
 
10985
- //# debugId=BCDA2BDB44B18DE364756E2164756E21
10985
+ //# debugId=C9FBDD1C1F3F8CF664756E2164756E21
10986
10986
  //# sourceMappingURL=index.js.map