/
logs.go
66 lines (54 loc) · 1.99 KB
/
logs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package plog // import "go.opentelemetry.io/collector/pdata/plog"
import (
"go.opentelemetry.io/collector/pdata/internal"
otlpcollectorlog "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1"
)
// Logs is the top-level struct that is propagated through the logs pipeline.
// Use NewLogs to create new instance, zero-initialized instance is not valid for use.
type Logs internal.Logs
func newLogs(orig *otlpcollectorlog.ExportLogsServiceRequest) Logs {
state := internal.StateMutable
return Logs(internal.NewLogs(orig, &state))
}
func (ms Logs) getOrig() *otlpcollectorlog.ExportLogsServiceRequest {
return internal.GetOrigLogs(internal.Logs(ms))
}
func (ms Logs) getState() *internal.State {
return internal.GetLogsState(internal.Logs(ms))
}
// NewLogs creates a new Logs struct.
func NewLogs() Logs {
return newLogs(&otlpcollectorlog.ExportLogsServiceRequest{})
}
// IsReadOnly returns true if this Logs instance is read-only.
func (ms Logs) IsReadOnly() bool {
return *ms.getState() == internal.StateReadOnly
}
// CopyTo copies the Logs instance overriding the destination.
func (ms Logs) CopyTo(dest Logs) {
ms.ResourceLogs().CopyTo(dest.ResourceLogs())
}
// LogRecordCount calculates the total number of log records.
func (ms Logs) LogRecordCount() int {
logCount := 0
rss := ms.ResourceLogs()
for i := 0; i < rss.Len(); i++ {
rs := rss.At(i)
ill := rs.ScopeLogs()
for i := 0; i < ill.Len(); i++ {
logs := ill.At(i)
logCount += logs.LogRecords().Len()
}
}
return logCount
}
// ResourceLogs returns the ResourceLogsSlice associated with this Logs.
func (ms Logs) ResourceLogs() ResourceLogsSlice {
return newResourceLogsSlice(&ms.getOrig().ResourceLogs, internal.GetLogsState(internal.Logs(ms)))
}
// MarkReadOnly marks the Logs as shared so that no further modifications can be done on it.
func (ms Logs) MarkReadOnly() {
internal.SetLogsState(internal.Logs(ms), internal.StateReadOnly)
}