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51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/**
 * OTLP Protobuf encoding for traces, metrics, and logs.
 *
 * Implements the protobuf wire format according to:
 * https://github.com/open-telemetry/opentelemetry-proto
 */
import * as Proto from "./protobuf.js";
// Common types (opentelemetry.proto.common.v1)
/**
 * Encodes an AnyValue message.
 *
 * message AnyValue {
 *   oneof value {
 *     string string_value = 1;
 *     bool bool_value = 2;
 *     int64 int_value = 3;
 *     double double_value = 4;
 *     ArrayValue array_value = 5;
 *     KeyValueList kvlist_value = 6;
 *     bytes bytes_value = 7;
 *   }
 * }
 *
 * @internal
 */
export const encodeAnyValue = value => {
  if (value.stringValue !== undefined && value.stringValue !== null) {
    return Proto.stringField(1, value.stringValue);
  }
  if (value.boolValue !== undefined && value.boolValue !== null) {
    return Proto.boolField(2, value.boolValue);
  }
  if (value.intValue !== undefined && value.intValue !== null) {
    return Proto.varintField(3, BigInt(value.intValue));
  }
  if (value.doubleValue !== undefined && value.doubleValue !== null) {
    return Proto.doubleField(4, value.doubleValue);
  }
  if (value.arrayValue !== undefined) {
    return Proto.messageField(5, encodeArrayValue(value.arrayValue));
  }
  if (value.kvlistValue !== undefined) {
    return Proto.messageField(6, encodeKeyValueList(value.kvlistValue));
  }
  if (value.bytesValue !== undefined) {
    return Proto.lengthDelimitedField(7, value.bytesValue);
  }
  return new Uint8Array(0);
};
/**
 * Encodes an ArrayValue message.
 *
 * message ArrayValue {
 *   repeated AnyValue values = 1;
 * }
 *
 * @internal
 */
export const encodeArrayValue = value => Proto.repeatedField(1, value.values, encodeAnyValue);
/**
 * Encodes a KeyValueList message.
 *
 * message KeyValueList {
 *   repeated KeyValue values = 1;
 * }
 *
 * @internal
 */
export const encodeKeyValueList = value => Proto.repeatedField(1, value.values, encodeKeyValue);
/**
 * Encodes a KeyValue message.
 *
 * message KeyValue {
 *   string key = 1;
 *   AnyValue value = 2;
 * }
 *
 * @internal
 */
export const encodeKeyValue = kv => Proto.concat(Proto.stringField(1, kv.key), Proto.messageField(2, encodeAnyValue(kv.value)));
/**
 * Encodes an InstrumentationScope message.
 *
 * message InstrumentationScope {
 *   string name = 1;
 *   string version = 2;
 *   repeated KeyValue attributes = 3;
 *   uint32 dropped_attributes_count = 4;
 * }
 *
 * @internal
 */
export const encodeInstrumentationScope = scope => Proto.concat(Proto.stringField(1, scope.name), Proto.optionalStringField(2, scope.version), scope.attributes ? Proto.repeatedField(3, scope.attributes, encodeKeyValue) : new Uint8Array(0), scope.droppedAttributesCount ? Proto.varintField(4, scope.droppedAttributesCount) : new Uint8Array(0));
// Resource types (opentelemetry.proto.resource.v1)
/**
 * Encodes a Resource message.
 *
 * message Resource {
 *   repeated KeyValue attributes = 1;
 *   uint32 dropped_attributes_count = 2;
 * }
 *
 * @internal
 */
export const encodeResource = resource => Proto.concat(Proto.repeatedField(1, resource.attributes, encodeKeyValue), resource.droppedAttributesCount > 0 ? Proto.varintField(2, resource.droppedAttributesCount) : new Uint8Array(0));
// Trace types (opentelemetry.proto.trace.v1)
/**
 * Status code enum
 *
 * @internal
 */
export const StatusCode = {
  Unset: 0,
  Ok: 1,
  Error: 2
};
/**
 * SpanKind enum
 *
 * @internal
 */
