datanotes 2.0.1 → 3.1.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/NOTICE +9 -0
- package/README.md +203 -28
- package/SECURITY.md +92 -45
- package/dist/THIRD-PARTY-NOTICES.txt +682 -0
- package/dist/api/catalog.d.cts +69 -0
- package/dist/api/catalog.d.ts +50 -2
- package/dist/api/cli-options.d.cts +39 -0
- package/dist/api/cli-options.d.ts +39 -0
- package/dist/api/client.d.cts +122 -0
- package/dist/api/client.d.ts +56 -34
- package/dist/api/docs.d.cts +211 -0
- package/dist/api/docs.d.ts +211 -0
- package/dist/api/guidance.d.cts +81 -0
- package/dist/api/guidance.d.ts +81 -0
- package/dist/api/index.cjs +7470 -2771
- package/dist/api/index.d.cts +14 -0
- package/dist/api/index.d.ts +11 -7
- package/dist/api/index.js +7470 -2771
- package/dist/api/local.cjs +118 -6
- package/dist/api/local.d.cts +95 -0
- package/dist/api/local.d.ts +70 -6
- package/dist/api/local.js +104 -6
- package/dist/api/mcp.cjs +17387 -0
- package/dist/api/mcp.d.cts +108 -0
- package/dist/api/mcp.d.ts +108 -0
- package/dist/api/mcp.js +17337 -0
- package/dist/api/otlp.d.cts +113 -0
- package/dist/api/otlp.d.ts +63 -15
- package/dist/api/redact.d.cts +42 -0
- package/dist/api/redact.d.ts +42 -0
- package/dist/api/requests.d.cts +26 -0
- package/dist/api/requests.d.ts +14 -16
- package/dist/api/results.d.cts +16 -0
- package/dist/api/results.d.ts +2 -1
- package/dist/api/tokens.d.cts +12 -0
- package/dist/api/tokens.d.ts +5 -0
- package/dist/api/tracing.d.cts +107 -0
- package/dist/api/tracing.d.ts +107 -0
- package/dist/datanotes.cjs +69597 -28329
- package/dist/docs/administration/configuration.md +59 -0
- package/dist/docs/administration/docker.md +80 -0
- package/dist/docs/administration/git-sync.md +71 -0
- package/dist/docs/administration/limits.md +153 -0
- package/dist/docs/administration/run-the-service.md +237 -0
- package/dist/docs/administration/status.md +61 -0
- package/dist/docs/administration/use-with-obsidian.md +75 -0
- package/dist/docs/api/operations/add_column.md +49 -0
- package/dist/docs/api/operations/add_constraint.md +55 -0
- package/dist/docs/api/operations/adopt_rows.md +50 -0
- package/dist/docs/api/operations/align_relations.md +41 -0
- package/dist/docs/api/operations/alter_column.md +46 -0
- package/dist/docs/api/operations/alter_table.md +67 -0
- package/dist/docs/api/operations/batch.md +48 -0
- package/dist/docs/api/operations/changes_stream.md +28 -0
- package/dist/docs/api/operations/check_table.md +29 -0
- package/dist/docs/api/operations/clone_table.md +48 -0
- package/dist/docs/api/operations/comment_on.md +42 -0
- package/dist/docs/api/operations/configure_database.md +52 -0
- package/dist/docs/api/operations/create_table.md +78 -0
- package/dist/docs/api/operations/create_view.md +54 -0
- package/dist/docs/api/operations/create_webhook.md +37 -0
- package/dist/docs/api/operations/define_base.md +52 -0
- package/dist/docs/api/operations/delete_rows.md +43 -0
- package/dist/docs/api/operations/delete_webhook.md +31 -0
- package/dist/docs/api/operations/describe_database.md +30 -0
- package/dist/docs/api/operations/describe_history.md +40 -0
- package/dist/docs/api/operations/describe_semantic_index.md +24 -0
- package/dist/docs/api/operations/describe_table.md +38 -0
- package/dist/docs/api/operations/docs.md +13 -0
- package/dist/docs/api/operations/drop_column.md +41 -0
- package/dist/docs/api/operations/drop_constraint.md +39 -0
- package/dist/docs/api/operations/drop_table.md +43 -0
- package/dist/docs/api/operations/drop_view.md +38 -0
- package/dist/docs/api/operations/engine_status.md +23 -0
- package/dist/docs/api/operations/graph_neighbors.md +34 -0
- package/dist/docs/api/operations/graph_path.md +32 -0
- package/dist/docs/api/operations/graph_traverse.md +43 -0
- package/dist/docs/api/operations/identify_session.md +24 -0
- package/dist/docs/api/operations/infer_table.md +43 -0
- package/dist/docs/api/operations/insert_row.md +48 -0
- package/dist/docs/api/operations/list_changes.md +35 -0
- package/dist/docs/api/operations/list_folder.md +28 -0
- package/dist/docs/api/operations/list_link_targets.md +44 -0
- package/dist/docs/api/operations/list_migrations.md +35 -0
- package/dist/docs/api/operations/list_tables.md +32 -0
- package/dist/docs/api/operations/list_webhooks.md +23 -0
- package/dist/docs/api/operations/manual_index.md +14 -0
- package/dist/docs/api/operations/manual_page.md +22 -0
- package/dist/docs/api/operations/merge_rows.md +44 -0
- package/dist/docs/api/operations/move_rows.md +52 -0
- package/dist/docs/api/operations/openapi.md +13 -0
- package/dist/docs/api/operations/openapi_post.md +20 -0
- package/dist/docs/api/operations/read_note.md +29 -0
- package/dist/docs/api/operations/recompute_columns.md +44 -0
- package/dist/docs/api/operations/record_tool_call.md +37 -0
- package/dist/docs/api/operations/rename_column.md +44 -0
- package/dist/docs/api/operations/rename_value.md +45 -0
- package/dist/docs/api/operations/restore_database.md +51 -0
- package/dist/docs/api/operations/restore_table.md +46 -0
- package/dist/docs/api/operations/search_notes.md +28 -0
- package/dist/docs/api/operations/select_rows.md +61 -0
- package/dist/docs/api/operations/semantic_search.md +34 -0
- package/dist/docs/api/operations/semantic_search_docs.md +26 -0
- package/dist/docs/api/operations/set_table_bases.md +44 -0
- package/dist/docs/api/operations/status.md +13 -0
- package/dist/docs/api/operations/stop_engine.md +23 -0
- package/dist/docs/api/operations/sync_semantic_index.md +33 -0
- package/dist/docs/api/operations/table_changes.md +31 -0
- package/dist/docs/api/operations/tags/auxiliary.md +14 -0
- package/dist/docs/api/operations/tags/change-feed.md +8 -0
- package/dist/docs/api/operations/tags/history.md +17 -0
- package/dist/docs/api/operations/tags/queries.md +15 -0
- package/dist/docs/api/operations/tags/rows-dml.md +16 -0
- package/dist/docs/api/operations/tags/schema-ddl.md +22 -0
- package/dist/docs/api/operations/tags/service.md +15 -0
- package/dist/docs/api/operations/tags/tokens.md +13 -0
- package/dist/docs/api/operations/tokens_create.md +34 -0
- package/dist/docs/api/operations/tokens_delete.md +29 -0
- package/dist/docs/api/operations/tokens_list.md +21 -0
- package/dist/docs/api/operations/tokens_me.md +20 -0
- package/dist/docs/api/operations/tokens_rotate.md +29 -0
- package/dist/docs/api/operations/tokens_update.md +34 -0
- package/dist/docs/api/operations/undo_migration.md +46 -0
- package/dist/docs/api/operations/update_row.md +60 -0
- package/dist/docs/api/operations/update_rows.md +46 -0
- package/dist/docs/api/operations/vacuum_table.md +37 -0
- package/dist/docs/api.md +135 -0
- package/dist/docs/develop/build-an-app.md +320 -0
- package/dist/docs/develop/build-on-datanotes.md +138 -0
- package/dist/docs/develop/change-feed-and-webhooks.md +70 -0
- package/dist/docs/develop/client.md +116 -0
- package/dist/docs/develop/concurrency.md +188 -0
- package/dist/docs/develop/http-api.md +89 -0
- package/dist/docs/develop/telemetry.md +285 -0
- package/dist/docs/guides/agents/docs-offline.md +99 -0
- package/dist/docs/guides/agents/how-agents-use-datanotes.md +124 -0
- package/dist/docs/guides/agents/prompts.md +495 -0
- package/dist/docs/guides/agents/reading-errors.md +112 -0
- package/dist/docs/guides/data-quality/check-constraints.md +379 -0
- package/dist/docs/guides/data-quality/check-table.md +63 -0
- package/dist/docs/guides/data-quality/hand-edits.md +507 -0
- package/dist/docs/guides/data-quality/sync-between-devices.md +51 -0
- package/dist/docs/guides/data-quality/validation.md +90 -0
- package/dist/docs/guides/database-objects/bases.md +480 -0
- package/dist/docs/guides/database-objects/catalogs-and-schemas.md +897 -0
- package/dist/docs/guides/database-objects/columns.md +1332 -0
- package/dist/docs/guides/database-objects/relations.md +1454 -0
- package/dist/docs/guides/database-objects/tables.md +1340 -0
- package/dist/docs/guides/database-objects/views.md +1003 -0
- package/dist/docs/guides/history/back-up.md +203 -0
- package/dist/docs/guides/history/change-data-feed.md +247 -0
- package/dist/docs/guides/history/journal-and-undo.md +262 -0
- package/dist/docs/guides/history/restore.md +341 -0
- package/dist/docs/guides/history/table-history.md +657 -0
- package/dist/docs/guides/history/vacuum.md +26 -0
- package/dist/docs/guides/read-and-write/automatic-links.md +768 -0
- package/dist/docs/guides/read-and-write/batch.md +139 -0
- package/dist/docs/guides/read-and-write/import-notes.md +896 -0
- package/dist/docs/guides/read-and-write/joins-and-aggregates.md +251 -0
- package/dist/docs/guides/read-and-write/read-and-filter.md +536 -0
- package/dist/docs/guides/read-and-write/write-rows.md +573 -0
- package/dist/docs/guides/search/link-graph.md +241 -0
- package/dist/docs/guides/search/semantic.md +133 -0
- package/dist/docs/guides/search/text.md +142 -0
- package/dist/docs/guides/security/security-model.md +110 -0
- package/dist/docs/guides/security/tokens.md +60 -0
- package/dist/docs/guides/security/who-did-what.md +44 -0
- package/dist/docs/index.md +113 -0
- package/dist/docs/llms.txt +33 -0
- package/dist/docs/reference/cli.md +143 -0
- package/dist/docs/reference/compatibility.md +83 -0
- package/dist/docs/reference/errors.md +72 -0
- package/dist/docs/reference/glossary.md +161 -0
- package/dist/docs/reference/operations/auxiliary.md +116 -0
- package/dist/docs/reference/operations/history.md +168 -0
- package/dist/docs/reference/operations/queries.md +169 -0
- package/dist/docs/reference/operations/rows.md +185 -0
- package/dist/docs/reference/operations/schema.md +316 -0
- package/dist/docs/reference/operations.md +96 -0
- package/dist/docs/reference/settings.md +43 -0
- package/dist/docs/release-notes.md +188 -0
- package/dist/docs/start/connect-agents.md +204 -0
- package/dist/docs/start/how-it-works.md +349 -0
- package/dist/docs/start/quick-start.md +128 -0
- package/package.json +60 -15
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTelemetry export over OTLP/HTTP, vendor-neutral: log records (`OtlpLogExporter`, to
|
|
3
|
+
* `<endpoint>/v1/logs`) and spans (`OtlpTraceExporter`, to `<endpoint>/v1/traces`) are buffered
|
|
4
|
+
* and POSTed as `http/protobuf` (the OTLP default) or `http/json`, which every OpenTelemetry
|
|
5
|
+
* collector and OTLP backend reads. No dependency, no SDK. Export failures are counted, never
|
|
6
|
+
* thrown: telemetry must not break the program. (OTLP over gRPC is not supported: use the
|
|
7
|
+
* collector's HTTP port, 4318 by default.)
|
|
8
|
+
*
|
|
9
|
+
* A log record made inside a span names it (`log`'s `context`), so the backend links the two.
|
|
10
|
+
* Configure the exporters in code, or from the standard OpenTelemetry variables with
|
|
11
|
+
* `otlpFromEnv` and `otlpTracesFromEnv`.
|
|
12
|
+
*/
|
|
13
|
+
import type { SpanRecord, TraceContext } from "./tracing.cjs";
|
|
14
|
+
export type Severity = "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
15
|
+
export type AttrValue = string | number | boolean | null | undefined;
|
|
16
|
+
export type OtlpProtocol = "http/protobuf" | "http/json";
|
|
17
|
+
export interface OtlpOptions {
|
|
18
|
+
/** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` or `/v1/traces` is added). */
|
|
19
|
+
endpoint: string;
|
|
20
|
+
/** `service.name` of the records. */
|
|
21
|
+
serviceName: string;
|
|
22
|
+
serviceVersion?: string;
|
|
23
|
+
/** `http/protobuf` (default) or `http/json`. */
|
|
24
|
+
protocol?: OtlpProtocol;
|
|
25
|
+
/** Extra headers, e.g. an API key or `Authorization`, as the backend asks. */
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
/** More resource attributes (e.g. `host.name`). */
|
|
28
|
+
resource?: Record<string, AttrValue>;
|
|
29
|
+
/** Send at most this many records (or spans) per request (default 50 records, 512 spans); a full buffer is sent at once. */
|
|
30
|
+
maxBatch?: number;
|
|
31
|
+
/** Send the buffer every this many ms (default 5000; 0: only on `flush`). */
|
|
32
|
+
flushMs?: number;
|
|
33
|
+
/** POST a body; resolves on 2xx (default: fetch). `headers` include the Content-Type. */
|
|
34
|
+
send?: (url: string, body: string | Uint8Array, headers: Record<string, string>) => Promise<void>;
|
|
35
|
+
now?: () => number;
|
|
36
|
+
}
|
|
37
|
+
interface LogRecord {
|
|
38
|
+
timeUnixNano: string;
|
|
39
|
+
severity: Severity;
|
|
40
|
+
body: string;
|
|
41
|
+
attributes: Record<string, AttrValue>;
|
|
42
|
+
context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">;
|
|
43
|
+
}
|
|
44
|
+
/** Unix ms (with a fraction) as OTLP nanoseconds, a decimal string. */
|
|
45
|
+
export declare function unixNano(ms: number): string;
|
|
46
|
+
/** What both exporters share: the buffer, the timer, the POST, the counts. */
|
|
47
|
+
declare abstract class OtlpBatcher<T> {
|
|
48
|
+
protected readonly o: OtlpOptions;
|
|
49
|
+
private readonly path;
|
|
50
|
+
private readonly maxBatch;
|
|
51
|
+
protected buffer: T[];
|
|
52
|
+
private inflight;
|
|
53
|
+
private timer;
|
|
54
|
+
/** Items sent, and items lost because the collector did not take them (or the buffer was full). */
|
|
55
|
+
sent: number;
|
|
56
|
+
dropped: number;
|
|
57
|
+
constructor(o: OtlpOptions, path: string, maxBatch: number);
|
|
58
|
+
protected push(items: readonly T[]): void;
|
|
59
|
+
protected resource(): Record<string, AttrValue>;
|
|
60
|
+
protected abstract encode(batch: T[], protobuf: boolean): string | Uint8Array;
|
|
61
|
+
/** Send what is buffered. Never rejects. */
|
|
62
|
+
flush(): Promise<void>;
|
|
63
|
+
/** Stop the timer and send what is left. */
|
|
64
|
+
close(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export declare class OtlpLogExporter extends OtlpBatcher<LogRecord> {
|
|
67
|
+
constructor(o: OtlpOptions);
|
|
68
|
+
/** Buffer a record; `context`: the span it was made in (its trace and span id go with it). */
|
|
69
|
+
log(severity: Severity, body: string, attributes?: Record<string, AttrValue>, context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">): void;
|
|
70
|
+
protected encode(batch: LogRecord[], protobuf: boolean): string | Uint8Array;
|
|
71
|
+
private protobuf;
|
|
72
|
+
}
|
|
73
|
+
/** Spans to `<endpoint>/v1/traces` (ExportTraceServiceRequest), in batches. */
|
|
74
|
+
export declare class OtlpTraceExporter extends OtlpBatcher<SpanRecord> {
|
|
75
|
+
constructor(o: OtlpOptions);
|
|
76
|
+
/** Buffer finished spans (sent with the next batch). Never throws. */
|
|
77
|
+
export(spans: SpanRecord | readonly SpanRecord[]): void;
|
|
78
|
+
protected encode(batch: SpanRecord[], protobuf: boolean): string | Uint8Array;
|
|
79
|
+
private protobuf;
|
|
80
|
+
}
|
|
81
|
+
/** `k1=v1,k2=v2` (values URL-encoded), the format of `OTEL_EXPORTER_OTLP_HEADERS`. */
|
|
82
|
+
export declare function parseOtlpHeaders(text: string | undefined): Record<string, string>;
|
|
83
|
+
/** `k1=v1,k2=v2` resource attributes, the format of `OTEL_RESOURCE_ATTRIBUTES`. */
|
|
84
|
+
export declare const parseResourceAttributes: typeof parseOtlpHeaders;
|
|
85
|
+
/**
|
|
86
|
+
* Exporter options from the standard OpenTelemetry variables, or null when export is off (no
|
|
87
|
+
* endpoint, `OTEL_SDK_DISABLED=true` or `OTEL_LOGS_EXPORTER=none`):
|
|
88
|
+
* `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` (full URL of /v1/logs) or `OTEL_EXPORTER_OTLP_ENDPOINT`;
|
|
89
|
+
* `OTEL_EXPORTER_OTLP_[LOGS_]HEADERS`; `OTEL_EXPORTER_OTLP_[LOGS_]PROTOCOL` (`http/protobuf`,
|
|
90
|
+
* `http/json`); `OTEL_SERVICE_NAME`; `OTEL_RESOURCE_ATTRIBUTES`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function otlpFromEnv(env: Record<string, string | undefined>, defaults: {
|
|
93
|
+
serviceName: string;
|
|
94
|
+
serviceVersion?: string;
|
|
95
|
+
}): OtlpOptions | null;
|
|
96
|
+
/**
|
|
97
|
+
* The same for traces: `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` (full URL of /v1/traces) or
|
|
98
|
+
* `OTEL_EXPORTER_OTLP_ENDPOINT`; the `…_TRACES_…` headers and protocol; null also when
|
|
99
|
+
* `OTEL_TRACES_EXPORTER=none`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function otlpTracesFromEnv(env: Record<string, string | undefined>, defaults: {
|
|
102
|
+
serviceName: string;
|
|
103
|
+
serviceVersion?: string;
|
|
104
|
+
}): OtlpOptions | null;
|
|
105
|
+
/**
|
|
106
|
+
* The share of new traces to keep, from `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
|
|
107
|
+
* (`always_on`, `always_off`, `traceidratio`, and their `parentbased_` forms: a trace continued
|
|
108
|
+
* from a caller always follows the caller); undefined when they say nothing usable.
|
|
109
|
+
*/
|
|
110
|
+
export declare function samplerRatioFromEnv(env: Record<string, string | undefined>): number | undefined;
|
|
111
|
+
/** `http/protobuf` or `http/json` from a setting or variable; undefined for anything else. */
|
|
112
|
+
export declare function otlpProtocol(v: string | undefined): OtlpProtocol | undefined;
|
|
113
|
+
export {};
|
package/dist/api/otlp.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpenTelemetry
|
|
3
|
-
* `<endpoint>/v1/logs`
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* OpenTelemetry export over OTLP/HTTP, vendor-neutral: log records (`OtlpLogExporter`, to
|
|
3
|
+
* `<endpoint>/v1/logs`) and spans (`OtlpTraceExporter`, to `<endpoint>/v1/traces`) are buffered
|
|
4
|
+
* and POSTed as `http/protobuf` (the OTLP default) or `http/json`, which every OpenTelemetry
|
|
5
|
+
* collector and OTLP backend reads. No dependency, no SDK. Export failures are counted, never
|
|
6
|
+
* thrown: telemetry must not break the program. (OTLP over gRPC is not supported: use the
|
|
7
|
+
* collector's HTTP port, 4318 by default.)
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
+
* A log record made inside a span names it (`log`'s `context`), so the backend links the two.
|
|
10
|
+
* Configure the exporters in code, or from the standard OpenTelemetry variables with
|
|
11
|
+
* `otlpFromEnv` and `otlpTracesFromEnv`.
|
|
9
12
|
*/
|
|
13
|
+
import type { SpanRecord, TraceContext } from "./tracing.js";
|
|
10
14
|
export type Severity = "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
11
15
|
export type AttrValue = string | number | boolean | null | undefined;
|
|
12
16
|
export type OtlpProtocol = "http/protobuf" | "http/json";
|
|
13
17
|
export interface OtlpOptions {
|
|
14
|
-
/** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` is added). */
|
|
18
|
+
/** Collector base URL, e.g. `http://127.0.0.1:4318` (`/v1/logs` or `/v1/traces` is added). */
|
|
15
19
|
endpoint: string;
|
|
16
20
|
/** `service.name` of the records. */
|
|
17
21
|
serviceName: string;
|
|
@@ -22,7 +26,7 @@ export interface OtlpOptions {
|
|
|
22
26
|
headers?: Record<string, string>;
|
|
23
27
|
/** More resource attributes (e.g. `host.name`). */
|
|
24
28
|
resource?: Record<string, AttrValue>;
|
|
25
|
-
/** Send at most this many records per request (default 50); a full buffer is sent at once. */
|
|
29
|
+
/** Send at most this many records (or spans) per request (default 50 records, 512 spans); a full buffer is sent at once. */
|
|
26
30
|
maxBatch?: number;
|
|
27
31
|
/** Send the buffer every this many ms (default 5000; 0: only on `flush`). */
|
|
28
32
|
flushMs?: number;
|
|
@@ -30,22 +34,50 @@ export interface OtlpOptions {
|
|
|
30
34
|
send?: (url: string, body: string | Uint8Array, headers: Record<string, string>) => Promise<void>;
|
|
31
35
|
now?: () => number;
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
interface LogRecord {
|
|
38
|
+
timeUnixNano: string;
|
|
39
|
+
severity: Severity;
|
|
40
|
+
body: string;
|
|
41
|
+
attributes: Record<string, AttrValue>;
|
|
42
|
+
context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">;
|
|
43
|
+
}
|
|
44
|
+
/** Unix ms (with a fraction) as OTLP nanoseconds, a decimal string. */
|
|
45
|
+
export declare function unixNano(ms: number): string;
|
|
46
|
+
/** What both exporters share: the buffer, the timer, the POST, the counts. */
|
|
47
|
+
declare abstract class OtlpBatcher<T> {
|
|
48
|
+
protected readonly o: OtlpOptions;
|
|
49
|
+
private readonly path;
|
|
50
|
+
private readonly maxBatch;
|
|
51
|
+
protected buffer: T[];
|
|
36
52
|
private inflight;
|
|
37
53
|
private timer;
|
|
38
|
-
/**
|
|
54
|
+
/** Items sent, and items lost because the collector did not take them (or the buffer was full). */
|
|
39
55
|
sent: number;
|
|
40
56
|
dropped: number;
|
|
41
|
-
constructor(o: OtlpOptions);
|
|
42
|
-
|
|
57
|
+
constructor(o: OtlpOptions, path: string, maxBatch: number);
|
|
58
|
+
protected push(items: readonly T[]): void;
|
|
59
|
+
protected resource(): Record<string, AttrValue>;
|
|
60
|
+
protected abstract encode(batch: T[], protobuf: boolean): string | Uint8Array;
|
|
43
61
|
/** Send what is buffered. Never rejects. */
|
|
44
62
|
flush(): Promise<void>;
|
|
45
|
-
private protobuf;
|
|
46
63
|
/** Stop the timer and send what is left. */
|
|
47
64
|
close(): Promise<void>;
|
|
48
65
|
}
|
|
66
|
+
export declare class OtlpLogExporter extends OtlpBatcher<LogRecord> {
|
|
67
|
+
constructor(o: OtlpOptions);
|
|
68
|
+
/** Buffer a record; `context`: the span it was made in (its trace and span id go with it). */
|
|
69
|
+
log(severity: Severity, body: string, attributes?: Record<string, AttrValue>, context?: Pick<TraceContext, "traceId" | "spanId" | "sampled">): void;
|
|
70
|
+
protected encode(batch: LogRecord[], protobuf: boolean): string | Uint8Array;
|
|
71
|
+
private protobuf;
|
|
72
|
+
}
|
|
73
|
+
/** Spans to `<endpoint>/v1/traces` (ExportTraceServiceRequest), in batches. */
|
|
74
|
+
export declare class OtlpTraceExporter extends OtlpBatcher<SpanRecord> {
|
|
75
|
+
constructor(o: OtlpOptions);
|
|
76
|
+
/** Buffer finished spans (sent with the next batch). Never throws. */
|
|
77
|
+
export(spans: SpanRecord | readonly SpanRecord[]): void;
|
|
78
|
+
protected encode(batch: SpanRecord[], protobuf: boolean): string | Uint8Array;
|
|
79
|
+
private protobuf;
|
|
80
|
+
}
|
|
49
81
|
/** `k1=v1,k2=v2` (values URL-encoded), the format of `OTEL_EXPORTER_OTLP_HEADERS`. */
|
|
50
82
|
export declare function parseOtlpHeaders(text: string | undefined): Record<string, string>;
|
|
51
83
|
/** `k1=v1,k2=v2` resource attributes, the format of `OTEL_RESOURCE_ATTRIBUTES`. */
|
|
@@ -61,5 +93,21 @@ export declare function otlpFromEnv(env: Record<string, string | undefined>, def
|
|
|
61
93
|
serviceName: string;
|
|
62
94
|
serviceVersion?: string;
|
|
63
95
|
}): OtlpOptions | null;
|
|
96
|
+
/**
|
|
97
|
+
* The same for traces: `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` (full URL of /v1/traces) or
|
|
98
|
+
* `OTEL_EXPORTER_OTLP_ENDPOINT`; the `…_TRACES_…` headers and protocol; null also when
|
|
99
|
+
* `OTEL_TRACES_EXPORTER=none`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function otlpTracesFromEnv(env: Record<string, string | undefined>, defaults: {
|
|
102
|
+
serviceName: string;
|
|
103
|
+
serviceVersion?: string;
|
|
104
|
+
}): OtlpOptions | null;
|
|
105
|
+
/**
|
|
106
|
+
* The share of new traces to keep, from `OTEL_TRACES_SAMPLER` and `OTEL_TRACES_SAMPLER_ARG`
|
|
107
|
+
* (`always_on`, `always_off`, `traceidratio`, and their `parentbased_` forms: a trace continued
|
|
108
|
+
* from a caller always follows the caller); undefined when they say nothing usable.
|
|
109
|
+
*/
|
|
110
|
+
export declare function samplerRatioFromEnv(env: Record<string, string | undefined>): number | undefined;
|
|
64
111
|
/** `http/protobuf` or `http/json` from a setting or variable; undefined for anything else. */
|
|
65
112
|
export declare function otlpProtocol(v: string | undefined): OtlpProtocol | undefined;
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secrets out of recorded tool calls. A tool call becomes a `tool_call` event of the change feed,
|
|
3
|
+
* which the engine keeps in its store and the store backup commits and pushes: a webhook's secret
|
|
4
|
+
* or a token returned by a call must never get there. Removed are the arguments and result keys
|
|
5
|
+
* the catalogue marks `sensitive`, and, for any tool, the keys that name a secret
|
|
6
|
+
* ({@link SECRET_KEYS}), at any depth. A text (an error, a result sent as text) loses the values
|
|
7
|
+
* of those keys written as JSON.
|
|
8
|
+
*/
|
|
9
|
+
/** What a removed value becomes. */
|
|
10
|
+
export declare const REDACTED = "[redacted]";
|
|
11
|
+
/** Keys whose values are secrets, whatever the tool (compared without case, `_` or `-`). */
|
|
12
|
+
export declare const SECRET_KEYS: readonly ["secret", "token", "password", "apikey", "authorization", "httpservertoken", "accesstoken", "refreshtoken", "clientsecret"];
|
|
13
|
+
/** A tool call's arguments and result without their secrets (new objects; the call's own are kept). */
|
|
14
|
+
export declare function redactToolCall(tool: string, args: Record<string, unknown>, value: unknown): {
|
|
15
|
+
args: Record<string, unknown>;
|
|
16
|
+
value: unknown;
|
|
17
|
+
};
|
|
18
|
+
/** How many characters of a recorded call's result, and of each of its arguments, are kept. */
|
|
19
|
+
export declare const RECORDED_CHARS: {
|
|
20
|
+
readonly value: 1000;
|
|
21
|
+
readonly arg: 300;
|
|
22
|
+
};
|
|
23
|
+
/** A value as a recorded call keeps it: a text, or an object's JSON, longer than `n` characters is cut (with "…"). */
|
|
24
|
+
export declare function cutRecorded(v: unknown, n: number): unknown;
|
|
25
|
+
/** A result object in short: its first 30 fields, lists as their length, texts cut at 200 characters, nothing nested. */
|
|
26
|
+
export declare function summarizeRecorded(v: Record<string, unknown>): Record<string, unknown>;
|
|
27
|
+
/** An object that is no list. */
|
|
28
|
+
export declare function isPlainObject(v: unknown): v is Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* A call (secrets already removed) as a reporter sends it to an engine that takes it cut: the
|
|
31
|
+
* arguments and the value cut as the engine cuts them, and the summary of a result object, which
|
|
32
|
+
* the cut value may no longer give. The engine records the same event as from the whole call.
|
|
33
|
+
*/
|
|
34
|
+
export declare function cutToolCall(call: {
|
|
35
|
+
args: Record<string, unknown>;
|
|
36
|
+
ok: boolean;
|
|
37
|
+
value: unknown;
|
|
38
|
+
}): {
|
|
39
|
+
args: Record<string, unknown>;
|
|
40
|
+
value: unknown;
|
|
41
|
+
summary?: Record<string, unknown>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secrets out of recorded tool calls. A tool call becomes a `tool_call` event of the change feed,
|
|
3
|
+
* which the engine keeps in its store and the store backup commits and pushes: a webhook's secret
|
|
4
|
+
* or a token returned by a call must never get there. Removed are the arguments and result keys
|
|
5
|
+
* the catalogue marks `sensitive`, and, for any tool, the keys that name a secret
|
|
6
|
+
* ({@link SECRET_KEYS}), at any depth. A text (an error, a result sent as text) loses the values
|
|
7
|
+
* of those keys written as JSON.
|
|
8
|
+
*/
|
|
9
|
+
/** What a removed value becomes. */
|
|
10
|
+
export declare const REDACTED = "[redacted]";
|
|
11
|
+
/** Keys whose values are secrets, whatever the tool (compared without case, `_` or `-`). */
|
|
12
|
+
export declare const SECRET_KEYS: readonly ["secret", "token", "password", "apikey", "authorization", "httpservertoken", "accesstoken", "refreshtoken", "clientsecret"];
|
|
13
|
+
/** A tool call's arguments and result without their secrets (new objects; the call's own are kept). */
|
|
14
|
+
export declare function redactToolCall(tool: string, args: Record<string, unknown>, value: unknown): {
|
|
15
|
+
args: Record<string, unknown>;
|
|
16
|
+
value: unknown;
|
|
17
|
+
};
|
|
18
|
+
/** How many characters of a recorded call's result, and of each of its arguments, are kept. */
|
|
19
|
+
export declare const RECORDED_CHARS: {
|
|
20
|
+
readonly value: 1000;
|
|
21
|
+
readonly arg: 300;
|
|
22
|
+
};
|
|
23
|
+
/** A value as a recorded call keeps it: a text, or an object's JSON, longer than `n` characters is cut (with "…"). */
|
|
24
|
+
export declare function cutRecorded(v: unknown, n: number): unknown;
|
|
25
|
+
/** A result object in short: its first 30 fields, lists as their length, texts cut at 200 characters, nothing nested. */
|
|
26
|
+
export declare function summarizeRecorded(v: Record<string, unknown>): Record<string, unknown>;
|
|
27
|
+
/** An object that is no list. */
|
|
28
|
+
export declare function isPlainObject(v: unknown): v is Record<string, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* A call (secrets already removed) as a reporter sends it to an engine that takes it cut: the
|
|
31
|
+
* arguments and the value cut as the engine cuts them, and the summary of a result object, which
|
|
32
|
+
* the cut value may no longer give. The engine records the same event as from the whole call.
|
|
33
|
+
*/
|
|
34
|
+
export declare function cutToolCall(call: {
|
|
35
|
+
args: Record<string, unknown>;
|
|
36
|
+
ok: boolean;
|
|
37
|
+
value: unknown;
|
|
38
|
+
}): {
|
|
39
|
+
args: Record<string, unknown>;
|
|
40
|
+
value: unknown;
|
|
41
|
+
summary?: Record<string, unknown>;
|
|
42
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP request behind each operation of the catalogue (`catalog.ts`): every one is
|
|
3
|
+
* `POST /datanotes/operations/<name>/`, its JSON body the operation's arguments as they are (the
|
|
4
|
+
* same names an agent passes to the MCP tool), without the ones left out (null or undefined).
|
|
5
|
+
*/
|
|
6
|
+
import { type Guidance } from "./guidance.cjs";
|
|
7
|
+
type Args = Record<string, unknown>;
|
|
8
|
+
/** Arguments no request can be built from; `message` ends with how to fix them. */
|
|
9
|
+
export declare class OperationInputError extends Error {
|
|
10
|
+
readonly name = "OperationInputError";
|
|
11
|
+
constructor(message: string, guidance: Guidance);
|
|
12
|
+
}
|
|
13
|
+
export declare const ROUTE_PREFIX = "/datanotes";
|
|
14
|
+
/** The operations of the catalogue, by name. */
|
|
15
|
+
export declare const CALLABLE_OPERATIONS: ReadonlySet<string>;
|
|
16
|
+
/** The route of an operation, without the prefix: `/operations/<name>/`. */
|
|
17
|
+
export declare function operationRoute(name: string): string;
|
|
18
|
+
export interface OperationRequest {
|
|
19
|
+
method: "POST";
|
|
20
|
+
/** Path from the server root. */
|
|
21
|
+
path: string;
|
|
22
|
+
body: Args;
|
|
23
|
+
}
|
|
24
|
+
/** The request for an operation and its arguments; throws OperationInputError for an unknown operation. */
|
|
25
|
+
export declare function operationRequest(name: string, args?: Args): OperationRequest;
|
|
26
|
+
export {};
|
package/dist/api/requests.d.ts
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The HTTP request behind each operation of the catalogue (`catalog.ts`):
|
|
3
|
-
* `POST /datanotes/<
|
|
4
|
-
*
|
|
2
|
+
* The HTTP request behind each operation of the catalogue (`catalog.ts`): every one is
|
|
3
|
+
* `POST /datanotes/operations/<name>/`, its JSON body the operation's arguments as they are (the
|
|
4
|
+
* same names an agent passes to the MCP tool), without the ones left out (null or undefined).
|
|
5
5
|
*/
|
|
6
|
+
import { type Guidance } from "./guidance.js";
|
|
6
7
|
type Args = Record<string, unknown>;
|
|
8
|
+
/** Arguments no request can be built from; `message` ends with how to fix them. */
|
|
7
9
|
export declare class OperationInputError extends Error {
|
|
8
10
|
readonly name = "OperationInputError";
|
|
11
|
+
constructor(message: string, guidance: Guidance);
|
|
9
12
|
}
|
|
10
13
|
export declare const ROUTE_PREFIX = "/datanotes";
|
|
14
|
+
/** The operations of the catalogue, by name. */
|
|
15
|
+
export declare const CALLABLE_OPERATIONS: ReadonlySet<string>;
|
|
16
|
+
/** The route of an operation, without the prefix: `/operations/<name>/`. */
|
|
17
|
+
export declare function operationRoute(name: string): string;
|
|
11
18
|
export interface OperationRequest {
|
|
12
|
-
method: "
|
|
13
|
-
/** Path from the server root
|
|
19
|
+
method: "POST";
|
|
20
|
+
/** Path from the server root. */
|
|
14
21
|
path: string;
|
|
15
|
-
body
|
|
16
|
-
/** Accept header, when the route answers in more than one format. */
|
|
17
|
-
accept?: string;
|
|
22
|
+
body: Args;
|
|
18
23
|
}
|
|
19
|
-
/** The request for an operation and its arguments; throws OperationInputError
|
|
24
|
+
/** The request for an operation and its arguments; throws OperationInputError for an unknown operation. */
|
|
20
25
|
export declare function operationRequest(name: string, args?: Args): OperationRequest;
|
|
21
|
-
/** Operations this module can build a request for (to check the catalogue against). */
|
|
22
|
-
export declare const CALLABLE_OPERATIONS: Set<string>;
|
|
23
|
-
/** The route an operation calls (without the prefix) and the body fields it fixes (e.g. `op` for DDL), or null. */
|
|
24
|
-
export declare function operationRoute(name: string): {
|
|
25
|
-
path: string;
|
|
26
|
-
fixed: Args;
|
|
27
|
-
} | null;
|
|
28
26
|
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an operation returned, for its caller: the value of a success, or an agent-readable text
|
|
3
|
+
* for a refusal (what was refused; nothing was written) or an error, ending with the engine's
|
|
4
|
+
* `hint` (how to fix it) and `docs` (where to read more) when it sends them.
|
|
5
|
+
*/
|
|
6
|
+
/** Agent-readable summary of conflicts / violations / failures in a refused result. */
|
|
7
|
+
export declare function describeRefusal(data: Record<string, unknown>): string;
|
|
8
|
+
/** Agent-readable summary of a refused batch: the failing operation and the rollback. */
|
|
9
|
+
export declare function describeBatch(data: Record<string, unknown>): string;
|
|
10
|
+
export interface OperationResult {
|
|
11
|
+
ok: boolean;
|
|
12
|
+
/** The result (JSON, or the text of a note) or, when `ok` is false, the reason. */
|
|
13
|
+
value: unknown;
|
|
14
|
+
}
|
|
15
|
+
/** The result of an HTTP answer: `json` when the body was JSON, else its `text`. */
|
|
16
|
+
export declare function resultOf(status: number, json: unknown, text: string): OperationResult;
|
package/dist/api/results.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* What an operation returned, for its caller: the value of a success, or an agent-readable text
|
|
3
|
-
* for a refusal (what was refused; nothing was written) or an error
|
|
3
|
+
* for a refusal (what was refused; nothing was written) or an error, ending with the engine's
|
|
4
|
+
* `hint` (how to fix it) and `docs` (where to read more) when it sends them.
|
|
4
5
|
*/
|
|
5
6
|
/** Agent-readable summary of conflicts / violations / failures in a refused result. */
|
|
6
7
|
export declare function describeRefusal(data: Record<string, unknown>): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tokenizer-free estimate of how many tokens a text costs a model: words count about one token
|
|
3
|
+
* per 4 letters, numbers one per 3 digits, every other symbol (JSON punctuation, quotes, …) one.
|
|
4
|
+
* Close to real tokenizers on JSON and on Italian/English prose (within ~15%); good for telling
|
|
5
|
+
* which tools and sessions fill the context, not for billing.
|
|
6
|
+
*
|
|
7
|
+
* One pass over the text, character by character: a run of letters (`\p{L}`) or of digits
|
|
8
|
+
* (`\p{N}`) is one word or number, its length counted in UTF-16 units; white space (`\s`) counts
|
|
9
|
+
* nothing; any other character counts one.
|
|
10
|
+
*/
|
|
11
|
+
export declare function estimateTokens(text: string): number;
|
|
12
|
+
export declare const ASTRAL_KEPT = 4096;
|
package/dist/api/tokens.d.ts
CHANGED
|
@@ -3,5 +3,10 @@
|
|
|
3
3
|
* per 4 letters, numbers one per 3 digits, every other symbol (JSON punctuation, quotes, …) one.
|
|
4
4
|
* Close to real tokenizers on JSON and on Italian/English prose (within ~15%); good for telling
|
|
5
5
|
* which tools and sessions fill the context, not for billing.
|
|
6
|
+
*
|
|
7
|
+
* One pass over the text, character by character: a run of letters (`\p{L}`) or of digits
|
|
8
|
+
* (`\p{N}`) is one word or number, its length counted in UTF-16 units; white space (`\s`) counts
|
|
9
|
+
* nothing; any other character counts one.
|
|
6
10
|
*/
|
|
7
11
|
export declare function estimateTokens(text: string): number;
|
|
12
|
+
export declare const ASTRAL_KEPT = 4096;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3C Trace Context and a small tracer, with no dependency, for programs that call the engine:
|
|
3
|
+
* the MCP server (`datanotes mcp`), apps, scripts. A program continues its own trace in the
|
|
4
|
+
* engine by sending `traceparent` (and `tracestate`) with its requests: `DatanotesClient` does it
|
|
5
|
+
* with its `trace` option, or makes a CLIENT span per request with its `tracer` option.
|
|
6
|
+
*
|
|
7
|
+
* The spans go to an exporter, usually `OtlpTraceExporter` (otlp.ts). Unlike the engine's tracer,
|
|
8
|
+
* this one keeps no context across `await`: pass the parent explicitly, so it runs anywhere
|
|
9
|
+
* (Node, browsers, Obsidian).
|
|
10
|
+
*/
|
|
11
|
+
export type SpanKind = "internal" | "server" | "client" | "producer" | "consumer";
|
|
12
|
+
export type SpanStatusCode = "unset" | "ok" | "error";
|
|
13
|
+
type AttrValue = string | number | boolean | null | undefined;
|
|
14
|
+
/** A position in a trace: what `traceparent` carries. */
|
|
15
|
+
export interface TraceContext {
|
|
16
|
+
/** 32 lowercase hex characters. */
|
|
17
|
+
traceId: string;
|
|
18
|
+
/** 16 lowercase hex characters: the caller's span. */
|
|
19
|
+
spanId: string;
|
|
20
|
+
/** Whether the caller records the trace (flag `01`). */
|
|
21
|
+
sampled: boolean;
|
|
22
|
+
/** The `tracestate` header, passed on as it came. */
|
|
23
|
+
traceState?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
26
|
+
export declare const TRACESTATE_HEADER = "tracestate";
|
|
27
|
+
/**
|
|
28
|
+
* Read a `traceparent` header (and its `tracestate`); null when it is missing or invalid (an
|
|
29
|
+
* all-zero id, version `ff`, a version 00 header with extra fields), as the W3C spec says.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseTraceparent(traceparent: string | null | undefined, tracestate?: string | null): TraceContext | null;
|
|
32
|
+
/** The `traceparent` header of a context (version 00). */
|
|
33
|
+
export declare function formatTraceparent(ctx: TraceContext): string;
|
|
34
|
+
/** The headers that continue `ctx` in another process: `traceparent`, and `tracestate` when there is one. */
|
|
35
|
+
export declare function traceHeaders(ctx: TraceContext): Record<string, string>;
|
|
36
|
+
/** A new random trace id (32 hex characters). */
|
|
37
|
+
export declare const newTraceId: () => string;
|
|
38
|
+
/** A new random span id (16 hex characters). */
|
|
39
|
+
export declare const newSpanId: () => string;
|
|
40
|
+
/** A finished span, as `OtlpTraceExporter` sends it (times are Unix ms, with a fraction). */
|
|
41
|
+
export interface SpanRecord {
|
|
42
|
+
traceId: string;
|
|
43
|
+
spanId: string;
|
|
44
|
+
parentSpanId?: string;
|
|
45
|
+
traceState?: string;
|
|
46
|
+
name: string;
|
|
47
|
+
kind: SpanKind;
|
|
48
|
+
startMs: number;
|
|
49
|
+
endMs: number;
|
|
50
|
+
attributes: Record<string, AttrValue>;
|
|
51
|
+
events: {
|
|
52
|
+
name: string;
|
|
53
|
+
timeMs: number;
|
|
54
|
+
attributes: Record<string, AttrValue>;
|
|
55
|
+
}[];
|
|
56
|
+
status: {
|
|
57
|
+
code: SpanStatusCode;
|
|
58
|
+
message?: string;
|
|
59
|
+
};
|
|
60
|
+
droppedAttributes?: number;
|
|
61
|
+
droppedEvents?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface TracerOptions {
|
|
64
|
+
/** Where finished spans go, e.g. `(s) => exporter.export(s)` of an `OtlpTraceExporter`. */
|
|
65
|
+
export(spans: SpanRecord[]): void;
|
|
66
|
+
/** Share of new traces kept, 0 to 1 (default 1); a trace continued from a parent follows the parent. */
|
|
67
|
+
sampleRatio?: number;
|
|
68
|
+
/** Unix time in ms (default: `performance` when there is one, else `Date.now`). */
|
|
69
|
+
now?: () => number;
|
|
70
|
+
}
|
|
71
|
+
/** One operation of a program, timed; `end()` sends it. Not sampled: `recording` is false and nothing is sent. */
|
|
72
|
+
export declare class TraceSpan {
|
|
73
|
+
private readonly tracer;
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly kind: SpanKind;
|
|
76
|
+
readonly parent: TraceContext | null;
|
|
77
|
+
readonly recording: boolean;
|
|
78
|
+
readonly context: TraceContext;
|
|
79
|
+
private readonly startMs;
|
|
80
|
+
private readonly attributes;
|
|
81
|
+
private readonly events;
|
|
82
|
+
private status;
|
|
83
|
+
private ended;
|
|
84
|
+
constructor(tracer: Tracer, name: string, kind: SpanKind, parent: TraceContext | null, recording: boolean, attributes: Record<string, AttrValue>);
|
|
85
|
+
setAttribute(key: string, value: AttrValue): this;
|
|
86
|
+
setAttributes(attributes: Record<string, AttrValue>): this;
|
|
87
|
+
addEvent(name: string, attributes?: Record<string, AttrValue>): this;
|
|
88
|
+
/** An `exception` event, `error.type` and status ERROR. */
|
|
89
|
+
recordException(e: unknown): this;
|
|
90
|
+
setStatus(code: SpanStatusCode, message?: string): this;
|
|
91
|
+
end(): void;
|
|
92
|
+
}
|
|
93
|
+
/** Makes spans with explicit parents and hands them to an exporter. Never throws. */
|
|
94
|
+
export declare class Tracer {
|
|
95
|
+
private readonly o;
|
|
96
|
+
readonly now: () => number;
|
|
97
|
+
constructor(o: TracerOptions);
|
|
98
|
+
/** A new span: a child of `parent` (a context or a `traceparent` header), or a new trace. */
|
|
99
|
+
startSpan(name: string, opts?: {
|
|
100
|
+
kind?: SpanKind;
|
|
101
|
+
parent?: TraceContext | string | null;
|
|
102
|
+
attributes?: Record<string, AttrValue>;
|
|
103
|
+
}): TraceSpan;
|
|
104
|
+
/** @internal */
|
|
105
|
+
send(span: SpanRecord): void;
|
|
106
|
+
}
|
|
107
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3C Trace Context and a small tracer, with no dependency, for programs that call the engine:
|
|
3
|
+
* the MCP server (`datanotes mcp`), apps, scripts. A program continues its own trace in the
|
|
4
|
+
* engine by sending `traceparent` (and `tracestate`) with its requests: `DatanotesClient` does it
|
|
5
|
+
* with its `trace` option, or makes a CLIENT span per request with its `tracer` option.
|
|
6
|
+
*
|
|
7
|
+
* The spans go to an exporter, usually `OtlpTraceExporter` (otlp.ts). Unlike the engine's tracer,
|
|
8
|
+
* this one keeps no context across `await`: pass the parent explicitly, so it runs anywhere
|
|
9
|
+
* (Node, browsers, Obsidian).
|
|
10
|
+
*/
|
|
11
|
+
export type SpanKind = "internal" | "server" | "client" | "producer" | "consumer";
|
|
12
|
+
export type SpanStatusCode = "unset" | "ok" | "error";
|
|
13
|
+
type AttrValue = string | number | boolean | null | undefined;
|
|
14
|
+
/** A position in a trace: what `traceparent` carries. */
|
|
15
|
+
export interface TraceContext {
|
|
16
|
+
/** 32 lowercase hex characters. */
|
|
17
|
+
traceId: string;
|
|
18
|
+
/** 16 lowercase hex characters: the caller's span. */
|
|
19
|
+
spanId: string;
|
|
20
|
+
/** Whether the caller records the trace (flag `01`). */
|
|
21
|
+
sampled: boolean;
|
|
22
|
+
/** The `tracestate` header, passed on as it came. */
|
|
23
|
+
traceState?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
26
|
+
export declare const TRACESTATE_HEADER = "tracestate";
|
|
27
|
+
/**
|
|
28
|
+
* Read a `traceparent` header (and its `tracestate`); null when it is missing or invalid (an
|
|
29
|
+
* all-zero id, version `ff`, a version 00 header with extra fields), as the W3C spec says.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseTraceparent(traceparent: string | null | undefined, tracestate?: string | null): TraceContext | null;
|
|
32
|
+
/** The `traceparent` header of a context (version 00). */
|
|
33
|
+
export declare function formatTraceparent(ctx: TraceContext): string;
|
|
34
|
+
/** The headers that continue `ctx` in another process: `traceparent`, and `tracestate` when there is one. */
|
|
35
|
+
export declare function traceHeaders(ctx: TraceContext): Record<string, string>;
|
|
36
|
+
/** A new random trace id (32 hex characters). */
|
|
37
|
+
export declare const newTraceId: () => string;
|
|
38
|
+
/** A new random span id (16 hex characters). */
|
|
39
|
+
export declare const newSpanId: () => string;
|
|
40
|
+
/** A finished span, as `OtlpTraceExporter` sends it (times are Unix ms, with a fraction). */
|
|
41
|
+
export interface SpanRecord {
|
|
42
|
+
traceId: string;
|
|
43
|
+
spanId: string;
|
|
44
|
+
parentSpanId?: string;
|
|
45
|
+
traceState?: string;
|
|
46
|
+
name: string;
|
|
47
|
+
kind: SpanKind;
|
|
48
|
+
startMs: number;
|
|
49
|
+
endMs: number;
|
|
50
|
+
attributes: Record<string, AttrValue>;
|
|
51
|
+
events: {
|
|
52
|
+
name: string;
|
|
53
|
+
timeMs: number;
|
|
54
|
+
attributes: Record<string, AttrValue>;
|
|
55
|
+
}[];
|
|
56
|
+
status: {
|
|
57
|
+
code: SpanStatusCode;
|
|
58
|
+
message?: string;
|
|
59
|
+
};
|
|
60
|
+
droppedAttributes?: number;
|
|
61
|
+
droppedEvents?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface TracerOptions {
|
|
64
|
+
/** Where finished spans go, e.g. `(s) => exporter.export(s)` of an `OtlpTraceExporter`. */
|
|
65
|
+
export(spans: SpanRecord[]): void;
|
|
66
|
+
/** Share of new traces kept, 0 to 1 (default 1); a trace continued from a parent follows the parent. */
|
|
67
|
+
sampleRatio?: number;
|
|
68
|
+
/** Unix time in ms (default: `performance` when there is one, else `Date.now`). */
|
|
69
|
+
now?: () => number;
|
|
70
|
+
}
|
|
71
|
+
/** One operation of a program, timed; `end()` sends it. Not sampled: `recording` is false and nothing is sent. */
|
|
72
|
+
export declare class TraceSpan {
|
|
73
|
+
private readonly tracer;
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly kind: SpanKind;
|
|
76
|
+
readonly parent: TraceContext | null;
|
|
77
|
+
readonly recording: boolean;
|
|
78
|
+
readonly context: TraceContext;
|
|
79
|
+
private readonly startMs;
|
|
80
|
+
private readonly attributes;
|
|
81
|
+
private readonly events;
|
|
82
|
+
private status;
|
|
83
|
+
private ended;
|
|
84
|
+
constructor(tracer: Tracer, name: string, kind: SpanKind, parent: TraceContext | null, recording: boolean, attributes: Record<string, AttrValue>);
|
|
85
|
+
setAttribute(key: string, value: AttrValue): this;
|
|
86
|
+
setAttributes(attributes: Record<string, AttrValue>): this;
|
|
87
|
+
addEvent(name: string, attributes?: Record<string, AttrValue>): this;
|
|
88
|
+
/** An `exception` event, `error.type` and status ERROR. */
|
|
89
|
+
recordException(e: unknown): this;
|
|
90
|
+
setStatus(code: SpanStatusCode, message?: string): this;
|
|
91
|
+
end(): void;
|
|
92
|
+
}
|
|
93
|
+
/** Makes spans with explicit parents and hands them to an exporter. Never throws. */
|
|
94
|
+
export declare class Tracer {
|
|
95
|
+
private readonly o;
|
|
96
|
+
readonly now: () => number;
|
|
97
|
+
constructor(o: TracerOptions);
|
|
98
|
+
/** A new span: a child of `parent` (a context or a `traceparent` header), or a new trace. */
|
|
99
|
+
startSpan(name: string, opts?: {
|
|
100
|
+
kind?: SpanKind;
|
|
101
|
+
parent?: TraceContext | string | null;
|
|
102
|
+
attributes?: Record<string, AttrValue>;
|
|
103
|
+
}): TraceSpan;
|
|
104
|
+
/** @internal */
|
|
105
|
+
send(span: SpanRecord): void;
|
|
106
|
+
}
|
|
107
|
+
export {};
|