@rivetkit/traces 2.1.0-rc.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/LICENSE +203 -0
- package/dist/schemas/v1.ts +653 -0
- package/dist/tsup/chunk-2D7JND4Z.js +63 -0
- package/dist/tsup/chunk-2D7JND4Z.js.map +1 -0
- package/dist/tsup/chunk-7RQXHEKZ.js +541 -0
- package/dist/tsup/chunk-7RQXHEKZ.js.map +1 -0
- package/dist/tsup/chunk-DXS2HLRN.cjs +63 -0
- package/dist/tsup/chunk-DXS2HLRN.cjs.map +1 -0
- package/dist/tsup/chunk-QOSSO6CN.cjs +541 -0
- package/dist/tsup/chunk-QOSSO6CN.cjs.map +1 -0
- package/dist/tsup/chunk-UNGPFJ4C.js +417 -0
- package/dist/tsup/chunk-UNGPFJ4C.js.map +1 -0
- package/dist/tsup/chunk-ZTVH74GC.cjs +417 -0
- package/dist/tsup/chunk-ZTVH74GC.cjs.map +1 -0
- package/dist/tsup/encoding.cjs +20 -0
- package/dist/tsup/encoding.cjs.map +1 -0
- package/dist/tsup/encoding.d.cts +6 -0
- package/dist/tsup/encoding.d.ts +6 -0
- package/dist/tsup/encoding.js +20 -0
- package/dist/tsup/encoding.js.map +1 -0
- package/dist/tsup/index.browser.cjs +15 -0
- package/dist/tsup/index.browser.cjs.map +1 -0
- package/dist/tsup/index.browser.d.cts +7 -0
- package/dist/tsup/index.browser.d.ts +7 -0
- package/dist/tsup/index.browser.js +15 -0
- package/dist/tsup/index.browser.js.map +1 -0
- package/dist/tsup/index.cjs +921 -0
- package/dist/tsup/index.cjs.map +1 -0
- package/dist/tsup/index.d.cts +9 -0
- package/dist/tsup/index.d.ts +9 -0
- package/dist/tsup/index.js +921 -0
- package/dist/tsup/index.js.map +1 -0
- package/dist/tsup/noop-CcgjEgCu.d.cts +99 -0
- package/dist/tsup/noop-D-YAZiGa.d.ts +99 -0
- package/dist/tsup/otlp-Da4Yz0xC.d.cts +81 -0
- package/dist/tsup/otlp-Da4Yz0xC.d.ts +81 -0
- package/dist/tsup/otlp-entry.cjs +16 -0
- package/dist/tsup/otlp-entry.cjs.map +1 -0
- package/dist/tsup/otlp-entry.d.cts +10 -0
- package/dist/tsup/otlp-entry.d.ts +10 -0
- package/dist/tsup/otlp-entry.js +16 -0
- package/dist/tsup/otlp-entry.js.map +1 -0
- package/dist/tsup/v1-DovAIc7f.d.cts +118 -0
- package/dist/tsup/v1-DovAIc7f.d.ts +118 -0
- package/package.json +74 -0
- package/schemas/v1.bare +177 -0
- package/schemas/versioned.ts +99 -0
- package/src/encoding.ts +18 -0
- package/src/index.browser.ts +13 -0
- package/src/index.ts +31 -0
- package/src/noop.ts +81 -0
- package/src/otlp-entry.ts +18 -0
- package/src/otlp.ts +158 -0
- package/src/read-range.ts +502 -0
- package/src/traces.ts +1186 -0
- package/src/types.ts +94 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
type u32 = number;
|
|
2
|
+
type u64 = bigint;
|
|
3
|
+
type Cbor = ArrayBuffer;
|
|
4
|
+
type TraceId = ArrayBuffer;
|
|
5
|
+
type SpanId = ArrayBuffer;
|
|
6
|
+
type StringId = u32;
|
|
7
|
+
type KeyValue = {
|
|
8
|
+
readonly key: StringId;
|
|
9
|
+
readonly value: Cbor;
|
|
10
|
+
};
|
|
11
|
+
type Attributes = readonly KeyValue[];
|
|
12
|
+
declare enum SpanStatusCode {
|
|
13
|
+
UNSET = "UNSET",
|
|
14
|
+
OK = "OK",
|
|
15
|
+
ERROR = "ERROR"
|
|
16
|
+
}
|
|
17
|
+
type SpanStatus = {
|
|
18
|
+
readonly code: SpanStatusCode;
|
|
19
|
+
readonly message: string | null;
|
|
20
|
+
};
|
|
21
|
+
type SpanLink = {
|
|
22
|
+
readonly traceId: TraceId;
|
|
23
|
+
readonly spanId: SpanId;
|
|
24
|
+
readonly traceState: string | null;
|
|
25
|
+
readonly attributes: Attributes;
|
|
26
|
+
readonly droppedAttributesCount: u32;
|
|
27
|
+
};
|
|
28
|
+
type SpanStart = {
|
|
29
|
+
readonly traceId: TraceId;
|
|
30
|
+
readonly spanId: SpanId;
|
|
31
|
+
readonly parentSpanId: SpanId | null;
|
|
32
|
+
readonly name: StringId;
|
|
33
|
+
readonly kind: u32;
|
|
34
|
+
readonly traceState: string | null;
|
|
35
|
+
readonly flags: u32;
|
|
36
|
+
readonly attributes: Attributes;
|
|
37
|
+
readonly droppedAttributesCount: u32;
|
|
38
|
+
readonly links: readonly SpanLink[];
|
|
39
|
+
readonly droppedLinksCount: u32;
|
|
40
|
+
};
|
|
41
|
+
type SpanUpdate = {
|
|
42
|
+
readonly spanId: SpanId;
|
|
43
|
+
readonly attributes: Attributes;
|
|
44
|
+
readonly droppedAttributesCount: u32;
|
|
45
|
+
readonly status: SpanStatus | null;
|
|
46
|
+
};
|
|
47
|
+
type SpanEvent = {
|
|
48
|
+
readonly spanId: SpanId;
|
|
49
|
+
readonly name: StringId;
|
|
50
|
+
readonly attributes: Attributes;
|
|
51
|
+
readonly droppedAttributesCount: u32;
|
|
52
|
+
};
|
|
53
|
+
type SpanEnd = {
|
|
54
|
+
readonly spanId: SpanId;
|
|
55
|
+
readonly status: SpanStatus | null;
|
|
56
|
+
};
|
|
57
|
+
type SpanSnapshot = {
|
|
58
|
+
readonly traceId: TraceId;
|
|
59
|
+
readonly spanId: SpanId;
|
|
60
|
+
readonly parentSpanId: SpanId | null;
|
|
61
|
+
readonly name: StringId;
|
|
62
|
+
readonly kind: u32;
|
|
63
|
+
readonly startTimeUnixNs: u64;
|
|
64
|
+
readonly traceState: string | null;
|
|
65
|
+
readonly flags: u32;
|
|
66
|
+
readonly attributes: Attributes;
|
|
67
|
+
readonly droppedAttributesCount: u32;
|
|
68
|
+
readonly links: readonly SpanLink[];
|
|
69
|
+
readonly droppedLinksCount: u32;
|
|
70
|
+
readonly status: SpanStatus | null;
|
|
71
|
+
};
|
|
72
|
+
type RecordBody = {
|
|
73
|
+
readonly tag: "SpanStart";
|
|
74
|
+
readonly val: SpanStart;
|
|
75
|
+
} | {
|
|
76
|
+
readonly tag: "SpanEvent";
|
|
77
|
+
readonly val: SpanEvent;
|
|
78
|
+
} | {
|
|
79
|
+
readonly tag: "SpanUpdate";
|
|
80
|
+
readonly val: SpanUpdate;
|
|
81
|
+
} | {
|
|
82
|
+
readonly tag: "SpanEnd";
|
|
83
|
+
readonly val: SpanEnd;
|
|
84
|
+
} | {
|
|
85
|
+
readonly tag: "SpanSnapshot";
|
|
86
|
+
readonly val: SpanSnapshot;
|
|
87
|
+
};
|
|
88
|
+
type Record = {
|
|
89
|
+
readonly timeOffsetNs: u64;
|
|
90
|
+
readonly body: RecordBody;
|
|
91
|
+
};
|
|
92
|
+
type SpanRecordKey = {
|
|
93
|
+
readonly prefix: u32;
|
|
94
|
+
readonly bucketStartSec: u64;
|
|
95
|
+
readonly chunkId: u32;
|
|
96
|
+
readonly recordIndex: u32;
|
|
97
|
+
};
|
|
98
|
+
type ActiveSpanRef = {
|
|
99
|
+
readonly spanId: SpanId;
|
|
100
|
+
readonly startKey: SpanRecordKey;
|
|
101
|
+
readonly latestSnapshotKey: SpanRecordKey | null;
|
|
102
|
+
};
|
|
103
|
+
type Chunk = {
|
|
104
|
+
readonly baseUnixNs: u64;
|
|
105
|
+
readonly strings: readonly string[];
|
|
106
|
+
readonly records: readonly Record[];
|
|
107
|
+
readonly activeSpans: readonly ActiveSpanRef[];
|
|
108
|
+
};
|
|
109
|
+
type ReadRangeWire = {
|
|
110
|
+
readonly startTimeMs: u64;
|
|
111
|
+
readonly endTimeMs: u64;
|
|
112
|
+
readonly limit: u32;
|
|
113
|
+
readonly clamped: boolean;
|
|
114
|
+
readonly baseChunks: readonly Chunk[];
|
|
115
|
+
readonly chunks: readonly Chunk[];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type { ReadRangeWire as R };
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rivetkit/traces",
|
|
3
|
+
"version": "2.1.0-rc.1",
|
|
4
|
+
"description": "Generic tracing storage and OTLP export for RivetKit",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"src",
|
|
10
|
+
"schemas",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"browser": {
|
|
16
|
+
"types": "./dist/tsup/index.browser.d.ts",
|
|
17
|
+
"import": "./dist/tsup/index.browser.js",
|
|
18
|
+
"require": "./dist/tsup/index.browser.cjs"
|
|
19
|
+
},
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/tsup/index.d.ts",
|
|
22
|
+
"default": "./dist/tsup/index.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/tsup/index.d.cts",
|
|
26
|
+
"default": "./dist/tsup/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./encoding": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/tsup/encoding.d.ts",
|
|
32
|
+
"default": "./dist/tsup/encoding.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/tsup/encoding.d.cts",
|
|
36
|
+
"default": "./dist/tsup/encoding.cjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./otlp": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/tsup/otlp-entry.d.ts",
|
|
42
|
+
"default": "./dist/tsup/otlp-entry.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/tsup/otlp-entry.d.cts",
|
|
46
|
+
"default": "./dist/tsup/otlp-entry.cjs"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@rivetkit/bare-ts": "^0.6.2",
|
|
55
|
+
"fdb-tuple": "^1.0.0",
|
|
56
|
+
"cbor-x": "^1.6.0",
|
|
57
|
+
"vbare": "^0.0.4"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@bare-ts/tools": "^0.13.0",
|
|
61
|
+
"@types/node": "^22.13.1",
|
|
62
|
+
"commander": "^12.0.0",
|
|
63
|
+
"tsx": "^4.7.0",
|
|
64
|
+
"tsup": "^8.4.0",
|
|
65
|
+
"typescript": "^5.7.3",
|
|
66
|
+
"vitest": "^3.1.1"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "pnpm run compile:bare && tsup src/index.ts src/index.browser.ts src/encoding.ts src/otlp-entry.ts",
|
|
70
|
+
"compile:bare": "tsx scripts/compile-bare.ts compile schemas/v1.bare -o dist/schemas/v1.ts",
|
|
71
|
+
"check-types": "pnpm run compile:bare && tsc --noEmit",
|
|
72
|
+
"test": "pnpm run compile:bare && vitest run"
|
|
73
|
+
}
|
|
74
|
+
}
|
package/schemas/v1.bare
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Traces BARE Schema v1
|
|
2
|
+
#
|
|
3
|
+
# Internal storage format for @rivetkit/traces. Records are stored as an
|
|
4
|
+
# append-only Span[] stream and exported to OTLP v1 JSON on read.
|
|
5
|
+
#
|
|
6
|
+
# OTLP spec: https://opentelemetry.io/docs/specs/otlp/
|
|
7
|
+
# OTel trace data model: https://opentelemetry.io/docs/specs/otel/trace/api/
|
|
8
|
+
# OTLP proto: https://github.com/open-telemetry/opentelemetry-proto
|
|
9
|
+
|
|
10
|
+
# Opaque CBOR bytes for attribute values
|
|
11
|
+
# See cbor-x for encoding/decoding
|
|
12
|
+
# https://github.com/kriszyp/cbor-x
|
|
13
|
+
#
|
|
14
|
+
# NOTE: AnyValue conversion happens at export time.
|
|
15
|
+
#
|
|
16
|
+
# BARE type for raw bytes
|
|
17
|
+
#
|
|
18
|
+
# type Cbor data
|
|
19
|
+
|
|
20
|
+
# Raw bytes types
|
|
21
|
+
|
|
22
|
+
type Cbor data
|
|
23
|
+
|
|
24
|
+
type TraceId data
|
|
25
|
+
|
|
26
|
+
type SpanId data
|
|
27
|
+
|
|
28
|
+
# String table index
|
|
29
|
+
|
|
30
|
+
type StringId u32
|
|
31
|
+
|
|
32
|
+
# KeyValue (attribute)
|
|
33
|
+
|
|
34
|
+
type KeyValue struct {
|
|
35
|
+
key: StringId
|
|
36
|
+
value: Cbor
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type Attributes list<KeyValue>
|
|
40
|
+
|
|
41
|
+
# Status
|
|
42
|
+
|
|
43
|
+
type SpanStatusCode enum {
|
|
44
|
+
UNSET
|
|
45
|
+
OK
|
|
46
|
+
ERROR
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type SpanStatus struct {
|
|
50
|
+
code: SpanStatusCode
|
|
51
|
+
message: optional<str>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# Link
|
|
55
|
+
|
|
56
|
+
type SpanLink struct {
|
|
57
|
+
traceId: TraceId
|
|
58
|
+
spanId: SpanId
|
|
59
|
+
traceState: optional<str>
|
|
60
|
+
attributes: Attributes
|
|
61
|
+
droppedAttributesCount: u32
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Start
|
|
65
|
+
|
|
66
|
+
type SpanStart struct {
|
|
67
|
+
traceId: TraceId
|
|
68
|
+
spanId: SpanId
|
|
69
|
+
parentSpanId: optional<SpanId>
|
|
70
|
+
name: StringId
|
|
71
|
+
kind: u32
|
|
72
|
+
traceState: optional<str>
|
|
73
|
+
flags: u32
|
|
74
|
+
attributes: Attributes
|
|
75
|
+
droppedAttributesCount: u32
|
|
76
|
+
links: list<SpanLink>
|
|
77
|
+
droppedLinksCount: u32
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# Update
|
|
81
|
+
|
|
82
|
+
type SpanUpdate struct {
|
|
83
|
+
spanId: SpanId
|
|
84
|
+
attributes: Attributes
|
|
85
|
+
droppedAttributesCount: u32
|
|
86
|
+
status: optional<SpanStatus>
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# Event
|
|
90
|
+
|
|
91
|
+
type SpanEvent struct {
|
|
92
|
+
spanId: SpanId
|
|
93
|
+
name: StringId
|
|
94
|
+
attributes: Attributes
|
|
95
|
+
droppedAttributesCount: u32
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
# End
|
|
99
|
+
|
|
100
|
+
type SpanEnd struct {
|
|
101
|
+
spanId: SpanId
|
|
102
|
+
status: optional<SpanStatus>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# Snapshot
|
|
106
|
+
|
|
107
|
+
type SpanSnapshot struct {
|
|
108
|
+
traceId: TraceId
|
|
109
|
+
spanId: SpanId
|
|
110
|
+
parentSpanId: optional<SpanId>
|
|
111
|
+
name: StringId
|
|
112
|
+
kind: u32
|
|
113
|
+
startTimeUnixNs: u64
|
|
114
|
+
traceState: optional<str>
|
|
115
|
+
flags: u32
|
|
116
|
+
attributes: Attributes
|
|
117
|
+
droppedAttributesCount: u32
|
|
118
|
+
links: list<SpanLink>
|
|
119
|
+
droppedLinksCount: u32
|
|
120
|
+
status: optional<SpanStatus>
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# Record
|
|
124
|
+
|
|
125
|
+
type RecordBody union {
|
|
126
|
+
SpanStart |
|
|
127
|
+
SpanEvent |
|
|
128
|
+
SpanUpdate |
|
|
129
|
+
SpanEnd |
|
|
130
|
+
SpanSnapshot
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
type Record struct {
|
|
134
|
+
timeOffsetNs: u64
|
|
135
|
+
body: RecordBody
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# Record pointer
|
|
139
|
+
|
|
140
|
+
type SpanRecordKey struct {
|
|
141
|
+
prefix: u32
|
|
142
|
+
bucketStartSec: u64
|
|
143
|
+
chunkId: u32
|
|
144
|
+
recordIndex: u32
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Active span reference (stored in every chunk)
|
|
148
|
+
|
|
149
|
+
type ActiveSpanRef struct {
|
|
150
|
+
spanId: SpanId
|
|
151
|
+
startKey: SpanRecordKey
|
|
152
|
+
latestSnapshotKey: optional<SpanRecordKey>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
# Chunk container
|
|
156
|
+
|
|
157
|
+
type Chunk struct {
|
|
158
|
+
baseUnixNs: u64
|
|
159
|
+
strings: list<str>
|
|
160
|
+
records: list<Record>
|
|
161
|
+
activeSpans: list<ActiveSpanRef>
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# Read range response wire format.
|
|
165
|
+
# This reuses existing chunk structs for compactness.
|
|
166
|
+
#
|
|
167
|
+
# baseChunks contains the minimal records needed to hydrate spans that
|
|
168
|
+
# started before the query range (e.g., start or snapshot records).
|
|
169
|
+
|
|
170
|
+
type ReadRangeWire struct {
|
|
171
|
+
startTimeMs: u64
|
|
172
|
+
endTimeMs: u64
|
|
173
|
+
limit: u32
|
|
174
|
+
clamped: bool
|
|
175
|
+
baseChunks: list<Chunk>
|
|
176
|
+
chunks: list<Chunk>
|
|
177
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as bare from "@rivetkit/bare-ts";
|
|
2
|
+
import { createVersionedDataHandler } from "vbare";
|
|
3
|
+
import * as v1 from "../dist/schemas/v1";
|
|
4
|
+
|
|
5
|
+
export const CURRENT_VERSION = 1;
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
ActiveSpanRef,
|
|
9
|
+
Attributes,
|
|
10
|
+
Chunk,
|
|
11
|
+
KeyValue,
|
|
12
|
+
ReadRangeWire,
|
|
13
|
+
Record,
|
|
14
|
+
RecordBody,
|
|
15
|
+
SpanEnd,
|
|
16
|
+
SpanEvent,
|
|
17
|
+
SpanId,
|
|
18
|
+
SpanLink,
|
|
19
|
+
SpanRecordKey,
|
|
20
|
+
SpanSnapshot,
|
|
21
|
+
SpanStart,
|
|
22
|
+
SpanStatus,
|
|
23
|
+
SpanUpdate,
|
|
24
|
+
StringId,
|
|
25
|
+
TraceId,
|
|
26
|
+
} from "../dist/schemas/v1";
|
|
27
|
+
|
|
28
|
+
export { SpanStatusCode } from "../dist/schemas/v1";
|
|
29
|
+
|
|
30
|
+
export const CHUNK_VERSIONED = createVersionedDataHandler<v1.Chunk>({
|
|
31
|
+
deserializeVersion: (bytes, version) => {
|
|
32
|
+
switch (version) {
|
|
33
|
+
case 1:
|
|
34
|
+
return decodeChunk(bytes);
|
|
35
|
+
default:
|
|
36
|
+
throw new Error(`Unknown Chunk version ${version}`);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
serializeVersion: (data, version) => {
|
|
40
|
+
switch (version) {
|
|
41
|
+
case 1:
|
|
42
|
+
return encodeChunk(data as v1.Chunk);
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unknown Chunk version ${version}`);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
deserializeConverters: () => [],
|
|
48
|
+
serializeConverters: () => [],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const READ_RANGE_VERSIONED =
|
|
52
|
+
createVersionedDataHandler<v1.ReadRangeWire>({
|
|
53
|
+
deserializeVersion: (bytes, version) => {
|
|
54
|
+
switch (version) {
|
|
55
|
+
case 1:
|
|
56
|
+
return v1.decodeReadRangeWire(bytes);
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unknown ReadRangeWire version ${version}`);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
serializeVersion: (data, version) => {
|
|
62
|
+
switch (version) {
|
|
63
|
+
case 1:
|
|
64
|
+
return v1.encodeReadRangeWire(data as v1.ReadRangeWire);
|
|
65
|
+
default:
|
|
66
|
+
throw new Error(`Unknown ReadRangeWire version ${version}`);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
deserializeConverters: () => [],
|
|
70
|
+
serializeConverters: () => [],
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export { decodeReadRangeWire, encodeReadRangeWire } from "../dist/schemas/v1";
|
|
74
|
+
|
|
75
|
+
const recordConfig = bare.Config({});
|
|
76
|
+
const chunkConfig = bare.Config({});
|
|
77
|
+
|
|
78
|
+
export function encodeChunk(chunk: v1.Chunk): Uint8Array {
|
|
79
|
+
const bc = new bare.ByteCursor(
|
|
80
|
+
new Uint8Array(chunkConfig.initialBufferLength),
|
|
81
|
+
chunkConfig,
|
|
82
|
+
);
|
|
83
|
+
v1.writeChunk(bc, chunk);
|
|
84
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function decodeChunk(bytes: Uint8Array): v1.Chunk {
|
|
88
|
+
const bc = new bare.ByteCursor(bytes, chunkConfig);
|
|
89
|
+
return v1.readChunk(bc);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function encodeRecord(record: v1.Record): Uint8Array {
|
|
93
|
+
const bc = new bare.ByteCursor(
|
|
94
|
+
new Uint8Array(recordConfig.initialBufferLength),
|
|
95
|
+
recordConfig,
|
|
96
|
+
);
|
|
97
|
+
v1.writeRecord(bc, record);
|
|
98
|
+
return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset);
|
|
99
|
+
}
|
package/src/encoding.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CURRENT_VERSION,
|
|
3
|
+
READ_RANGE_VERSIONED,
|
|
4
|
+
type ReadRangeWire,
|
|
5
|
+
} from "../schemas/versioned.js";
|
|
6
|
+
|
|
7
|
+
export type { ReadRangeWire };
|
|
8
|
+
|
|
9
|
+
export function encodeReadRangeWire(wire: ReadRangeWire): Uint8Array {
|
|
10
|
+
return READ_RANGE_VERSIONED.serializeWithEmbeddedVersion(
|
|
11
|
+
wire,
|
|
12
|
+
CURRENT_VERSION,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function decodeReadRangeWire(bytes: Uint8Array): ReadRangeWire {
|
|
17
|
+
return READ_RANGE_VERSIONED.deserializeWithEmbeddedVersion(bytes);
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createNoopTraces } from "./noop.js";
|
|
2
|
+
|
|
3
|
+
// Browser stub: createTraces is server-only (uses node:async_hooks, node:crypto,
|
|
4
|
+
// fdb-tuple). This module is selected via the "browser" export condition so that
|
|
5
|
+
// bundlers like Vite never pull in the real implementation when resolving
|
|
6
|
+
// @rivetkit/traces in a browser context. The function is never actually called
|
|
7
|
+
// in the browser; it only exists because tsup chunk-splitting may place the
|
|
8
|
+
// import in a shared chunk also reached by client code.
|
|
9
|
+
export function createTraces(): never {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"createTraces is not available in the browser. This is a server-only API.",
|
|
12
|
+
);
|
|
13
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createTraces,
|
|
3
|
+
} from "./traces.js";
|
|
4
|
+
export { createNoopTraces } from "./noop.js";
|
|
5
|
+
export type {
|
|
6
|
+
EndSpanOptions,
|
|
7
|
+
EventOptions,
|
|
8
|
+
ReadRangeOptions,
|
|
9
|
+
ReadRangeResult,
|
|
10
|
+
ReadRangeWire,
|
|
11
|
+
SpanHandle,
|
|
12
|
+
SpanStatusInput,
|
|
13
|
+
StartSpanOptions,
|
|
14
|
+
Traces,
|
|
15
|
+
TracesDriver,
|
|
16
|
+
TracesOptions,
|
|
17
|
+
UpdateSpanOptions,
|
|
18
|
+
} from "./types.js";
|
|
19
|
+
export type {
|
|
20
|
+
OtlpAnyValue,
|
|
21
|
+
OtlpExportTraceServiceRequestJson,
|
|
22
|
+
OtlpInstrumentationScope,
|
|
23
|
+
OtlpKeyValue,
|
|
24
|
+
OtlpResource,
|
|
25
|
+
OtlpResourceSpans,
|
|
26
|
+
OtlpScopeSpans,
|
|
27
|
+
OtlpSpan,
|
|
28
|
+
OtlpSpanEvent,
|
|
29
|
+
OtlpSpanLink,
|
|
30
|
+
OtlpSpanStatus,
|
|
31
|
+
} from "./otlp.js";
|
package/src/noop.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { OtlpExportTraceServiceRequestJson } from "./otlp.js";
|
|
2
|
+
import type {
|
|
3
|
+
EndSpanOptions,
|
|
4
|
+
EventOptions,
|
|
5
|
+
ReadRangeOptions,
|
|
6
|
+
ReadRangeResult,
|
|
7
|
+
ReadRangeWire,
|
|
8
|
+
SpanHandle,
|
|
9
|
+
SpanStatusInput,
|
|
10
|
+
StartSpanOptions,
|
|
11
|
+
Traces,
|
|
12
|
+
UpdateSpanOptions,
|
|
13
|
+
} from "./types.js";
|
|
14
|
+
|
|
15
|
+
const U32_MAX = 0xffff_ffff;
|
|
16
|
+
|
|
17
|
+
const NOOP_SPAN: SpanHandle = {
|
|
18
|
+
spanId: new Uint8Array(8),
|
|
19
|
+
traceId: new Uint8Array(16),
|
|
20
|
+
isActive: () => false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function createEmptyOtlpExport(): OtlpExportTraceServiceRequestJson {
|
|
24
|
+
return {
|
|
25
|
+
resourceSpans: [
|
|
26
|
+
{
|
|
27
|
+
scopeSpans: [{ spans: [] }],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Implements the Traces contract without persisting or exporting trace data.
|
|
35
|
+
*/
|
|
36
|
+
export function createNoopTraces(): Traces<OtlpExportTraceServiceRequestJson> {
|
|
37
|
+
return {
|
|
38
|
+
startSpan(_name: string, _options?: StartSpanOptions): SpanHandle {
|
|
39
|
+
return NOOP_SPAN;
|
|
40
|
+
},
|
|
41
|
+
updateSpan(_handle: SpanHandle, _options: UpdateSpanOptions): void {},
|
|
42
|
+
setAttributes(
|
|
43
|
+
_handle: SpanHandle,
|
|
44
|
+
_attributes: Record<string, unknown>,
|
|
45
|
+
): void {},
|
|
46
|
+
setStatus(_handle: SpanHandle, _status: SpanStatusInput): void {},
|
|
47
|
+
endSpan(_handle: SpanHandle, _options?: EndSpanOptions): void {},
|
|
48
|
+
emitEvent(
|
|
49
|
+
_handle: SpanHandle,
|
|
50
|
+
_name: string,
|
|
51
|
+
_options?: EventOptions,
|
|
52
|
+
): void {},
|
|
53
|
+
withSpan<T>(_handle: SpanHandle, fn: () => T): T {
|
|
54
|
+
return fn();
|
|
55
|
+
},
|
|
56
|
+
getCurrentSpan(): SpanHandle | null {
|
|
57
|
+
return null;
|
|
58
|
+
},
|
|
59
|
+
async flush(): Promise<boolean> {
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
async readRange(
|
|
63
|
+
_options: ReadRangeOptions,
|
|
64
|
+
): Promise<ReadRangeResult<OtlpExportTraceServiceRequestJson>> {
|
|
65
|
+
return {
|
|
66
|
+
otlp: createEmptyOtlpExport(),
|
|
67
|
+
clamped: false,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
async readRangeWire(options: ReadRangeOptions): Promise<ReadRangeWire> {
|
|
71
|
+
return {
|
|
72
|
+
startTimeMs: BigInt(options.startMs),
|
|
73
|
+
endTimeMs: BigInt(options.endMs),
|
|
74
|
+
limit: Math.max(0, Math.min(U32_MAX, Math.floor(options.limit))),
|
|
75
|
+
clamped: false,
|
|
76
|
+
baseChunks: [],
|
|
77
|
+
chunks: [],
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { readRangeWireToOtlp } from "./read-range.js";
|
|
2
|
+
export {
|
|
3
|
+
anyValueFromCborBytes,
|
|
4
|
+
anyValueFromJs,
|
|
5
|
+
base64FromBytes,
|
|
6
|
+
hexFromBytes,
|
|
7
|
+
type OtlpAnyValue,
|
|
8
|
+
type OtlpExportTraceServiceRequestJson,
|
|
9
|
+
type OtlpInstrumentationScope,
|
|
10
|
+
type OtlpKeyValue,
|
|
11
|
+
type OtlpResource,
|
|
12
|
+
type OtlpResourceSpans,
|
|
13
|
+
type OtlpScopeSpans,
|
|
14
|
+
type OtlpSpan,
|
|
15
|
+
type OtlpSpanEvent,
|
|
16
|
+
type OtlpSpanLink,
|
|
17
|
+
type OtlpSpanStatus,
|
|
18
|
+
} from "./otlp.js";
|