export const SpanKind = {
  Unspecified: 0,
  Internal: 1,
  Server: 2,
  Client: 3,
  Producer: 4,
  Consumer: 5
};
/**
 * Encodes a Status message.
 *
 * message Status {
 *   string message = 2;
 *   StatusCode code = 3;
 * }
 *
 * @internal
 */
export const encodeStatus = status => Proto.concat(Proto.optionalStringField(2, status.message), Proto.varintField(3, status.code));
/**
 * Encodes an Event message.
 *
 * message Event {
 *   fixed64 time_unix_nano = 1;
 *   string name = 2;
 *   repeated KeyValue attributes = 3;
 *   uint32 dropped_attributes_count = 4;
 * }
 *
 * @internal
 */
export const encodeEvent = event => Proto.concat(Proto.fixed64Field(1, BigInt(event.timeUnixNano)), Proto.stringField(2, event.name), Proto.repeatedField(3, event.attributes, encodeKeyValue), event.droppedAttributesCount > 0 ? Proto.varintField(4, event.droppedAttributesCount) : new Uint8Array(0));
/**
 * Encodes a Link message.
 *
 * message Link {
 *   bytes trace_id = 1;
 *   bytes span_id = 2;
 *   string trace_state = 3;
 *   repeated KeyValue attributes = 4;
 *   uint32 dropped_attributes_count = 5;
 *   fixed32 flags = 6;
 * }
 *
 * @internal
 */
export const encodeLink = link => Proto.concat(Proto.bytesFieldFromHex(1, link.traceId), Proto.bytesFieldFromHex(2, link.spanId), Proto.optionalStringField(3, link.traceState), Proto.repeatedField(4, link.attributes, encodeKeyValue), link.droppedAttributesCount > 0 ? Proto.varintField(5, link.droppedAttributesCount) : new Uint8Array(0), link.flags !== undefined ? Proto.fixed32Field(6, link.flags) : new Uint8Array(0));
/**
 * Encodes a Span message.
 *
 * message Span {
 *   bytes trace_id = 1;
 *   bytes span_id = 2;
 *   string trace_state = 3;
 *   bytes parent_span_id = 4;
 *   string name = 5;
 *   SpanKind kind = 6;
 *   fixed64 start_time_unix_nano = 7;
 *   fixed64 end_time_unix_nano = 8;
 *   repeated KeyValue attributes = 9;
 *   uint32 dropped_attributes_count = 10;
 *   repeated Event events = 11;
 *   uint32 dropped_events_count = 12;
 *   repeated Link links = 13;
 *   uint32 dropped_links_count = 14;
 *   Status status = 15;
 *   fixed32 flags = 16;
 * }
 *
 * @internal
 */
export const encodeSpan = span => Proto.concat(Proto.bytesFieldFromHex(1, span.traceId), Proto.bytesFieldFromHex(2, span.spanId), Proto.optionalStringField(3, span.traceState), span.parentSpanId !== undefined ? Proto.bytesFieldFromHex(4, span.parentSpanId) : new Uint8Array(0), Proto.stringField(5, span.name), Proto.varintField(6, span.kind), Proto.fixed64Field(7, BigInt(span.startTimeUnixNano)), Proto.fixed64Field(8, BigInt(span.endTimeUnixNano)), Proto.repeatedField(9, span.attributes, encodeKeyValue), span.droppedAttributesCount > 0 ? Proto.varintField(10, span.droppedAttributesCount) : new Uint8Array(0), Proto.repeatedField(11, span.events, encodeEvent), span.droppedEventsCount > 0 ? Proto.varintField(12, span.droppedEventsCount) : new Uint8Array(0), Proto.repeatedField(13, span.links, encodeLink), span.droppedLinksCount > 0 ? Proto.varintField(14, span.droppedLinksCount) : new Uint8Array(0), Proto.messageField(15, encodeStatus(span.status)), span.flags !== undefined ? Proto.fixed32Field(16, span.flags) : new Uint8Array(0));
/**
 * Encodes a ScopeSpans message.
 *
 * message ScopeSpans {
 *   InstrumentationScope scope = 1;
 *   repeated Span spans = 2;
 *   string schema_url = 3;
 * }
 *
 * @internal
 */
