@effect/opentelemetry 0.60.0 → 0.61.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.
Files changed (67) hide show
  1. package/OtlpSerialization/package.json +6 -0
  2. package/dist/cjs/Otlp.js +19 -1
  3. package/dist/cjs/Otlp.js.map +1 -1
  4. package/dist/cjs/OtlpLogger.js +13 -8
  5. package/dist/cjs/OtlpLogger.js.map +1 -1
  6. package/dist/cjs/OtlpMetrics.js +4 -1
  7. package/dist/cjs/OtlpMetrics.js.map +1 -1
  8. package/dist/cjs/OtlpSerialization.js +55 -0
  9. package/dist/cjs/OtlpSerialization.js.map +1 -0
  10. package/dist/cjs/OtlpTracer.js +3 -1
  11. package/dist/cjs/OtlpTracer.js.map +1 -1
  12. package/dist/cjs/index.js +3 -1
  13. package/dist/cjs/internal/otlpExporter.js +3 -1
  14. package/dist/cjs/internal/otlpExporter.js.map +1 -1
  15. package/dist/cjs/internal/otlpProtobuf.js +430 -0
  16. package/dist/cjs/internal/otlpProtobuf.js.map +1 -0
  17. package/dist/cjs/internal/protobuf.js +183 -0
  18. package/dist/cjs/internal/protobuf.js.map +1 -0
  19. package/dist/cjs/internal/tracer.js +9 -2
  20. package/dist/cjs/internal/tracer.js.map +1 -1
  21. package/dist/dts/Otlp.d.ts +49 -0
  22. package/dist/dts/Otlp.d.ts.map +1 -1
  23. package/dist/dts/OtlpLogger.d.ts +3 -2
  24. package/dist/dts/OtlpLogger.d.ts.map +1 -1
  25. package/dist/dts/OtlpMetrics.d.ts +3 -2
  26. package/dist/dts/OtlpMetrics.d.ts.map +1 -1
  27. package/dist/dts/OtlpSerialization.d.ts +53 -0
  28. package/dist/dts/OtlpSerialization.d.ts.map +1 -0
  29. package/dist/dts/OtlpTracer.d.ts +3 -2
  30. package/dist/dts/OtlpTracer.d.ts.map +1 -1
  31. package/dist/dts/index.d.ts +9 -0
  32. package/dist/dts/index.d.ts.map +1 -1
  33. package/dist/dts/internal/otlpProtobuf.d.ts +501 -0
  34. package/dist/dts/internal/otlpProtobuf.d.ts.map +1 -0
  35. package/dist/dts/internal/protobuf.d.ts +100 -0
  36. package/dist/dts/internal/protobuf.d.ts.map +1 -0
  37. package/dist/esm/Otlp.js +18 -0
  38. package/dist/esm/Otlp.js.map +1 -1
  39. package/dist/esm/OtlpLogger.js +13 -8
  40. package/dist/esm/OtlpLogger.js.map +1 -1
  41. package/dist/esm/OtlpMetrics.js +4 -1
  42. package/dist/esm/OtlpMetrics.js.map +1 -1
  43. package/dist/esm/OtlpSerialization.js +46 -0
  44. package/dist/esm/OtlpSerialization.js.map +1 -0
  45. package/dist/esm/OtlpTracer.js +3 -1
  46. package/dist/esm/OtlpTracer.js.map +1 -1
  47. package/dist/esm/index.js +9 -0
  48. package/dist/esm/index.js.map +1 -1
  49. package/dist/esm/internal/otlpExporter.js +3 -1
  50. package/dist/esm/internal/otlpExporter.js.map +1 -1
  51. package/dist/esm/internal/otlpProtobuf.js +396 -0
  52. package/dist/esm/internal/otlpProtobuf.js.map +1 -0
  53. package/dist/esm/internal/protobuf.js +155 -0
  54. package/dist/esm/internal/protobuf.js.map +1 -0
  55. package/dist/esm/internal/tracer.js +9 -2
  56. package/dist/esm/internal/tracer.js.map +1 -1
  57. package/package.json +11 -26
  58. package/src/Otlp.ts +53 -1
  59. package/src/OtlpLogger.ts +15 -10
  60. package/src/OtlpMetrics.ts +8 -4
  61. package/src/OtlpSerialization.ts +64 -0
  62. package/src/OtlpTracer.ts +6 -3
  63. package/src/index.ts +10 -0
  64. package/src/internal/otlpExporter.ts +6 -4
  65. package/src/internal/otlpProtobuf.ts +729 -0
  66. package/src/internal/protobuf.ts +219 -0
  67. package/src/internal/tracer.ts +13 -2
