Debian Codegraph @

exporter/debugexporter/internal/otlptext/logs.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 (
7 "go.opentelemetry.io/collector/pdata/plog"
8 )
9
10 // NewTextLogsMarshaler returns a plog.Marshaler to encode to OTLP text bytes.
11 func NewTextLogsMarshaler() plog.Marshaler {
12 return textLogsMarshaler{}
13 }
14
15 type textLogsMarshaler struct{}
16
17 // MarshalLogs plog.Logs to OTLP text.
18 func (textLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) {
19 buf := dataBuffer{}
20 rls := ld.ResourceLogs()
21 for i := 0; i < rls.Len(); i++ {
22 buf.logEntry("ResourceLog #%d", i)
23 rl := rls.At(i)
24 buf.logEntry("Resource SchemaURL: %s", rl.SchemaUrl())
25 buf.logAttributes("Resource attributes", rl.Resource().Attributes())
26 buf.logEntityRefs(rl.Resource())
27 ills := rl.ScopeLogs()
28 for j := 0; j < ills.Len(); j++ {
29 buf.logEntry("ScopeLogs #%d", j)
30 ils := ills.At(j)
31 buf.logEntry("ScopeLogs SchemaURL: %s", ils.SchemaUrl())
32 buf.logInstrumentationScope(ils.Scope())
33
34 logs := ils.LogRecords()
35 for k := 0; k < logs.Len(); k++ {
36 buf.logEntry("LogRecord #%d", k)
37 lr := logs.At(k)
38 buf.logEntry("ObservedTimestamp: %s", lr.ObservedTimestamp())
39 buf.logEntry("Timestamp: %s", lr.Timestamp())
40 buf.logEntry("SeverityText: %s", lr.SeverityText())
41 buf.logEntry("SeverityNumber: %s(%d)", lr.SeverityNumber(), lr.SeverityNumber())
42 if lr.EventName() != "" {
43 buf.logEntry("EventName: %s", lr.EventName())
44 }
45 buf.logEntry("Body: %s", valueToString(lr.Body()))
46 buf.logAttributes("Attributes", lr.Attributes())
47 buf.logEntry("Trace ID: %s", lr.TraceID())
48 buf.logEntry("Span ID: %s", lr.SpanID())
49 buf.logEntry("Flags: %d", lr.Flags())
50 }
51 }
52 }
53
54 return buf.buf.Bytes(), nil
55 }