export const encodeScopeSpans = scopeSpans => Proto.concat(Proto.messageField(1, encodeInstrumentationScope(scopeSpans.scope)), Proto.repeatedField(2, scopeSpans.spans, encodeSpan), Proto.optionalStringField(3, scopeSpans.schemaUrl));
/**
 * Encodes a ResourceSpans message.
 *
 * message ResourceSpans {
 *   Resource resource = 1;
 *   repeated ScopeSpans scope_spans = 2;
 *   string schema_url = 3;
 * }
 *
 * @internal
 */
export const encodeResourceSpans = resourceSpans => Proto.concat(Proto.messageField(1, encodeResource(resourceSpans.resource)), Proto.repeatedField(2, resourceSpans.scopeSpans, encodeScopeSpans), Proto.optionalStringField(3, resourceSpans.schemaUrl));
/**
 * Encodes a TracesData message (top-level export request).
 *
 * message TracesData {
 *   repeated ResourceSpans resource_spans = 1;
 * }
 *
 * @internal
 */
export const encodeTracesData = tracesData => Proto.repeatedField(1, tracesData.resourceSpans, encodeResourceSpans);
// Metrics types (opentelemetry.proto.metrics.v1)
/**
 * AggregationTemporality enum
 *
 * @internal
 */
export const AggregationTemporality = {
  Unspecified: 0,
  Delta: 1,
  Cumulative: 2
};
/**
 * Encodes a NumberDataPoint message.
 *
 * message NumberDataPoint {
 *   repeated KeyValue attributes = 7;
 *   fixed64 start_time_unix_nano = 2;
 *   fixed64 time_unix_nano = 3;
 *   oneof value {
 *     double as_double = 4;
 *     sfixed64 as_int = 6;
 *   }
 *   repeated Exemplar exemplars = 5;
 *   uint32 flags = 8;
 * }
 *
 * @internal
 */
export const encodeNumberDataPoint = point => Proto.concat(Proto.fixed64Field(2, BigInt(point.startTimeUnixNano)), Proto.fixed64Field(3, BigInt(point.timeUnixNano)), point.asDouble !== undefined ? Proto.doubleField(4, point.asDouble) : new Uint8Array(0), point.asInt !== undefined ? Proto.fixed64Field(6, BigInt(point.asInt)) : new Uint8Array(0), Proto.repeatedField(7, point.attributes, encodeKeyValue), point.flags !== undefined ? Proto.varintField(8, point.flags) : new Uint8Array(0));
/**
 * Encodes a HistogramDataPoint message.
 *
 * message HistogramDataPoint {
 *   repeated KeyValue attributes = 9;
 *   fixed64 start_time_unix_nano = 2;
 *   fixed64 time_unix_nano = 3;
 *   fixed64 count = 4;
 *   optional double sum = 5;
 *   repeated fixed64 bucket_counts = 6;
 *   repeated double explicit_bounds = 7;
 *   optional double min = 11;
 *   optional double max = 12;
 *   uint32 flags = 10;
 * }
 *
 * @internal
 */
export const encodeHistogramDataPoint = point => {
  // Pack bucket counts as repeated fixed64
  const bucketCountsEncoded = Proto.concat(...point.bucketCounts.map(count => Proto.fixed64Field(6, BigInt(count))));
  // Pack explicit bounds as repeated double
  const explicitBoundsEncoded = Proto.concat(...point.explicitBounds.map(bound => Proto.doubleField(7, bound)));
  return Proto.concat(Proto.fixed64Field(2, BigInt(point.startTimeUnixNano)), Proto.fixed64Field(3, BigInt(point.timeUnixNano)), Proto.fixed64Field(4, BigInt(point.count)), point.sum !== undefined ? Proto.doubleField(5, point.sum) : new Uint8Array(0), bucketCountsEncoded, explicitBoundsEncoded, Proto.repeatedField(9, point.attributes, encodeKeyValue), point.flags !== undefined ? Proto.varintField(10, point.flags) : new Uint8Array(0), point.min !== undefined ? Proto.doubleField(11, point.min) : new Uint8Array(0), point.max !== undefined ? Proto.doubleField(12, point.max) : new Uint8Array(0));
};
/**
 * Encodes a Gauge message.
 *
 * message Gauge {
 *   repeated NumberDataPoint data_points = 1;
 * }
 *
 * @internal
 */