@@ -0,0 +1,729 @@
1
+ /**
2
+ * OTLP Protobuf encoding for traces, metrics, and logs.
3
+ *
4
+ * Implements the protobuf wire format according to:
5
+ * https://github.com/open-telemetry/opentelemetry-proto
6
+ *
7
+ * @internal
8
+ */
9
+
10
+ import type { AnyValue, KeyValue, Resource } from "../OtlpResource.js"
11
+ import * as Proto from "./protobuf.js"
12
+
13
+ // Common types (opentelemetry.proto.common.v1)
14
+
15
+ /**
16
+ * Encodes an AnyValue message.
17
+ *
18
+ * message AnyValue {
19
+ * oneof value {
20
+ * string string_value = 1;
21
+ * bool bool_value = 2;
22
+ * int64 int_value = 3;
23
+ * double double_value = 4;
24
+ * ArrayValue array_value = 5;
25
+ * KeyValueList kvlist_value = 6;
26
+ * bytes bytes_value = 7;
27
+ * }
28
+ * }
29
+ */
30
+ export const encodeAnyValue = (value: AnyValue): Uint8Array => {
31
+ if (value.stringValue !== undefined && value.stringValue !== null) {
32
+ return Proto.stringField(1, value.stringValue)
33
+ }
34
+ if (value.boolValue !== undefined && value.boolValue !== null) {
35
+ return Proto.boolField(2, value.boolValue)
36
+ }
37
+ if (value.intValue !== undefined && value.intValue !== null) {
38
+ return Proto.varintField(3, BigInt(value.intValue))
39
+ }
40
+ if (value.doubleValue !== undefined && value.doubleValue !== null) {
41
+ return Proto.doubleField(4, value.doubleValue)
42
+ }
43
+ if (value.arrayValue !== undefined) {
44
+ return Proto.messageField(5, encodeArrayValue(value.arrayValue))
45
+ }
46
+ if (value.kvlistValue !== undefined) {
47
+ return Proto.messageField(6, encodeKeyValueList(value.kvlistValue))
48
+ }
49
+ if (value.bytesValue !== undefined) {
50
+ return Proto.lengthDelimitedField(7, value.bytesValue)
51
+ }
52
+ return new Uint8Array(0)
53
+ }
54
+
55
+ /**
56
+ * Encodes an ArrayValue message.
57
+ *
58
+ * message ArrayValue {
59
+ * repeated AnyValue values = 1;
60
+ * }
61
+ */
62
+ export const encodeArrayValue = (value: { values: ReadonlyArray<AnyValue> }): Uint8Array =>
63
+ Proto.repeatedField(1, value.values, encodeAnyValue)
64
+
65
+ /**
66
+ * Encodes a KeyValueList message.
67
+ *
68
+ * message KeyValueList {
69
+ * repeated KeyValue values = 1;
70
+ * }
71
+ */
72
+ export const encodeKeyValueList = (value: { values: ReadonlyArray<KeyValue> }): Uint8Array =>
73
+ Proto.repeatedField(1, value.values, encodeKeyValue)
74
+
75
+ /**
76
+ * Encodes a KeyValue message.
77
+ *
78
+ * message KeyValue {
79
+ * string key = 1;
80
+ * AnyValue value = 2;
81
+ * }
82
+ */
83
+ export const encodeKeyValue = (kv: KeyValue): Uint8Array =>
84
+ Proto.concat(
85
+ Proto.stringField(1, kv.key),
86
+ Proto.messageField(2, encodeAnyValue(kv.value))
87
+ )
88
+
89
+ /**
90
+ * Encodes an InstrumentationScope message.
91
+ *
92
+ * message InstrumentationScope {
93
+ * string name = 1;
94
+ * string version = 2;
95
+ * repeated KeyValue attributes = 3;
96
+ * uint32 dropped_attributes_count = 4;
97
+ * }
98
+ */
99
+ export const encodeInstrumentationScope = (scope: {
100
+ readonly name: string
101
+ readonly version?: string
102
+ readonly attributes?: ReadonlyArray<KeyValue>
103
+ readonly droppedAttributesCount?: number
104
+ }): Uint8Array =>
105
+ Proto.concat(
106
+ Proto.stringField(1, scope.name),
107
+ Proto.optionalStringField(2, scope.version),
108
+ scope.attributes ? Proto.repeatedField(3, scope.attributes, encodeKeyValue) : new Uint8Array(0),
109
+ scope.droppedAttributesCount ? Proto.varintField(4, scope.droppedAttributesCount) : new Uint8Array(0)
110
+ )
111
+
112
+ // Resource types (opentelemetry.proto.resource.v1)
113
+
114
+ /**
115
+ * Encodes a Resource message.
116
+ *
117
+ * message Resource {
118
+ * repeated KeyValue attributes = 1;
119
+ * uint32 dropped_attributes_count = 2;
120
+ * }
121
+ */
122
+ export const encodeResource = (resource: Resource): Uint8Array =>
123
+ Proto.concat(
124
+ Proto.repeatedField(1, resource.attributes, encodeKeyValue),
125
+ resource.droppedAttributesCount > 0
126
+ ? Proto.varintField(2, resource.droppedAttributesCount)
127
+ : new Uint8Array(0)
128
+ )
129
+
130
+ // Trace types (opentelemetry.proto.trace.v1)
131
+
132
+ /**
133
+ * Status code enum
134
+ */
135
+ export const StatusCode = {
136
+ Unset: 0,
137
+ Ok: 1,
138
+ Error: 2
139
+ } as const
140
+
141
+ /**
142
+ * SpanKind enum
143
+ */
144
+ export const SpanKind = {
145
+ Unspecified: 0,
146
+ Internal: 1,
147
+ Server: 2,
148
+ Client: 3,
149
+ Producer: 4,
150
+ Consumer: 5
151
+ } as const
152
+
153
+ /**
154
+ * Encodes a Status message.
155
+ *
156
+ * message Status {
157
+ * string message = 2;
158
+ * StatusCode code = 3;
159
+ * }
160
+ */
161
+ export const encodeStatus = (status: {
162
+ readonly code: number
163
+ readonly message?: string
164
+ }): Uint8Array =>
165
+ Proto.concat(
166
+ Proto.optionalStringField(2, status.message),
167
+ Proto.varintField(3, status.code)
168
+ )
169
+
170
+ /**
171
+ * Encodes an Event message.
172
+ *
173
+ * message Event {
174
+ * fixed64 time_unix_nano = 1;
175
+ * string name = 2;
176
+ * repeated KeyValue attributes = 3;
177
+ * uint32 dropped_attributes_count = 4;
178
+ * }
179
+ */
180
+ export const encodeEvent = (event: {
181
+ readonly timeUnixNano: string
182
+ readonly name: string
183
+ readonly attributes: ReadonlyArray<KeyValue>
184
+ readonly droppedAttributesCount: number
185
+ }): Uint8Array =>
186
+ Proto.concat(
187
+ Proto.fixed64Field(1, BigInt(event.timeUnixNano)),
188
+ Proto.stringField(2, event.name),
189
+ Proto.repeatedField(3, event.attributes, encodeKeyValue),
190
+ event.droppedAttributesCount > 0
191
+ ? Proto.varintField(4, event.droppedAttributesCount)
192
+ : new Uint8Array(0)
193
+ )
194
+
195
+ /**
196
+ * Encodes a Link message.
197
+ *
198
+ * message Link {
199
+ * bytes trace_id = 1;
200
+ * bytes span_id = 2;
201
+ * string trace_state = 3;
202
+ * repeated KeyValue attributes = 4;
203
+ * uint32 dropped_attributes_count = 5;
204
+ * fixed32 flags = 6;
205
+ * }
206
+ */
207
+ export const encodeLink = (link: {
208
+ readonly traceId: string
209
+ readonly spanId: string
210
+ readonly traceState?: string
211
+ readonly attributes: ReadonlyArray<KeyValue>
212
+ readonly droppedAttributesCount: number
213
+ readonly flags?: number
214
+ }): Uint8Array =>
215
+ Proto.concat(
216
+ Proto.bytesFieldFromHex(1, link.traceId),
217
+ Proto.bytesFieldFromHex(2, link.spanId),
218
+ Proto.optionalStringField(3, link.traceState),
219
+ Proto.repeatedField(4, link.attributes, encodeKeyValue),
220
+ link.droppedAttributesCount > 0
221
+ ? Proto.varintField(5, link.droppedAttributesCount)
222
+ : new Uint8Array(0),
223
+ link.flags !== undefined ? Proto.fixed32Field(6, link.flags) : new Uint8Array(0)
224
+ )
225
+
226
+ /**
227
+ * Encodes a Span message.
228
+ *
229
+ * message Span {
230
+ * bytes trace_id = 1;
231
+ * bytes span_id = 2;
232
+ * string trace_state = 3;
233
+ * bytes parent_span_id = 4;
234
+ * string name = 5;
235
+ * SpanKind kind = 6;
236
+ * fixed64 start_time_unix_nano = 7;
237
+ * fixed64 end_time_unix_nano = 8;
238
+ * repeated KeyValue attributes = 9;
239
+ * uint32 dropped_attributes_count = 10;
240
+ * repeated Event events = 11;
241
+ * uint32 dropped_events_count = 12;
242
+ * repeated Link links = 13;
243
+ * uint32 dropped_links_count = 14;
244
+ * Status status = 15;
245
+ * fixed32 flags = 16;
246
+ * }
247
+ */
248
+ export const encodeSpan = (span: {
249
+ readonly traceId: string
250
+ readonly spanId: string
251
+ readonly traceState?: string
252
+ readonly parentSpanId?: string
253
+ readonly name: string
254
+ readonly kind: number
255
+ readonly startTimeUnixNano: string
256
+ readonly endTimeUnixNano: string
257
+ readonly attributes: ReadonlyArray<KeyValue>
258
+ readonly droppedAttributesCount: number
259
+ readonly events: ReadonlyArray<{
260
+ readonly timeUnixNano: string
261
+ readonly name: string
262
+ readonly attributes: ReadonlyArray<KeyValue>
263
+ readonly droppedAttributesCount: number
264
+ }>
265
+ readonly droppedEventsCount: number
266
+ readonly links: ReadonlyArray<{
267
+ readonly traceId: string
268
+ readonly spanId: string
269
+ readonly traceState?: string
270
+ readonly attributes: ReadonlyArray<KeyValue>
271
+ readonly droppedAttributesCount: number
272
+ readonly flags?: number
273
+ }>
274
+ readonly droppedLinksCount: number
275
+ readonly status: {
276
+ readonly code: number
277
+ readonly message?: string
278
+ }
279
+ readonly flags?: number
280
+ }): Uint8Array =>
281
+ Proto.concat(
282
+ Proto.bytesFieldFromHex(1, span.traceId),
283
+ Proto.bytesFieldFromHex(2, span.spanId),
284
+ Proto.optionalStringField(3, span.traceState),
285
+ span.parentSpanId !== undefined
286
+ ? Proto.bytesFieldFromHex(4, span.parentSpanId)
287
+ : new Uint8Array(0),
288
+ Proto.stringField(5, span.name),
289
+ Proto.varintField(6, span.kind),
290
+ Proto.fixed64Field(7, BigInt(span.startTimeUnixNano)),
291
+ Proto.fixed64Field(8, BigInt(span.endTimeUnixNano)),
292
+ Proto.repeatedField(9, span.attributes, encodeKeyValue),
293
+ span.droppedAttributesCount > 0
294
+ ? Proto.varintField(10, span.droppedAttributesCount)
295
+ : new Uint8Array(0),
296
+ Proto.repeatedField(11, span.events, encodeEvent),
297
+ span.droppedEventsCount > 0
298
+ ? Proto.varintField(12, span.droppedEventsCount)
299
+ : new Uint8Array(0),
300
+ Proto.repeatedField(13, span.links, encodeLink),
301
+ span.droppedLinksCount > 0
302
+ ? Proto.varintField(14, span.droppedLinksCount)
303
+ : new Uint8Array(0),
304
+ Proto.messageField(15, encodeStatus(span.status)),
305
+ span.flags !== undefined ? Proto.fixed32Field(16, span.flags) : new Uint8Array(0)
306
+ )
307
+
308
+ /**
309
+ * Encodes a ScopeSpans message.
310
+ *
311
+ * message ScopeSpans {
312
+ * InstrumentationScope scope = 1;
313
+ * repeated Span spans = 2;
314
+ * string schema_url = 3;
315
+ * }
316
+ */
317
+ export const encodeScopeSpans = (scopeSpans: {
318
+ readonly scope: { readonly name: string; readonly version?: string }
319
+ readonly spans: ReadonlyArray<Parameters<typeof encodeSpan>[0]>
320
+ readonly schemaUrl?: string
321
+ }): Uint8Array =>
322
+ Proto.concat(
323
+ Proto.messageField(1, encodeInstrumentationScope(scopeSpans.scope)),
324
+ Proto.repeatedField(2, scopeSpans.spans, encodeSpan),
325
+ Proto.optionalStringField(3, scopeSpans.schemaUrl)
326
+ )
327
+
328
+ /**
329
+ * Encodes a ResourceSpans message.
330
+ *
331
+ * message ResourceSpans {
332
+ * Resource resource = 1;
333
+ * repeated ScopeSpans scope_spans = 2;
334
+ * string schema_url = 3;
335
+ * }
336
+ */
337
+ export const encodeResourceSpans = (resourceSpans: {
338
+ readonly resource: Resource
339
+ readonly scopeSpans: ReadonlyArray<Parameters<typeof encodeScopeSpans>[0]>
340
+ readonly schemaUrl?: string
341
+ }): Uint8Array =>
342
+ Proto.concat(
343
+ Proto.messageField(1, encodeResource(resourceSpans.resource)),
344
+ Proto.repeatedField(2, resourceSpans.scopeSpans, encodeScopeSpans),
345
+ Proto.optionalStringField(3, resourceSpans.schemaUrl)
346
+ )
347
+
348
+ /**
349
+ * Encodes a TracesData message (top-level export request).
350
+ *
351
+ * message TracesData {
352
+ * repeated ResourceSpans resource_spans = 1;
353
+ * }
354
+ */
355
+ export const encodeTracesData = (tracesData: {
356
+ readonly resourceSpans: ReadonlyArray<Parameters<typeof encodeResourceSpans>[0]>
357
+ }): Uint8Array => Proto.repeatedField(1, tracesData.resourceSpans, encodeResourceSpans)
358
+
359
+ // Metrics types (opentelemetry.proto.metrics.v1)
360
+
361
+ /**
362
+ * AggregationTemporality enum
363
+ */
364
+ export const AggregationTemporality = {
365
+ Unspecified: 0,
366
+ Delta: 1,
367
+ Cumulative: 2
368
+ } as const
369
+
370
+ /**
371
+ * Encodes a NumberDataPoint message.
372
+ *
373
+ * message NumberDataPoint {
374
+ * repeated KeyValue attributes = 7;
375
+ * fixed64 start_time_unix_nano = 2;
376
+ * fixed64 time_unix_nano = 3;
377
+ * oneof value {
378
+ * double as_double = 4;
379
+ * sfixed64 as_int = 6;
380
+ * }
381
+ * repeated Exemplar exemplars = 5;
382
+ * uint32 flags = 8;
383
+ * }
384
+ */
385
+ export const encodeNumberDataPoint = (point: {
386
+ readonly attributes: ReadonlyArray<KeyValue>
387
+ readonly startTimeUnixNano: string
388
+ readonly timeUnixNano: string
389
+ readonly asDouble?: number | undefined
390
+ readonly asInt?: string | number | bigint | undefined
391
+ readonly flags?: number | undefined
392
+ }): Uint8Array =>
393
+ Proto.concat(
394
+ Proto.fixed64Field(2, BigInt(point.startTimeUnixNano)),
395
+ Proto.fixed64Field(3, BigInt(point.timeUnixNano)),
396
+ point.asDouble !== undefined
397
+ ? Proto.doubleField(4, point.asDouble)
398
+ : new Uint8Array(0),
399
+ point.asInt !== undefined
400
+ ? Proto.fixed64Field(6, BigInt(point.asInt))
401
+ : new Uint8Array(0),
402
+ Proto.repeatedField(7, point.attributes, encodeKeyValue),
403
+ point.flags !== undefined ? Proto.varintField(8, point.flags) : new Uint8Array(0)
404
+ )
405
+
406
+ /**
407
+ * Encodes a HistogramDataPoint message.
408
+ *
409
+ * message HistogramDataPoint {
410
+ * repeated KeyValue attributes = 9;
411
+ * fixed64 start_time_unix_nano = 2;
412
+ * fixed64 time_unix_nano = 3;
413
+ * fixed64 count = 4;
414
+ * optional double sum = 5;
415
+ * repeated fixed64 bucket_counts = 6;
416
+ * repeated double explicit_bounds = 7;
417
+ * optional double min = 11;
418
+ * optional double max = 12;
419
+ * uint32 flags = 10;
420
+ * }
421
+ */
422
+ export const encodeHistogramDataPoint = (point: {
423
+ readonly attributes: ReadonlyArray<KeyValue>
424
+ readonly startTimeUnixNano: string
425
+ readonly timeUnixNano: string
426
+ readonly count: string | number | bigint
427
+ readonly sum?: number | undefined
428
+ readonly bucketCounts: ReadonlyArray<string | number | bigint>
429
+ readonly explicitBounds: ReadonlyArray<number>
430
+ readonly min?: number | undefined
431
+ readonly max?: number | undefined
432
+ readonly flags?: number | undefined
433
+ }): Uint8Array => {
434
+ // Pack bucket counts as repeated fixed64
435
+ const bucketCountsEncoded = Proto.concat(
436
+ ...point.bucketCounts.map((count) => Proto.fixed64Field(6, BigInt(count)))
437
+ )
438
+ // Pack explicit bounds as repeated double
439
+ const explicitBoundsEncoded = Proto.concat(
440
+ ...point.explicitBounds.map((bound) => Proto.doubleField(7, bound))
441
+ )
442
+ return Proto.concat(
443
+ Proto.fixed64Field(2, BigInt(point.startTimeUnixNano)),
444
+ Proto.fixed64Field(3, BigInt(point.timeUnixNano)),
445
+ Proto.fixed64Field(4, BigInt(point.count)),
446
+ point.sum !== undefined ? Proto.doubleField(5, point.sum) : new Uint8Array(0),
447
+ bucketCountsEncoded,
448
+ explicitBoundsEncoded,
449
+ Proto.repeatedField(9, point.attributes, encodeKeyValue),
450
+ point.flags !== undefined ? Proto.varintField(10, point.flags) : new Uint8Array(0),
451
+ point.min !== undefined ? Proto.doubleField(11, point.min) : new Uint8Array(0),
452
+ point.max !== undefined ? Proto.doubleField(12, point.max) : new Uint8Array(0)
453
+ )
454
+ }
455
+
456
+ /**
457
+ * Encodes a Gauge message.
458
+ *
459
+ * message Gauge {
460
+ * repeated NumberDataPoint data_points = 1;
461
+ * }
462
+ */
463
+ export const encodeGauge = (gauge: {
464
+ readonly dataPoints: ReadonlyArray<Parameters<typeof encodeNumberDataPoint>[0]>
465
+ }): Uint8Array => Proto.repeatedField(1, gauge.dataPoints, encodeNumberDataPoint)
466
+
467
+ /**
468
+ * Encodes a Sum message.
469
+ *
470
+ * message Sum {
471
+ * repeated NumberDataPoint data_points = 1;
472
+ * AggregationTemporality aggregation_temporality = 2;
473
+ * bool is_monotonic = 3;
474
+ * }
475
+ */
476
+ export const encodeSum = (sum: {
477
+ readonly dataPoints: ReadonlyArray<Parameters<typeof encodeNumberDataPoint>[0]>
478
+ readonly aggregationTemporality: number
479
+ readonly isMonotonic: boolean
480
+ }): Uint8Array =>
481
+ Proto.concat(
482
+ Proto.repeatedField(1, sum.dataPoints, encodeNumberDataPoint),
483
+ Proto.varintField(2, sum.aggregationTemporality),
484
+ Proto.boolField(3, sum.isMonotonic)
485
+ )
486
+
487
+ /**
488
+ * Encodes a Histogram message.
489
+ *
490
+ * message Histogram {
491
+ * repeated HistogramDataPoint data_points = 1;
492
+ * AggregationTemporality aggregation_temporality = 2;
493
+ * }
494
+ */
495
+ export const encodeHistogram = (histogram: {
496
+ readonly dataPoints: ReadonlyArray<Parameters<typeof encodeHistogramDataPoint>[0]>
497
+ readonly aggregationTemporality: number
498
+ }): Uint8Array =>
499
+ Proto.concat(
500
+ Proto.repeatedField(1, histogram.dataPoints, encodeHistogramDataPoint),
501
+ Proto.varintField(2, histogram.aggregationTemporality)
502
+ )
503
+
504
+ /**
505
+ * Encodes a Metric message.
506
+ *
507
+ * message Metric {
508
+ * string name = 1;
509
+ * string description = 2;
510
+ * string unit = 3;
511
+ * oneof data {
512
+ * Gauge gauge = 5;
513
+ * Sum sum = 7;
514
+ * Histogram histogram = 9;
515
+ * ExponentialHistogram exponential_histogram = 10;
516
+ * Summary summary = 11;
517
+ * }
518
+ * }
519
+ */
520
+ export const encodeMetric = (metric: {
521
+ readonly name: string
522
+ readonly description?: string | undefined
523
+ readonly unit?: string | undefined
524
+ readonly gauge?: Parameters<typeof encodeGauge>[0] | undefined
525
+ readonly sum?: Parameters<typeof encodeSum>[0] | undefined
526
+ readonly histogram?: Parameters<typeof encodeHistogram>[0] | undefined
527
+ }): Uint8Array =>
528
+ Proto.concat(
529
+ Proto.stringField(1, metric.name),
530
+ Proto.optionalStringField(2, metric.description),
531
+ Proto.optionalStringField(3, metric.unit),
532
+ metric.gauge !== undefined
533
+ ? Proto.messageField(5, encodeGauge(metric.gauge))
534
+ : new Uint8Array(0),
535
+ metric.sum !== undefined
536
+ ? Proto.messageField(7, encodeSum(metric.sum))
537
+ : new Uint8Array(0),
538
+ metric.histogram !== undefined
539
+ ? Proto.messageField(9, encodeHistogram(metric.histogram))
540
+ : new Uint8Array(0)
541
+ )
542
+
543
+ /**
544
+ * Encodes a ScopeMetrics message.
545
+ *
546
+ * message ScopeMetrics {
547
+ * InstrumentationScope scope = 1;
548
+ * repeated Metric metrics = 2;
549
+ * string schema_url = 3;
550
+ * }
551
+ */
552
+ export const encodeScopeMetrics = (scopeMetrics: {
553
+ readonly scope: { readonly name: string; readonly version?: string }
554
+ readonly metrics: ReadonlyArray<Parameters<typeof encodeMetric>[0]>
555
+ readonly schemaUrl?: string
556
+ }): Uint8Array =>
557
+ Proto.concat(
558
+ Proto.messageField(1, encodeInstrumentationScope(scopeMetrics.scope)),
559
+ Proto.repeatedField(2, scopeMetrics.metrics, encodeMetric),
560
+ Proto.optionalStringField(3, scopeMetrics.schemaUrl)
561
+ )
562
+
563
+ /**
564
+ * Encodes a ResourceMetrics message.
565
+ *
566
+ * message ResourceMetrics {
567
+ * Resource resource = 1;
568
+ * repeated ScopeMetrics scope_metrics = 2;
569
+ * string schema_url = 3;
570
+ * }
571
+ */
572
+ export const encodeResourceMetrics = (resourceMetrics: {
573
+ readonly resource: Resource
574
+ readonly scopeMetrics: ReadonlyArray<Parameters<typeof encodeScopeMetrics>[0]>
575
+ readonly schemaUrl?: string
576
+ }): Uint8Array =>
577
+ Proto.concat(
578
+ Proto.messageField(1, encodeResource(resourceMetrics.resource)),
579
+ Proto.repeatedField(2, resourceMetrics.scopeMetrics, encodeScopeMetrics),
580
+ Proto.optionalStringField(3, resourceMetrics.schemaUrl)
581
+ )
582
+
583
+ /**
584
+ * Encodes a MetricsData message (top-level export request).
585
+ *
586
+ * message MetricsData {
587
+ * repeated ResourceMetrics resource_metrics = 1;
588
+ * }
589
+ */
590
+ export const encodeMetricsData = (metricsData: {
591
+ readonly resourceMetrics: ReadonlyArray<Parameters<typeof encodeResourceMetrics>[0]>
592
+ }): Uint8Array => Proto.repeatedField(1, metricsData.resourceMetrics, encodeResourceMetrics)
593
+
594
+ // Logs types (opentelemetry.proto.logs.v1)
595
+
596
+ /**
597
+ * SeverityNumber enum
598
+ */
599
+ export const SeverityNumber = {
600
+ Unspecified: 0,
601
+ Trace: 1,
602
+ Trace2: 2,
603
+ Trace3: 3,
604
+ Trace4: 4,
605
+ Debug: 5,
606
+ Debug2: 6,
607
+ Debug3: 7,
608
+ Debug4: 8,
609
+ Info: 9,
610
+ Info2: 10,
611
+ Info3: 11,
612
+ Info4: 12,
613
+ Warn: 13,
614
+ Warn2: 14,
615
+ Warn3: 15,
616
+ Warn4: 16,
617
+ Error: 17,
618
+ Error2: 18,
619
+ Error3: 19,
620
+ Error4: 20,
621
+ Fatal: 21,
622
+ Fatal2: 22,
623
+ Fatal3: 23,
624
+ Fatal4: 24
625
+ } as const
626
+
627
+ /**
628
+ * Encodes a LogRecord message.
629
+ *
630
+ * message LogRecord {
631
+ * fixed64 time_unix_nano = 1;
632
+ * fixed64 observed_time_unix_nano = 11;
633
+ * SeverityNumber severity_number = 2;
634
+ * string severity_text = 3;
635
+ * AnyValue body = 5;
636
+ * repeated KeyValue attributes = 6;
637
+ * uint32 dropped_attributes_count = 7;
638
+ * fixed32 flags = 8;
639
+ * bytes trace_id = 9;
640
+ * bytes span_id = 10;
641
+ * }
642
+ */
643
+ export const encodeLogRecord = (record: {
644
+ readonly timeUnixNano: string
645
+ readonly observedTimeUnixNano?: string | undefined
646
+ readonly severityNumber?: number | undefined
647
+ readonly severityText?: string | undefined
648
+ readonly body?: AnyValue | undefined
649
+ readonly attributes: ReadonlyArray<KeyValue>
650
+ readonly droppedAttributesCount?: number | undefined
651
+ readonly flags?: number | undefined
652
+ readonly traceId?: string | undefined
653
+ readonly spanId?: string | undefined
654
+ }): Uint8Array =>
655
+ Proto.concat(
656
+ Proto.fixed64Field(1, BigInt(record.timeUnixNano)),
657
+ record.severityNumber !== undefined
658
+ ? Proto.varintField(2, record.severityNumber)
659
+ : new Uint8Array(0),
660
+ Proto.optionalStringField(3, record.severityText),
661
+ record.body !== undefined
662
+ ? Proto.messageField(5, encodeAnyValue(record.body))
663
+ : new Uint8Array(0),
664
+ Proto.repeatedField(6, record.attributes, encodeKeyValue),
665
+ record.droppedAttributesCount !== undefined && record.droppedAttributesCount > 0
666
+ ? Proto.varintField(7, record.droppedAttributesCount)
667
+ : new Uint8Array(0),
668
+ record.flags !== undefined ? Proto.fixed32Field(8, record.flags) : new Uint8Array(0),
669
+ record.traceId !== undefined && record.traceId !== ""
670
+ ? Proto.bytesFieldFromHex(9, record.traceId)
671
+ : new Uint8Array(0),
672
+ record.spanId !== undefined && record.spanId !== ""
673
+ ? Proto.bytesFieldFromHex(10, record.spanId)
674
+ : new Uint8Array(0),
675
+ record.observedTimeUnixNano !== undefined
676
+ ? Proto.fixed64Field(11, BigInt(record.observedTimeUnixNano))
677
+ : new Uint8Array(0)
678
+ )
679
+
680
+ /**
681
+ * Encodes a ScopeLogs message.
682
+ *
683
+ * message ScopeLogs {
684
+ * InstrumentationScope scope = 1;
685
+ * repeated LogRecord log_records = 2;
686
+ * string schema_url = 3;
687
+ * }
688
+ */
689
+ export const encodeScopeLogs = (scopeLogs: {
690
+ readonly scope: { readonly name: string; readonly version?: string }
691
+ readonly logRecords: ReadonlyArray<Parameters<typeof encodeLogRecord>[0]>
692
+ readonly schemaUrl?: string
693
+ }): Uint8Array =>
694
+ Proto.concat(
695
+ Proto.messageField(1, encodeInstrumentationScope(scopeLogs.scope)),
696
+ Proto.repeatedField(2, scopeLogs.logRecords, encodeLogRecord),
697
+ Proto.optionalStringField(3, scopeLogs.schemaUrl)
698
+ )
699
+
700
+ /**
701
+ * Encodes a ResourceLogs message.
702
+ *
703
+ * message ResourceLogs {
704
+ * Resource resource = 1;
705
+ * repeated ScopeLogs scope_logs = 2;
706
+ * string schema_url = 3;
707
+ * }
708
+ */
709
+ export const encodeResourceLogs = (resourceLogs: {
710
+ readonly resource: Resource
711
+ readonly scopeLogs: ReadonlyArray<Parameters<typeof encodeScopeLogs>[0]>
712
+ readonly schemaUrl?: string
713
+ }): Uint8Array =>
714
+ Proto.concat(
715
+ Proto.messageField(1, encodeResource(resourceLogs.resource)),
716
+ Proto.repeatedField(2, resourceLogs.scopeLogs, encodeScopeLogs),
717
+ Proto.optionalStringField(3, resourceLogs.schemaUrl)
718
+ )
719
+
720
+ /**
721
+ * Encodes a LogsData message (top-level export request).
722
+ *
723
+ * message LogsData {
724
+ * repeated ResourceLogs resource_logs = 1;
725
+ * }
726
+ */
727
+ export const encodeLogsData = (logsData: {
728
+ readonly resourceLogs: ReadonlyArray<Parameters<typeof encodeResourceLogs>[0]>
729
+ }): Uint8Array => Proto.repeatedField(1, logsData.resourceLogs, encodeResourceLogs)