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