export const encodeGauge = gauge => Proto.repeatedField(1, gauge.dataPoints, encodeNumberDataPoint);
/**
 * Encodes a Sum message.
 *
 * message Sum {
 *   repeated NumberDataPoint data_points = 1;
 *   AggregationTemporality aggregation_temporality = 2;
 *   bool is_monotonic = 3;
 * }
 *
 * @internal
 */
export const encodeSum = sum => Proto.concat(Proto.repeatedField(1, sum.dataPoints, encodeNumberDataPoint), Proto.varintField(2, sum.aggregationTemporality), Proto.boolField(3, sum.isMonotonic));
/**
 * Encodes a Histogram message.
 *
 * message Histogram {
 *   repeated HistogramDataPoint data_points = 1;
 *   AggregationTemporality aggregation_temporality = 2;
 * }
 *
 * @internal
 */
export const encodeHistogram = histogram => Proto.concat(Proto.repeatedField(1, histogram.dataPoints, encodeHistogramDataPoint), Proto.varintField(2, histogram.aggregationTemporality));
/**
 * Encodes a Metric message.
 *
 * message Metric {
 *   string name = 1;
 *   string description = 2;
 *   string unit = 3;
 *   oneof data {
 *     Gauge gauge = 5;
 *     Sum sum = 7;
 *     Histogram histogram = 9;
 *     ExponentialHistogram exponential_histogram = 10;
 *     Summary summary = 11;
 *   }
 * }
 *
 * @internal
 */
export const encodeMetric = metric => Proto.concat(Proto.stringField(1, metric.name), Proto.optionalStringField(2, metric.description), Proto.optionalStringField(3, metric.unit), metric.gauge !== undefined ? Proto.messageField(5, encodeGauge(metric.gauge)) : new Uint8Array(0), metric.sum !== undefined ? Proto.messageField(7, encodeSum(metric.sum)) : new Uint8Array(0), metric.histogram !== undefined ? Proto.messageField(9, encodeHistogram(metric.histogram)) : new Uint8Array(0));
/**
 * Encodes a ScopeMetrics message.
 *
 * message ScopeMetrics {
 *   InstrumentationScope scope = 1;
 *   repeated Metric metrics = 2;
 *   string schema_url = 3;
 * }
 *
 * @internal
 */
export const encodeScopeMetrics = scopeMetrics => Proto.concat(Proto.messageField(1, encodeInstrumentationScope(scopeMetrics.scope)), Proto.repeatedField(2, scopeMetrics.metrics, encodeMetric), Proto.optionalStringField(3, scopeMetrics.schemaUrl));
/**
 * Encodes a ResourceMetrics message.
 *
 * message ResourceMetrics {
 *   Resource resource = 1;
 *   repeated ScopeMetrics scope_metrics = 2;
 *   string schema_url = 3;
 * }
 *
 * @internal
 */
export const encodeResourceMetrics = resourceMetrics => Proto.concat(Proto.messageField(1, encodeResource(resourceMetrics.resource)), Proto.repeatedField(2, resourceMetrics.scopeMetrics, encodeScopeMetrics), Proto.optionalStringField(3, resourceMetrics.schemaUrl));
/**
 * Encodes a MetricsData message (top-level export request).
 *
 * message MetricsData {
 *   repeated ResourceMetrics resource_metrics = 1;
 * }
 *
 * @internal
 */
