@intellectual-frontiers/telemetry 0.0.0-stage → 0.1.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/dist/otlp.d.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * OTLP/HTTP with JSON, both ways (commons 0001-telemetry FR-004): export requests of traces, logs and metrics as the OTLP specification's
3
+ * JSON encoding writes them (camel-case field names, trace and span ids as hexadecimal, 64-bit integers as decimal strings, enumerations as
4
+ * integers, bytes as base64, signals grouped by resource and scope), the export responses with their partial success, and the decoding of
5
+ * each back to the values of `./otel.ts`: a failure is a `Result` naming the path, a 64-bit integer is read from a JSON number or a string,
6
+ * an enumeration from its number or its name, and a field the decoder does not know is ignored.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { decodeTraces, encodeTraces } from "./otlp.js";
11
+ * const request = encodeTraces([{ resource: { attributes: { "service.name": "build" } }, scope: { name: "ifc" }, spans: [] }]);
12
+ * decodeTraces(JSON.parse(JSON.stringify(request))); // { kind: "ok", value: [ ...the same batch ] }
13
+ * ```
14
+ *
15
+ * @module
16
+ */
17
+ import { type Result } from "@intellectual-frontiers/core";
18
+ import type { DecodeError, Decoder } from "@intellectual-frontiers/core";
19
+ import type { Json, JsonObject } from "@intellectual-frontiers/formats/json5";
20
+ import { type AnyValue, type AttributeValue, type Attributes, type LogRecord, type Metric, type Resource, type Scope, type SignalName, type SpanData } from "./otel.js";
21
+ /** The spans of one resource and scope, as OTLP groups them. */
22
+ export type TraceBatch = {
23
+ readonly resource: Resource;
24
+ readonly scope: Scope;
25
+ readonly spans: readonly SpanData[];
26
+ };
27
+ /** The log records of one resource and scope, as OTLP groups them. */
28
+ export type LogBatch = {
29
+ readonly resource: Resource;
30
+ readonly scope: Scope;
31
+ readonly records: readonly LogRecord[];
32
+ };
33
+ /** The metrics of one resource and scope, as OTLP groups them. */
34
+ export type MetricBatch = {
35
+ readonly resource: Resource;
36
+ readonly scope: Scope;
37
+ readonly metrics: readonly Metric[];
38
+ };
39
+ /** An export response: how many signals were rejected (spans, log records or data points) and why; zero and `""` for full success. */
40
+ export type ExportResponse = {
41
+ readonly rejected: number;
42
+ readonly errorMessage: string;
43
+ };
44
+ /** A value as OTLP's JSON `AnyValue`. */
45
+ export declare function encodeAnyValue(value: AnyValue): JsonObject;
46
+ /** Attributes as OTLP's JSON list of `KeyValue`. */
47
+ export declare function encodeAttributes(attributes: Attributes): Json[];
48
+ /** A finished span as OTLP's JSON `Span`. */
49
+ export declare function encodeSpan(s: SpanData): JsonObject;
50
+ /** A log record as OTLP's JSON `LogRecord`. */
51
+ export declare function encodeLogRecord(r: LogRecord): JsonObject;
52
+ /** A metric as OTLP's JSON `Metric`. */
53
+ export declare function encodeMetric(m: Metric): JsonObject;
54
+ /** Trace batches as an OTLP/JSON `ExportTraceServiceRequest`. */
55
+ export declare function encodeTraces(batches: readonly TraceBatch[]): JsonObject;
56
+ /** Log batches as an OTLP/JSON `ExportLogsServiceRequest`. */
57
+ export declare function encodeLogs(batches: readonly LogBatch[]): JsonObject;
58
+ /** Metric batches as an OTLP/JSON `ExportMetricsServiceRequest`. */
59
+ export declare function encodeMetrics(batches: readonly MetricBatch[]): JsonObject;
60
+ /** An export response as OTLP/JSON: `{}` for full success, else `partialSuccess` with the rejected count (a decimal string) and the message. */
61
+ export declare function encodeResponse(signal: SignalName, response: ExportResponse): JsonObject;
62
+ /** OTLP's JSON `AnyValue` as a value; an `AnyValue` that holds none is refused. */
63
+ export declare const decodeAnyValue: Decoder<AnyValue>;
64
+ /** An `AnyValue` that is an attribute value: a primitive, or an array of primitives of one type. */
65
+ export declare const decodeAttributeValue: Decoder<AttributeValue>;
66
+ /** OTLP's JSON list of `KeyValue` as attributes. */
67
+ export declare const decodeAttributes: Decoder<Attributes>;
68
+ /** OTLP's JSON `Span` as a finished span. */
69
+ export declare const decodeSpan: Decoder<SpanData>;
70
+ /** OTLP's JSON `LogRecord` as a log record; its severity number must be 1 to 24. */
71
+ export declare const decodeLogRecord: Decoder<LogRecord>;
72
+ /** OTLP's JSON `Metric` as a metric: a sum, a gauge or a histogram (other data is refused). */
73
+ export declare const decodeMetric: Decoder<Metric>;
74
+ /** An OTLP/JSON `ExportTraceServiceRequest` as trace batches, one for each scope of each resource; a failure names its path. */
75
+ export declare function decodeTraces(input: unknown): Result<readonly TraceBatch[], DecodeError>;
76
+ /** An OTLP/JSON `ExportLogsServiceRequest` as log batches, one for each scope of each resource; a failure names its path. */
77
+ export declare function decodeLogs(input: unknown): Result<readonly LogBatch[], DecodeError>;
78
+ /** An OTLP/JSON `ExportMetricsServiceRequest` as metric batches, one for each scope of each resource; a failure names its path. */
79
+ export declare function decodeMetrics(input: unknown): Result<readonly MetricBatch[], DecodeError>;
80
+ /** An OTLP/JSON export response; an absent `partialSuccess` is full success. */
81
+ export declare function decodeResponse(signal: SignalName, input: unknown): Result<ExportResponse, DecodeError>;
82
+ /** The number of signals in trace, log or metric batches: spans, log records, or data points (what a partial success counts). */
83
+ export declare function countSignals(batches: readonly TraceBatch[] | readonly LogBatch[] | readonly MetricBatch[]): number;