@rivetkit/traces 2.0.4-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.
Files changed (56) hide show
  1. package/LICENSE +203 -0
  2. package/dist/schemas/v1.ts +653 -0
  3. package/dist/tsup/chunk-2D7JND4Z.js +63 -0
  4. package/dist/tsup/chunk-2D7JND4Z.js.map +1 -0
  5. package/dist/tsup/chunk-7RQXHEKZ.js +541 -0
  6. package/dist/tsup/chunk-7RQXHEKZ.js.map +1 -0
  7. package/dist/tsup/chunk-DXS2HLRN.cjs +63 -0
  8. package/dist/tsup/chunk-DXS2HLRN.cjs.map +1 -0
  9. package/dist/tsup/chunk-QOSSO6CN.cjs +541 -0
  10. package/dist/tsup/chunk-QOSSO6CN.cjs.map +1 -0
  11. package/dist/tsup/chunk-UNGPFJ4C.js +417 -0
  12. package/dist/tsup/chunk-UNGPFJ4C.js.map +1 -0
  13. package/dist/tsup/chunk-ZTVH74GC.cjs +417 -0
  14. package/dist/tsup/chunk-ZTVH74GC.cjs.map +1 -0
  15. package/dist/tsup/encoding.cjs +20 -0
  16. package/dist/tsup/encoding.cjs.map +1 -0
  17. package/dist/tsup/encoding.d.cts +6 -0
  18. package/dist/tsup/encoding.d.ts +6 -0
  19. package/dist/tsup/encoding.js +20 -0
  20. package/dist/tsup/encoding.js.map +1 -0
  21. package/dist/tsup/index.browser.cjs +15 -0
  22. package/dist/tsup/index.browser.cjs.map +1 -0
  23. package/dist/tsup/index.browser.d.cts +7 -0
  24. package/dist/tsup/index.browser.d.ts +7 -0
  25. package/dist/tsup/index.browser.js +15 -0
  26. package/dist/tsup/index.browser.js.map +1 -0
  27. package/dist/tsup/index.cjs +921 -0
  28. package/dist/tsup/index.cjs.map +1 -0
  29. package/dist/tsup/index.d.cts +9 -0
  30. package/dist/tsup/index.d.ts +9 -0
  31. package/dist/tsup/index.js +921 -0
  32. package/dist/tsup/index.js.map +1 -0
  33. package/dist/tsup/noop-CcgjEgCu.d.cts +99 -0
  34. package/dist/tsup/noop-D-YAZiGa.d.ts +99 -0
  35. package/dist/tsup/otlp-Da4Yz0xC.d.cts +81 -0
  36. package/dist/tsup/otlp-Da4Yz0xC.d.ts +81 -0
  37. package/dist/tsup/otlp-entry.cjs +16 -0
  38. package/dist/tsup/otlp-entry.cjs.map +1 -0
  39. package/dist/tsup/otlp-entry.d.cts +10 -0
  40. package/dist/tsup/otlp-entry.d.ts +10 -0
  41. package/dist/tsup/otlp-entry.js +16 -0
  42. package/dist/tsup/otlp-entry.js.map +1 -0
  43. package/dist/tsup/v1-DovAIc7f.d.cts +118 -0
  44. package/dist/tsup/v1-DovAIc7f.d.ts +118 -0
  45. package/package.json +74 -0
  46. package/schemas/v1.bare +177 -0
  47. package/schemas/versioned.ts +99 -0
  48. package/src/encoding.ts +18 -0
  49. package/src/index.browser.ts +13 -0
  50. package/src/index.ts +31 -0
  51. package/src/noop.ts +81 -0
  52. package/src/otlp-entry.ts +18 -0
  53. package/src/otlp.ts +158 -0
  54. package/src/read-range.ts +502 -0
  55. package/src/traces.ts +1186 -0
  56. package/src/types.ts +94 -0