export const encodeMetricsData = metricsData => Proto.repeatedField(1, metricsData.resourceMetrics, encodeResourceMetrics);
// Logs types (opentelemetry.proto.logs.v1)
/**
 * SeverityNumber enum
 *
 * @internal
 */
export const SeverityNumber = {
  Unspecified: 0,
  Trace: 1,
  Trace2: 2,
  Trace3: 3,
  Trace4: 4,
  Debug: 5,
  Debug2: 6,
  Debug3: 7,
  Debug4: 8,
  Info: 9,
  Info2: 10,
  Info3: 11,
  Info4: 12,
  Warn: 13,
  Warn2: 14,
  Warn3: 15,
  Warn4: 16,
  Error: 17,
  Error2: 18,
  Error3: 19,
  Error4: 20,
  Fatal: 21,
  Fatal2: 22,
  Fatal3: 23,
  Fatal4: 24
};
/**
 * Encodes a LogRecord message.
 *
 * message LogRecord {
 *   fixed64 time_unix_nano = 1;
 *   fixed64 observed_time_unix_nano = 11;
 *   SeverityNumber severity_number = 2;
 *   string severity_text = 3;
 *   AnyValue body = 5;
 *   repeated KeyValue attributes = 6;
 *   uint32 dropped_attributes_count = 7;
 *   fixed32 flags = 8;
 *   bytes trace_id = 9;
 *   bytes span_id = 10;
 * }
 *
 * @internal
 */
export const encodeLogRecord = record => Proto.concat(Proto.fixed64Field(1, BigInt(record.timeUnixNano)), record.severityNumber !== undefined ? Proto.varintField(2, record.severityNumber) : new Uint8Array(0), Proto.optionalStringField(3, record.severityText), record.body !== undefined ? Proto.messageField(5, encodeAnyValue(record.body)) : new Uint8Array(0), Proto.repeatedField(6, record.attributes, encodeKeyValue), record.droppedAttributesCount !== undefined && record.droppedAttributesCount > 0 ? Proto.varintField(7, record.droppedAttributesCount) : new Uint8Array(0), record.flags !== undefined ? Proto.fixed32Field(8, record.flags) : new Uint8Array(0), record.traceId !== undefined && record.traceId !== "" ? Proto.bytesFieldFromHex(9, record.traceId) : new Uint8Array(0), record.spanId !== undefined && record.spanId !== "" ? Proto.bytesFieldFromHex(10, record.spanId) : new Uint8Array(0), record.observedTimeUnixNano !== undefined ? Proto.fixed64Field(11, BigInt(record.observedTimeUnixNano)) : new Uint8Array(0));
/**
 * Encodes a ScopeLogs message.
 *
 * message ScopeLogs {
 *   InstrumentationScope scope = 1;
 *   repeated LogRecord log_records = 2;
 *   string schema_url = 3;
 * }
 *
 * @internal
 */
export const encodeScopeLogs = scopeLogs => Proto.concat(Proto.messageField(1, encodeInstrumentationScope(scopeLogs.scope)), Proto.repeatedField(2, scopeLogs.logRecords, encodeLogRecord), Proto.optionalStringField(3, scopeLogs.schemaUrl));
/**
 * Encodes a ResourceLogs message.
 *
 * message ResourceLogs {
 *   Resource resource = 1;
 *   repeated ScopeLogs scope_logs = 2;
 *   string schema_url = 3;
 * }
 *
 * @internal
 */
export const encodeResourceLogs = resourceLogs => Proto.concat(Proto.messageField(1, encodeResource(resourceLogs.resource)), Proto.repeatedField(2, resourceLogs.scopeLogs, encodeScopeLogs), Proto.optionalStringField(3, resourceLogs.schemaUrl));
/**
 * Encodes a LogsData message (top-level export request).
 *
 * message LogsData {
 *   repeated ResourceLogs resource_logs = 1;
 * }
 *
 * @internal
 */
export const encodeLogsData = logsData => Proto.repeatedField(1, logsData.resourceLogs, encodeResourceLogs);
//# sourceMappingURL=otlpProtobuf.js.map