| 1 | /** |
| 2 | * What one delivery adds to a project's store: rows already in the shape |
| 3 | * they are kept in, whichever door they came through (./tail.ts for apps |
| 4 | * on g1t.page, ./otlp/normalize.ts for OTLP). |
| 5 | */ |
| 6 | import type { Attributes, MetricKind, TelemetryLog, TelemetryOrigin, TelemetryRequest, TelemetrySpan } from "@g1t/contracts/telemetry"; |
| 7 | |
| 8 | export type MetricPoint = TelemetryOrigin & { |
| 9 | name: string; |
| 10 | kind: MetricKind; |
| 11 | unit: string; |
| 12 | description: string; |
| 13 | time_us: number; |
| 14 | /** A gauge's or a sum's value; a histogram's or a summary's mean. */ |
| 15 | value: number | null; |
| 16 | count: number | null; |
| 17 | sum: number | null; |
| 18 | min: number | null; |
| 19 | max: number | null; |
| 20 | /** A histogram's buckets: `bounds.length + 1` counts. */ |
| 21 | bounds: number[] | null; |
| 22 | counts: number[] | null; |
| 23 | /** A summary's quantiles. */ |
| 24 | quantiles: { q: number; v: number }[] | null; |
| 25 | /** Cumulative sums are kept as sent and turned into rates when read. */ |
| 26 | monotonic: boolean; |
| 27 | attributes: Attributes; |
| 28 | }; |
| 29 | |
| 30 | /** One exception seen, before it is grouped (./errors.ts). */ |
| 31 | export type ErrorSeen = TelemetryOrigin & { |
| 32 | time_us: number; |
| 33 | name: string; |
| 34 | message: string; |
| 35 | stack: string | null; |
| 36 | request_id: string | null; |
| 37 | trace_id: string | null; |
| 38 | }; |
| 39 | |
| 40 | export type Batch = { |
| 41 | requests: TelemetryRequest[]; |
| 42 | logs: TelemetryLog[]; |
| 43 | spans: TelemetrySpan[]; |
| 44 | metrics: MetricPoint[]; |
| 45 | errors: ErrorSeen[]; |
| 46 | /** What it weighed on arrival, for metering. */ |
| 47 | bytes: number; |
| 48 | }; |
| 49 | |
| 50 | export function emptyBatch(): Batch { |
| 51 | return { requests: [], logs: [], spans: [], metrics: [], errors: [], bytes: 0 }; |
| 52 | } |
| 53 | |
| 54 | export function batchSize(batch: Batch): number { |
| 55 | return batch.requests.length + batch.logs.length + batch.spans.length + batch.metrics.length; |
| 56 | } |