Debian Codegraph @

exporter/debugexporter/internal/otlptext/metrics.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otlptext // import "go.opentelemetry.io/collector/exporter/debugexporter/internal/otlptext"
5
6 import "go.opentelemetry.io/collector/pdata/pmetric"
7
8 // NewTextMetricsMarshaler returns a pmetric.Marshaler to encode to OTLP text bytes.
9 func NewTextMetricsMarshaler() pmetric.Marshaler {
10 return textMetricsMarshaler{}
11 }
12
13 type textMetricsMarshaler struct{}
14
15 // MarshalMetrics pmetric.Metrics to OTLP text.
16 func (textMetricsMarshaler) MarshalMetrics(md pmetric.Metrics) ([]byte, error) {
17 buf := dataBuffer{}
18 rms := md.ResourceMetrics()
19 for i := 0; i < rms.Len(); i++ {
20 buf.logEntry("ResourceMetrics #%d", i)
21 rm := rms.At(i)
22 buf.logEntry("Resource SchemaURL: %s", rm.SchemaUrl())
23 buf.logAttributes("Resource attributes", rm.Resource().Attributes())
24 buf.logEntityRefs(rm.Resource())
25 ilms := rm.ScopeMetrics()
26 for j := 0; j < ilms.Len(); j++ {
27 buf.logEntry("ScopeMetrics #%d", j)
28 ilm := ilms.At(j)
29 buf.logEntry("ScopeMetrics SchemaURL: %s", ilm.SchemaUrl())
30 buf.logInstrumentationScope(ilm.Scope())
31 metrics := ilm.Metrics()
32 for k := 0; k < metrics.Len(); k++ {
33 buf.logEntry("Metric #%d", k)
34 metric := metrics.At(k)
35 buf.logMetricDescriptor(metric)
36 buf.logMetricDataPoints(metric)
37 }
38 }
39 }
40
41 return buf.buf.Bytes(), nil
42 }