@@ -0,0 +1,653 @@
1
+ // @generated - post-processed by compile-bare.ts
2
+ import * as bare from "@rivetkit/bare-ts"
3
+
4
+ const config = /* @__PURE__ */ bare.Config({})
5
+
6
+ export type u32 = number
7
+ export type u64 = bigint
8
+
9
+ export type Cbor = ArrayBuffer
10
+
11
+ export function readCbor(bc: bare.ByteCursor): Cbor {
12
+ return bare.readData(bc)
13
+ }
14
+
15
+ export function writeCbor(bc: bare.ByteCursor, x: Cbor): void {
16
+ bare.writeData(bc, x)
17
+ }
18
+
19
+ export type TraceId = ArrayBuffer
20
+
21
+ export function readTraceId(bc: bare.ByteCursor): TraceId {
22
+ return bare.readData(bc)
23
+ }
24
+
25
+ export function writeTraceId(bc: bare.ByteCursor, x: TraceId): void {
26
+ bare.writeData(bc, x)
27
+ }
28
+
29
+ export type SpanId = ArrayBuffer
30
+
31
+ export function readSpanId(bc: bare.ByteCursor): SpanId {
32
+ return bare.readData(bc)
33
+ }
34
+
35
+ export function writeSpanId(bc: bare.ByteCursor, x: SpanId): void {
36
+ bare.writeData(bc, x)
37
+ }
38
+
39
+ export type StringId = u32
40
+
41
+ export function readStringId(bc: bare.ByteCursor): StringId {
42
+ return bare.readU32(bc)
43
+ }
44
+
45
+ export function writeStringId(bc: bare.ByteCursor, x: StringId): void {
46
+ bare.writeU32(bc, x)
47
+ }
48
+
49
+ export type KeyValue = {
50
+ readonly key: StringId,
51
+ readonly value: Cbor,
52
+ }
53
+
54
+ export function readKeyValue(bc: bare.ByteCursor): KeyValue {
55
+ return {
56
+ key: readStringId(bc),
57
+ value: readCbor(bc),
58
+ }
59
+ }
60
+
61
+ export function writeKeyValue(bc: bare.ByteCursor, x: KeyValue): void {
62
+ writeStringId(bc, x.key)
63
+ writeCbor(bc, x.value)
64
+ }
65
+
66
+ export type Attributes = readonly KeyValue[]
67
+
68
+ export function readAttributes(bc: bare.ByteCursor): Attributes {
69
+ const len = bare.readUintSafe(bc)
70
+ if (len === 0) { return [] }
71
+ const result = [readKeyValue(bc)]
72
+ for (let i = 1; i < len; i++) {
73
+ result[i] = readKeyValue(bc)
74
+ }
75
+ return result
76
+ }
77
+
78
+ export function writeAttributes(bc: bare.ByteCursor, x: Attributes): void {
79
+ bare.writeUintSafe(bc, x.length)
80
+ for (let i = 0; i < x.length; i++) {
81
+ writeKeyValue(bc, x[i])
82
+ }
83
+ }
84
+
85
+ export enum SpanStatusCode {
86
+ UNSET = "UNSET",
87
+ OK = "OK",
88
+ ERROR = "ERROR",
89
+ }
90
+
91
+ export function readSpanStatusCode(bc: bare.ByteCursor): SpanStatusCode {
92
+ const offset = bc.offset
93
+ const tag = bare.readU8(bc)
94
+ switch (tag) {
95
+ case 0:
96
+ return SpanStatusCode.UNSET
97
+ case 1:
98
+ return SpanStatusCode.OK
99
+ case 2:
100
+ return SpanStatusCode.ERROR
101
+ default: {
102
+ bc.offset = offset
103
+ throw new bare.BareError(offset, "invalid tag")
104
+ }
105
+ }
106
+ }
107
+
108
+ export function writeSpanStatusCode(bc: bare.ByteCursor, x: SpanStatusCode): void {
109
+ switch (x) {
110
+ case SpanStatusCode.UNSET: {
111
+ bare.writeU8(bc, 0)
112
+ break
113
+ }
114
+ case SpanStatusCode.OK: {
115
+ bare.writeU8(bc, 1)
116
+ break
117
+ }
118
+ case SpanStatusCode.ERROR: {
119
+ bare.writeU8(bc, 2)
120
+ break
121
+ }
122
+ }
123
+ }
124
+
125
+ function read0(bc: bare.ByteCursor): string | null {
126
+ return bare.readBool(bc)
127
+ ? bare.readString(bc)
128
+ : null
129
+ }
130
+
131
+ function write0(bc: bare.ByteCursor, x: string | null): void {
132
+ bare.writeBool(bc, x !== null)
133
+ if (x !== null) {
134
+ bare.writeString(bc, x)
135
+ }
136
+ }
137
+
138
+ export type SpanStatus = {
139
+ readonly code: SpanStatusCode,
140
+ readonly message: string | null,
141
+ }
142
+
143
+ export function readSpanStatus(bc: bare.ByteCursor): SpanStatus {
144
+ return {
145
+ code: readSpanStatusCode(bc),
146
+ message: read0(bc),
147
+ }
148
+ }
149
+
150
+ export function writeSpanStatus(bc: bare.ByteCursor, x: SpanStatus): void {
151
+ writeSpanStatusCode(bc, x.code)
152
+ write0(bc, x.message)
153
+ }
154
+
155
+ export type SpanLink = {
156
+ readonly traceId: TraceId,
157
+ readonly spanId: SpanId,
158
+ readonly traceState: string | null,
159
+ readonly attributes: Attributes,
160
+ readonly droppedAttributesCount: u32,
161
+ }
162
+
163
+ export function readSpanLink(bc: bare.ByteCursor): SpanLink {
164
+ return {
165
+ traceId: readTraceId(bc),
166
+ spanId: readSpanId(bc),
167
+ traceState: read0(bc),
168
+ attributes: readAttributes(bc),
169
+ droppedAttributesCount: bare.readU32(bc),
170
+ }
171
+ }
172
+
173
+ export function writeSpanLink(bc: bare.ByteCursor, x: SpanLink): void {
174
+ writeTraceId(bc, x.traceId)
175
+ writeSpanId(bc, x.spanId)
176
+ write0(bc, x.traceState)
177
+ writeAttributes(bc, x.attributes)
178
+ bare.writeU32(bc, x.droppedAttributesCount)
179
+ }
180
+
181
+ function read1(bc: bare.ByteCursor): SpanId | null {
182
+ return bare.readBool(bc)
183
+ ? readSpanId(bc)
184
+ : null
185
+ }
186
+
187
+ function write1(bc: bare.ByteCursor, x: SpanId | null): void {
188
+ bare.writeBool(bc, x !== null)
189
+ if (x !== null) {
190
+ writeSpanId(bc, x)
191
+ }
192
+ }
193
+
194
+ function read2(bc: bare.ByteCursor): readonly SpanLink[] {
195
+ const len = bare.readUintSafe(bc)
196
+ if (len === 0) { return [] }
197
+ const result = [readSpanLink(bc)]
198
+ for (let i = 1; i < len; i++) {
199
+ result[i] = readSpanLink(bc)
200
+ }
201
+ return result
202
+ }
203
+
204
+ function write2(bc: bare.ByteCursor, x: readonly SpanLink[]): void {
205
+ bare.writeUintSafe(bc, x.length)
206
+ for (let i = 0; i < x.length; i++) {
207
+ writeSpanLink(bc, x[i])
208
+ }
209
+ }
210
+
211
+ export type SpanStart = {
212
+ readonly traceId: TraceId,
213
+ readonly spanId: SpanId,
214
+ readonly parentSpanId: SpanId | null,
215
+ readonly name: StringId,
216
+ readonly kind: u32,
217
+ readonly traceState: string | null,
218
+ readonly flags: u32,
219
+ readonly attributes: Attributes,
220
+ readonly droppedAttributesCount: u32,
221
+ readonly links: readonly SpanLink[],
222
+ readonly droppedLinksCount: u32,
223
+ }
224
+
225
+ export function readSpanStart(bc: bare.ByteCursor): SpanStart {
226
+ return {
227
+ traceId: readTraceId(bc),
228
+ spanId: readSpanId(bc),
229
+ parentSpanId: read1(bc),
230
+ name: readStringId(bc),
231
+ kind: bare.readU32(bc),
232
+ traceState: read0(bc),
233
+ flags: bare.readU32(bc),
234
+ attributes: readAttributes(bc),
235
+ droppedAttributesCount: bare.readU32(bc),
236
+ links: read2(bc),
237
+ droppedLinksCount: bare.readU32(bc),
238
+ }
239
+ }
240
+
241
+ export function writeSpanStart(bc: bare.ByteCursor, x: SpanStart): void {
242
+ writeTraceId(bc, x.traceId)
243
+ writeSpanId(bc, x.spanId)
244
+ write1(bc, x.parentSpanId)
245
+ writeStringId(bc, x.name)
246
+ bare.writeU32(bc, x.kind)
247
+ write0(bc, x.traceState)
248
+ bare.writeU32(bc, x.flags)
249
+ writeAttributes(bc, x.attributes)
250
+ bare.writeU32(bc, x.droppedAttributesCount)
251
+ write2(bc, x.links)
252
+ bare.writeU32(bc, x.droppedLinksCount)
253
+ }
254
+
255
+ function read3(bc: bare.ByteCursor): SpanStatus | null {
256
+ return bare.readBool(bc)
257
+ ? readSpanStatus(bc)
258
+ : null
259
+ }
260
+
261
+ function write3(bc: bare.ByteCursor, x: SpanStatus | null): void {
262
+ bare.writeBool(bc, x !== null)
263
+ if (x !== null) {
264
+ writeSpanStatus(bc, x)
265
+ }
266
+ }
267
+
268
+ export type SpanUpdate = {
269
+ readonly spanId: SpanId,
270
+ readonly attributes: Attributes,
271
+ readonly droppedAttributesCount: u32,
272
+ readonly status: SpanStatus | null,
273
+ }
274
+
275
+ export function readSpanUpdate(bc: bare.ByteCursor): SpanUpdate {
276
+ return {
277
+ spanId: readSpanId(bc),
278
+ attributes: readAttributes(bc),
279
+ droppedAttributesCount: bare.readU32(bc),
280
+ status: read3(bc),
281
+ }
282
+ }
283
+
284
+ export function writeSpanUpdate(bc: bare.ByteCursor, x: SpanUpdate): void {
285
+ writeSpanId(bc, x.spanId)
286
+ writeAttributes(bc, x.attributes)
287
+ bare.writeU32(bc, x.droppedAttributesCount)
288
+ write3(bc, x.status)
289
+ }
290
+
291
+ export type SpanEvent = {
292
+ readonly spanId: SpanId,
293
+ readonly name: StringId,
294
+ readonly attributes: Attributes,
295
+ readonly droppedAttributesCount: u32,
296
+ }
297
+
298
+ export function readSpanEvent(bc: bare.ByteCursor): SpanEvent {
299
+ return {
300
+ spanId: readSpanId(bc),
301
+ name: readStringId(bc),
302
+ attributes: readAttributes(bc),
303
+ droppedAttributesCount: bare.readU32(bc),
304
+ }
305
+ }
306
+
307
+ export function writeSpanEvent(bc: bare.ByteCursor, x: SpanEvent): void {
308
+ writeSpanId(bc, x.spanId)
309
+ writeStringId(bc, x.name)
310
+ writeAttributes(bc, x.attributes)
311
+ bare.writeU32(bc, x.droppedAttributesCount)
312
+ }
313
+
314
+ export type SpanEnd = {
315
+ readonly spanId: SpanId,
316
+ readonly status: SpanStatus | null,
317
+ }
318
+
319
+ export function readSpanEnd(bc: bare.ByteCursor): SpanEnd {
320
+ return {
321
+ spanId: readSpanId(bc),
322
+ status: read3(bc),
323
+ }
324
+ }
325
+
326
+ export function writeSpanEnd(bc: bare.ByteCursor, x: SpanEnd): void {
327
+ writeSpanId(bc, x.spanId)
328
+ write3(bc, x.status)
329
+ }
330
+
331
+ export type SpanSnapshot = {
332
+ readonly traceId: TraceId,
333
+ readonly spanId: SpanId,
334
+ readonly parentSpanId: SpanId | null,
335
+ readonly name: StringId,
336
+ readonly kind: u32,
337
+ readonly startTimeUnixNs: u64,
338
+ readonly traceState: string | null,
339
+ readonly flags: u32,
340
+ readonly attributes: Attributes,
341
+ readonly droppedAttributesCount: u32,
342
+ readonly links: readonly SpanLink[],
343
+ readonly droppedLinksCount: u32,
344
+ readonly status: SpanStatus | null,
345
+ }
346
+
347
+ export function readSpanSnapshot(bc: bare.ByteCursor): SpanSnapshot {
348
+ return {
349
+ traceId: readTraceId(bc),
350
+ spanId: readSpanId(bc),
351
+ parentSpanId: read1(bc),
352
+ name: readStringId(bc),
353
+ kind: bare.readU32(bc),
354
+ startTimeUnixNs: bare.readU64(bc),
355
+ traceState: read0(bc),
356
+ flags: bare.readU32(bc),
357
+ attributes: readAttributes(bc),
358
+ droppedAttributesCount: bare.readU32(bc),
359
+ links: read2(bc),
360
+ droppedLinksCount: bare.readU32(bc),
361
+ status: read3(bc),
362
+ }
363
+ }
364
+
365
+ export function writeSpanSnapshot(bc: bare.ByteCursor, x: SpanSnapshot): void {
366
+ writeTraceId(bc, x.traceId)
367
+ writeSpanId(bc, x.spanId)
368
+ write1(bc, x.parentSpanId)
369
+ writeStringId(bc, x.name)
370
+ bare.writeU32(bc, x.kind)
371
+ bare.writeU64(bc, x.startTimeUnixNs)
372
+ write0(bc, x.traceState)
373
+ bare.writeU32(bc, x.flags)
374
+ writeAttributes(bc, x.attributes)
375
+ bare.writeU32(bc, x.droppedAttributesCount)
376
+ write2(bc, x.links)
377
+ bare.writeU32(bc, x.droppedLinksCount)
378
+ write3(bc, x.status)
379
+ }
380
+
381
+ export type RecordBody =
382
+ | { readonly tag: "SpanStart", readonly val: SpanStart }
383
+ | { readonly tag: "SpanEvent", readonly val: SpanEvent }
384
+ | { readonly tag: "SpanUpdate", readonly val: SpanUpdate }
385
+ | { readonly tag: "SpanEnd", readonly val: SpanEnd }
386
+ | { readonly tag: "SpanSnapshot", readonly val: SpanSnapshot }
387
+
388
+ export function readRecordBody(bc: bare.ByteCursor): RecordBody {
389
+ const offset = bc.offset
390
+ const tag = bare.readU8(bc)
391
+ switch (tag) {
392
+ case 0:
393
+ return { tag: "SpanStart", val: readSpanStart(bc) }
394
+ case 1:
395
+ return { tag: "SpanEvent", val: readSpanEvent(bc) }
396
+ case 2:
397
+ return { tag: "SpanUpdate", val: readSpanUpdate(bc) }
398
+ case 3:
399
+ return { tag: "SpanEnd", val: readSpanEnd(bc) }
400
+ case 4:
401
+ return { tag: "SpanSnapshot", val: readSpanSnapshot(bc) }
402
+ default: {
403
+ bc.offset = offset
404
+ throw new bare.BareError(offset, "invalid tag")
405
+ }
406
+ }
407
+ }
408
+
409
+ export function writeRecordBody(bc: bare.ByteCursor, x: RecordBody): void {
410
+ switch (x.tag) {
411
+ case "SpanStart": {
412
+ bare.writeU8(bc, 0)
413
+ writeSpanStart(bc, x.val)
414
+ break
415
+ }
416
+ case "SpanEvent": {
417
+ bare.writeU8(bc, 1)
418
+ writeSpanEvent(bc, x.val)
419
+ break
420
+ }
421
+ case "SpanUpdate": {
422
+ bare.writeU8(bc, 2)
423
+ writeSpanUpdate(bc, x.val)
424
+ break
425
+ }
426
+ case "SpanEnd": {
427
+ bare.writeU8(bc, 3)
428
+ writeSpanEnd(bc, x.val)
429
+ break
430
+ }
431
+ case "SpanSnapshot": {
432
+ bare.writeU8(bc, 4)
433
+ writeSpanSnapshot(bc, x.val)
434
+ break
435
+ }
436
+ }
437
+ }
438
+
439
+ export type Record = {
440
+ readonly timeOffsetNs: u64,
441
+ readonly body: RecordBody,
442
+ }
443
+
444
+ export function readRecord(bc: bare.ByteCursor): Record {
445
+ return {
446
+ timeOffsetNs: bare.readU64(bc),
447
+ body: readRecordBody(bc),
448
+ }
449
+ }
450
+
451
+ export function writeRecord(bc: bare.ByteCursor, x: Record): void {
452
+ bare.writeU64(bc, x.timeOffsetNs)
453
+ writeRecordBody(bc, x.body)
454
+ }
455
+
456
+ export type SpanRecordKey = {
457
+ readonly prefix: u32,
458
+ readonly bucketStartSec: u64,
459
+ readonly chunkId: u32,
460
+ readonly recordIndex: u32,
461
+ }
462
+
463
+ export function readSpanRecordKey(bc: bare.ByteCursor): SpanRecordKey {
464
+ return {
465
+ prefix: bare.readU32(bc),
466
+ bucketStartSec: bare.readU64(bc),
467
+ chunkId: bare.readU32(bc),
468
+ recordIndex: bare.readU32(bc),
469
+ }
470
+ }
471
+
472
+ export function writeSpanRecordKey(bc: bare.ByteCursor, x: SpanRecordKey): void {
473
+ bare.writeU32(bc, x.prefix)
474
+ bare.writeU64(bc, x.bucketStartSec)
475
+ bare.writeU32(bc, x.chunkId)
476
+ bare.writeU32(bc, x.recordIndex)
477
+ }
478
+
479
+ function read4(bc: bare.ByteCursor): SpanRecordKey | null {
480
+ return bare.readBool(bc)
481
+ ? readSpanRecordKey(bc)
482
+ : null
483
+ }
484
+
485
+ function write4(bc: bare.ByteCursor, x: SpanRecordKey | null): void {
486
+ bare.writeBool(bc, x !== null)
487
+ if (x !== null) {
488
+ writeSpanRecordKey(bc, x)
489
+ }
490
+ }
491
+
492
+ export type ActiveSpanRef = {
493
+ readonly spanId: SpanId,
494
+ readonly startKey: SpanRecordKey,
495
+ readonly latestSnapshotKey: SpanRecordKey | null,
496
+ }
497
+
498
+ export function readActiveSpanRef(bc: bare.ByteCursor): ActiveSpanRef {
499
+ return {
500
+ spanId: readSpanId(bc),
501
+ startKey: readSpanRecordKey(bc),
502
+ latestSnapshotKey: read4(bc),
503
+ }
504
+ }
505
+
506
+ export function writeActiveSpanRef(bc: bare.ByteCursor, x: ActiveSpanRef): void {
507
+ writeSpanId(bc, x.spanId)
508
+ writeSpanRecordKey(bc, x.startKey)
509
+ write4(bc, x.latestSnapshotKey)
510
+ }
511
+
512
+ function read5(bc: bare.ByteCursor): readonly string[] {
513
+ const len = bare.readUintSafe(bc)
514
+ if (len === 0) { return [] }
515
+ const result = [bare.readString(bc)]
516
+ for (let i = 1; i < len; i++) {
517
+ result[i] = bare.readString(bc)
518
+ }
519
+ return result
520
+ }
521
+
522
+ function write5(bc: bare.ByteCursor, x: readonly string[]): void {
523
+ bare.writeUintSafe(bc, x.length)
524
+ for (let i = 0; i < x.length; i++) {
525
+ bare.writeString(bc, x[i])
526
+ }
527
+ }
528
+
529
+ function read6(bc: bare.ByteCursor): readonly Record[] {
530
+ const len = bare.readUintSafe(bc)
531
+ if (len === 0) { return [] }
532
+ const result = [readRecord(bc)]
533
+ for (let i = 1; i < len; i++) {
534
+ result[i] = readRecord(bc)
535
+ }
536
+ return result
537
+ }
538
+
539
+ function write6(bc: bare.ByteCursor, x: readonly Record[]): void {
540
+ bare.writeUintSafe(bc, x.length)
541
+ for (let i = 0; i < x.length; i++) {
542
+ writeRecord(bc, x[i])
543
+ }
544
+ }
545
+
546
+ function read7(bc: bare.ByteCursor): readonly ActiveSpanRef[] {
547
+ const len = bare.readUintSafe(bc)
548
+ if (len === 0) { return [] }
549
+ const result = [readActiveSpanRef(bc)]
550
+ for (let i = 1; i < len; i++) {
551
+ result[i] = readActiveSpanRef(bc)
552
+ }
553
+ return result
554
+ }
555
+
556
+ function write7(bc: bare.ByteCursor, x: readonly ActiveSpanRef[]): void {
557
+ bare.writeUintSafe(bc, x.length)
558
+ for (let i = 0; i < x.length; i++) {
559
+ writeActiveSpanRef(bc, x[i])
560
+ }
561
+ }
562
+
563
+ export type Chunk = {
564
+ readonly baseUnixNs: u64,
565
+ readonly strings: readonly string[],
566
+ readonly records: readonly Record[],
567
+ readonly activeSpans: readonly ActiveSpanRef[],
568
+ }
569
+
570
+ export function readChunk(bc: bare.ByteCursor): Chunk {
571
+ return {
572
+ baseUnixNs: bare.readU64(bc),
573
+ strings: read5(bc),
574
+ records: read6(bc),
575
+ activeSpans: read7(bc),
576
+ }
577
+ }
578
+
579
+ export function writeChunk(bc: bare.ByteCursor, x: Chunk): void {
580
+ bare.writeU64(bc, x.baseUnixNs)
581
+ write5(bc, x.strings)
582
+ write6(bc, x.records)
583
+ write7(bc, x.activeSpans)
584
+ }
585
+
586
+ function read8(bc: bare.ByteCursor): readonly Chunk[] {
587
+ const len = bare.readUintSafe(bc)
588
+ if (len === 0) { return [] }
589
+ const result = [readChunk(bc)]
590
+ for (let i = 1; i < len; i++) {
591
+ result[i] = readChunk(bc)
592
+ }
593
+ return result
594
+ }
595
+
596
+ function write8(bc: bare.ByteCursor, x: readonly Chunk[]): void {
597
+ bare.writeUintSafe(bc, x.length)
598
+ for (let i = 0; i < x.length; i++) {
599
+ writeChunk(bc, x[i])
600
+ }
601
+ }
602
+
603
+ export type ReadRangeWire = {
604
+ readonly startTimeMs: u64,
605
+ readonly endTimeMs: u64,
606
+ readonly limit: u32,
607
+ readonly clamped: boolean,
608
+ readonly baseChunks: readonly Chunk[],
609
+ readonly chunks: readonly Chunk[],
610
+ }
611
+
612
+ export function readReadRangeWire(bc: bare.ByteCursor): ReadRangeWire {
613
+ return {
614
+ startTimeMs: bare.readU64(bc),
615
+ endTimeMs: bare.readU64(bc),
616
+ limit: bare.readU32(bc),
617
+ clamped: bare.readBool(bc),
618
+ baseChunks: read8(bc),
619
+ chunks: read8(bc),
620
+ }
621
+ }
622
+
623
+ export function writeReadRangeWire(bc: bare.ByteCursor, x: ReadRangeWire): void {
624
+ bare.writeU64(bc, x.startTimeMs)
625
+ bare.writeU64(bc, x.endTimeMs)
626
+ bare.writeU32(bc, x.limit)
627
+ bare.writeBool(bc, x.clamped)
628
+ write8(bc, x.baseChunks)
629
+ write8(bc, x.chunks)
630
+ }
631
+
632
+ export function encodeReadRangeWire(x: ReadRangeWire): Uint8Array {
633
+ const bc = new bare.ByteCursor(
634
+ new Uint8Array(config.initialBufferLength),
635
+ config
636
+ )
637
+ writeReadRangeWire(bc, x)
638
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
639
+ }
640
+
641
+ export function decodeReadRangeWire(bytes: Uint8Array): ReadRangeWire {
642
+ const bc = new bare.ByteCursor(bytes, config)
643
+ const result = readReadRangeWire(bc)
644
+ if (bc.offset < bc.view.byteLength) {
645
+ throw new bare.BareError(bc.offset, "remaining bytes")
646
+ }
647
+ return result
648
+ }
649
+
650
+
651
+ function assert(condition: boolean, message?: string): asserts condition {
652
+ if (!condition) throw new Error(message ?? "Assertion failed")
653
+ }
@@ -0,0 +1,63 @@
1
+ // src/noop.ts
2
+ var U32_MAX = 4294967295;
3
+ var NOOP_SPAN = {
4
+ spanId: new Uint8Array(8),
5
+ traceId: new Uint8Array(16),
6
+ isActive: () => false
7
+ };
8
+ function createEmptyOtlpExport() {
9
+ return {
10
+ resourceSpans: [
11
+ {
12
+ scopeSpans: [{ spans: [] }]
13
+ }
14
+ ]
15
+ };
16
+ }
17
+ function createNoopTraces() {
18
+ return {
19
+ startSpan(_name, _options) {
20
+ return NOOP_SPAN;
21
+ },
22
+ updateSpan(_handle, _options) {
23
+ },
24
+ setAttributes(_handle, _attributes) {
25
+ },
26
+ setStatus(_handle, _status) {
27
+ },
28
+ endSpan(_handle, _options) {
29
+ },
30
+ emitEvent(_handle, _name, _options) {
31
+ },
32
+ withSpan(_handle, fn) {
33
+ return fn();
34
+ },
35
+ getCurrentSpan() {
36
+ return null;
37
+ },
38
+ async flush() {
39
+ return false;
40
+ },
41
+ async readRange(_options) {
42
+ return {
43
+ otlp: createEmptyOtlpExport(),
44
+ clamped: false
45
+ };
46
+ },
47
+ async readRangeWire(options) {
48
+ return {
49
+ startTimeMs: BigInt(options.startMs),
50
+ endTimeMs: BigInt(options.endMs),
51
+ limit: Math.max(0, Math.min(U32_MAX, Math.floor(options.limit))),
52
+ clamped: false,
53
+ baseChunks: [],
54
+ chunks: []
55
+ };
56
+ }
57
+ };
58
+ }
59
+
60
+ export {
61
+ createNoopTraces
62
+ };
63
+ //# sourceMappingURL=chunk-2D7JND4Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/noop.ts"],"sourcesContent":["import type { OtlpExportTraceServiceRequestJson } from \"./otlp.js\";\nimport type {\n\tEndSpanOptions,\n\tEventOptions,\n\tReadRangeOptions,\n\tReadRangeResult,\n\tReadRangeWire,\n\tSpanHandle,\n\tSpanStatusInput,\n\tStartSpanOptions,\n\tTraces,\n\tUpdateSpanOptions,\n} from \"./types.js\";\n\nconst U32_MAX = 0xffff_ffff;\n\nconst NOOP_SPAN: SpanHandle = {\n\tspanId: new Uint8Array(8),\n\ttraceId: new Uint8Array(16),\n\tisActive: () => false,\n};\n\nfunction createEmptyOtlpExport(): OtlpExportTraceServiceRequestJson {\n\treturn {\n\t\tresourceSpans: [\n\t\t\t{\n\t\t\t\tscopeSpans: [{ spans: [] }],\n\t\t\t},\n\t\t],\n\t};\n}\n\n/**\n * Implements the Traces contract without persisting or exporting trace data.\n */\nexport function createNoopTraces(): Traces<OtlpExportTraceServiceRequestJson> {\n\treturn {\n\t\tstartSpan(_name: string, _options?: StartSpanOptions): SpanHandle {\n\t\t\treturn NOOP_SPAN;\n\t\t},\n\t\tupdateSpan(_handle: SpanHandle, _options: UpdateSpanOptions): void {},\n\t\tsetAttributes(\n\t\t\t_handle: SpanHandle,\n\t\t\t_attributes: Record<string, unknown>,\n\t\t): void {},\n\t\tsetStatus(_handle: SpanHandle, _status: SpanStatusInput): void {},\n\t\tendSpan(_handle: SpanHandle, _options?: EndSpanOptions): void {},\n\t\temitEvent(\n\t\t\t_handle: SpanHandle,\n\t\t\t_name: string,\n\t\t\t_options?: EventOptions,\n\t\t): void {},\n\t\twithSpan<T>(_handle: SpanHandle, fn: () => T): T {\n\t\t\treturn fn();\n\t\t},\n\t\tgetCurrentSpan(): SpanHandle | null {\n\t\t\treturn null;\n\t\t},\n\t\tasync flush(): Promise<boolean> {\n\t\t\treturn false;\n\t\t},\n\t\tasync readRange(\n\t\t\t_options: ReadRangeOptions,\n\t\t): Promise<ReadRangeResult<OtlpExportTraceServiceRequestJson>> {\n\t\t\treturn {\n\t\t\t\totlp: createEmptyOtlpExport(),\n\t\t\t\tclamped: false,\n\t\t\t};\n\t\t},\n\t\tasync readRangeWire(options: ReadRangeOptions): Promise<ReadRangeWire> {\n\t\t\treturn {\n\t\t\t\tstartTimeMs: BigInt(options.startMs),\n\t\t\t\tendTimeMs: BigInt(options.endMs),\n\t\t\t\tlimit: Math.max(0, Math.min(U32_MAX, Math.floor(options.limit))),\n\t\t\t\tclamped: false,\n\t\t\t\tbaseChunks: [],\n\t\t\t\tchunks: [],\n\t\t\t};\n\t\t},\n\t};\n}\n"],"mappings":";AAcA,IAAM,UAAU;AAEhB,IAAM,YAAwB;AAAA,EAC7B,QAAQ,IAAI,WAAW,CAAC;AAAA,EACxB,SAAS,IAAI,WAAW,EAAE;AAAA,EAC1B,UAAU,MAAM;AACjB;AAEA,SAAS,wBAA2D;AACnE,SAAO;AAAA,IACN,eAAe;AAAA,MACd;AAAA,QACC,YAAY,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC;AAAA,MAC3B;AAAA,IACD;AAAA,EACD;AACD;AAKO,SAAS,mBAA8D;AAC7E,SAAO;AAAA,IACN,UAAU,OAAe,UAAyC;AACjE,aAAO;AAAA,IACR;AAAA,IACA,WAAW,SAAqB,UAAmC;AAAA,IAAC;AAAA,IACpE,cACC,SACA,aACO;AAAA,IAAC;AAAA,IACT,UAAU,SAAqB,SAAgC;AAAA,IAAC;AAAA,IAChE,QAAQ,SAAqB,UAAiC;AAAA,IAAC;AAAA,IAC/D,UACC,SACA,OACA,UACO;AAAA,IAAC;AAAA,IACT,SAAY,SAAqB,IAAgB;AAChD,aAAO,GAAG;AAAA,IACX;AAAA,IACA,iBAAoC;AACnC,aAAO;AAAA,IACR;AAAA,IACA,MAAM,QAA0B;AAC/B,aAAO;AAAA,IACR;AAAA,IACA,MAAM,UACL,UAC8D;AAC9D,aAAO;AAAA,QACN,MAAM,sBAAsB;AAAA,QAC5B,SAAS;AAAA,MACV;AAAA,IACD;AAAA,IACA,MAAM,cAAc,SAAmD;AACtE,aAAO;AAAA,QACN,aAAa,OAAO,QAAQ,OAAO;AAAA,QACnC,WAAW,OAAO,QAAQ,KAAK;AAAA,QAC/B,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC;AAAA,QAC/D,SAAS;AAAA,QACT,YAAY,CAAC;AAAA,QACb,QAAQ,CAAC;AAAA,MACV;AAAA,IACD;AAAA,EACD;AACD;","names":[]}