Documentation
¶
Index ¶
- Constants
- Variables
- type JSONMarshaler
- type JSONUnmarshaler
- type LogRecord
- func (ms LogRecord) Attributes() pcommon.Map
- func (ms LogRecord) Body() pcommon.Value
- func (ms LogRecord) CopyTo(dest LogRecord)
- func (ms LogRecord) DroppedAttributesCount() uint32
- func (ms LogRecord) EventName() string
- func (ms LogRecord) Flags() LogRecordFlags
- func (ms LogRecord) MoveTo(dest LogRecord)
- func (ms LogRecord) ObservedTimestamp() pcommon.Timestamp
- func (ms LogRecord) SetDroppedAttributesCount(v uint32)
- func (ms LogRecord) SetEventName(v string)
- func (ms LogRecord) SetFlags(v LogRecordFlags)
- func (ms LogRecord) SetObservedTimestamp(v pcommon.Timestamp)
- func (ms LogRecord) SetSeverityNumber(v SeverityNumber)
- func (ms LogRecord) SetSeverityText(v string)
- func (ms LogRecord) SetSpanID(v pcommon.SpanID)
- func (ms LogRecord) SetTimestamp(v pcommon.Timestamp)
- func (ms LogRecord) SetTraceID(v pcommon.TraceID)
- func (ms LogRecord) SeverityNumber() SeverityNumber
- func (ms LogRecord) SeverityText() string
- func (ms LogRecord) SpanID() pcommon.SpanID
- func (ms LogRecord) Timestamp() pcommon.Timestamp
- func (ms LogRecord) TraceID() pcommon.TraceID
- type LogRecordFlags
- type LogRecordSlice
- func (es LogRecordSlice) All() iter.Seq2[int, LogRecord]
- func (es LogRecordSlice) AppendEmpty() LogRecord
- func (es LogRecordSlice) At(i int) LogRecord
- func (es LogRecordSlice) CopyTo(dest LogRecordSlice)
- func (es LogRecordSlice) EnsureCapacity(newCap int)
- func (es LogRecordSlice) Len() int
- func (es LogRecordSlice) MoveAndAppendTo(dest LogRecordSlice)
- func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool)
- func (es LogRecordSlice) Sort(less func(a, b LogRecord) bool)
- type Logs
- type MarshalSizer
- type Marshaler
- type ProtoMarshaler
- type ProtoUnmarshaler
- type ResourceLogs
- type ResourceLogsSlice
- func (es ResourceLogsSlice) All() iter.Seq2[int, ResourceLogs]
- func (es ResourceLogsSlice) AppendEmpty() ResourceLogs
- func (es ResourceLogsSlice) At(i int) ResourceLogs
- func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice)
- func (es ResourceLogsSlice) EnsureCapacity(newCap int)
- func (es ResourceLogsSlice) Len() int
- func (es ResourceLogsSlice) MoveAndAppendTo(dest ResourceLogsSlice)
- func (es ResourceLogsSlice) RemoveIf(f func(ResourceLogs) bool)
- func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool)
- type ScopeLogs
- type ScopeLogsSlice
- func (es ScopeLogsSlice) All() iter.Seq2[int, ScopeLogs]
- func (es ScopeLogsSlice) AppendEmpty() ScopeLogs
- func (es ScopeLogsSlice) At(i int) ScopeLogs
- func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice)
- func (es ScopeLogsSlice) EnsureCapacity(newCap int)
- func (es ScopeLogsSlice) Len() int
- func (es ScopeLogsSlice) MoveAndAppendTo(dest ScopeLogsSlice)
- func (es ScopeLogsSlice) RemoveIf(f func(ScopeLogs) bool)
- func (es ScopeLogsSlice) Sort(less func(a, b ScopeLogs) bool)
- type SeverityNumber
- type Sizer
- type Unmarshaler
Examples ¶
Constants ¶
const ( SeverityNumberUnspecified = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_UNSPECIFIED) SeverityNumberTrace = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_TRACE) SeverityNumberTrace2 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_TRACE2) SeverityNumberTrace3 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_TRACE3) SeverityNumberTrace4 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_TRACE4) SeverityNumberDebug = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_DEBUG) SeverityNumberDebug2 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_DEBUG2) SeverityNumberDebug3 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_DEBUG3) SeverityNumberDebug4 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_DEBUG4) SeverityNumberInfo = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_INFO) SeverityNumberInfo2 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_INFO2) SeverityNumberInfo3 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_INFO3) SeverityNumberInfo4 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_INFO4) SeverityNumberWarn = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_WARN) SeverityNumberWarn2 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_WARN2) SeverityNumberWarn3 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_WARN3) SeverityNumberWarn4 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_WARN4) SeverityNumberError = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_ERROR) SeverityNumberError2 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_ERROR2) SeverityNumberError3 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_ERROR3) SeverityNumberError4 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_ERROR4) SeverityNumberFatal = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_FATAL) SeverityNumberFatal2 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_FATAL2) SeverityNumberFatal3 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_FATAL3) SeverityNumberFatal4 = SeverityNumber(internal.SeverityNumber_SEVERITY_NUMBER_FATAL4) )
Variables ¶
var DefaultLogRecordFlags = LogRecordFlags(0)
Functions ¶
This section is empty.
Types ¶
type JSONMarshaler ¶ added in v0.63.0
type JSONMarshaler struct{}
JSONMarshaler marshals Logs to JSON bytes using the OTLP/JSON format.
func (*JSONMarshaler) MarshalLogs ¶ added in v0.63.0
func (*JSONMarshaler) MarshalLogs(ld Logs) ([]byte, error)
MarshalLogs to the OTLP/JSON format.
type JSONUnmarshaler ¶ added in v0.63.0
type JSONUnmarshaler struct {
// DisallowUnknownFields causes UnmarshalLogs to return an error when the
// input contains JSON object fields that are not defined by the OTLP
// schema. When false (the default), unknown fields are silently ignored.
//
// Warning: enabling this option breaks forwards compatibility with future
// evolutions of the OTLP format, as fields added to the format in newer
// versions will be rejected as unknown.
DisallowUnknownFields bool
// contains filtered or unexported fields
}
JSONUnmarshaler unmarshals OTLP/JSON formatted-bytes to Logs.
func (*JSONUnmarshaler) UnmarshalLogs ¶ added in v0.63.0
func (u *JSONUnmarshaler) UnmarshalLogs(buf []byte) (Logs, error)
UnmarshalLogs from OTLP/JSON format into Logs.
type LogRecord ¶
type LogRecord struct {
// contains filtered or unexported fields
}
This is a reference type, if passed by value and callee modifies it the caller will see the modification.
Must use NewLogRecord function to create new instances. Important: zero-initialized instance is not valid for use.
func NewLogRecord ¶
func NewLogRecord() LogRecord
NewLogRecord creates a new empty LogRecord.
This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, OR directly access the member if this is embedded in another struct.
func (LogRecord) Attributes ¶ added in v0.59.0
Attributes returns the Attributes associated with this LogRecord.
func (LogRecord) Body ¶ added in v0.59.0
Body returns the body associated with this LogRecord.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecord1 := scopeLogs.LogRecords().AppendEmpty()
logRecord1.Body().SetStr("Simple string message")
logRecord1.SetSeverityNumber(plog.SeverityNumberInfo)
logRecord2 := scopeLogs.LogRecords().AppendEmpty()
body := logRecord2.Body().SetEmptyMap()
body.PutStr("event", "user_action")
body.PutStr("user_id", "user123")
body.PutInt("timestamp", 1640995200)
body.PutBool("success", true)
logRecord2.SetSeverityNumber(plog.SeverityNumberInfo)
logRecord3 := scopeLogs.LogRecords().AppendEmpty()
bodySlice := logRecord3.Body().SetEmptySlice()
bodySlice.AppendEmpty().SetStr("Step 1: Initialize connection")
bodySlice.AppendEmpty().SetStr("Step 2: Authenticate user")
bodySlice.AppendEmpty().SetStr("Step 3: Load configuration")
logRecord3.SetSeverityNumber(plog.SeverityNumberDebug)
fmt.Printf("Log 1 body type: %s\n", logRecord1.Body().Type())
fmt.Printf("Log 2 body type: %s\n", logRecord2.Body().Type())
fmt.Printf("Log 3 body type: %s\n", logRecord3.Body().Type())
fmt.Printf("Log 3 steps count: %d\n", logRecord3.Body().Slice().Len())
}
Output: Log 1 body type: Str Log 2 body type: Map Log 3 body type: Slice Log 3 steps count: 3
func (LogRecord) CopyTo ¶ added in v0.59.0
CopyTo copies all properties from the current struct overriding the destination.
func (LogRecord) DroppedAttributesCount ¶ added in v0.59.0
DroppedAttributesCount returns the droppedattributescount associated with this LogRecord.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.Body().SetStr("Log with some attributes dropped")
logRecord.SetSeverityNumber(plog.SeverityNumberWarn)
// Add some attributes
logRecord.Attributes().PutStr("included.attr1", "value1")
logRecord.Attributes().PutStr("included.attr2", "value2")
logRecord.Attributes().PutInt("included.count", 42)
// Set dropped attributes count
logRecord.SetDroppedAttributesCount(7)
fmt.Printf("Current attributes: %d\n", logRecord.Attributes().Len())
fmt.Printf("Dropped attributes: %d\n", logRecord.DroppedAttributesCount())
fmt.Printf("Total original attributes: %d\n", logRecord.Attributes().Len()+int(logRecord.DroppedAttributesCount()))
}
Output: Current attributes: 3 Dropped attributes: 7 Total original attributes: 10
func (LogRecord) EventName ¶ added in v1.23.0
EventName returns the eventname associated with this LogRecord.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.SetEventName("user.login")
logRecord.Body().SetStr("User authentication event")
logRecord.SetSeverityNumber(plog.SeverityNumberInfo)
logRecord.Attributes().PutStr("user.id", "user123")
logRecord.Attributes().PutStr("session.id", "session456")
logRecord.Attributes().PutBool("success", true)
fmt.Printf("Event name: %s\n", logRecord.EventName())
fmt.Printf("Log body: %s\n", logRecord.Body().Str())
}
Output: Event name: user.login Log body: User authentication event
func (LogRecord) Flags ¶ added in v0.59.0
func (ms LogRecord) Flags() LogRecordFlags
Flags returns the flags associated with this LogRecord.
func (LogRecord) MoveTo ¶ added in v0.59.0
MoveTo moves all properties from the current struct overriding the destination and resetting the current instance to its zero value
func (LogRecord) ObservedTimestamp ¶ added in v0.59.0
ObservedTimestamp returns the observedtimestamp associated with this LogRecord.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.Body().SetStr("Log entry with observation time")
logRecord.SetSeverityNumber(plog.SeverityNumberInfo)
// Set both original timestamp and observed timestamp
originalTime := pcommon.Timestamp(1640995200000000000) // 2022-01-01 00:00:00 UTC
observedTime := pcommon.Timestamp(1640995200500000000) // 2022-01-01 00:00:00.5 UTC
logRecord.SetTimestamp(originalTime)
logRecord.SetObservedTimestamp(observedTime)
fmt.Printf("Original timestamp: %d\n", logRecord.Timestamp())
fmt.Printf("Observed timestamp: %d\n", logRecord.ObservedTimestamp())
fmt.Printf("Delay (ns): %d\n", logRecord.ObservedTimestamp()-logRecord.Timestamp())
}
Output: Original timestamp: 1640995200000000000 Observed timestamp: 1640995200500000000 Delay (ns): 500000000
func (LogRecord) SetDroppedAttributesCount ¶ added in v0.59.0
SetDroppedAttributesCount replaces the droppedattributescount associated with this LogRecord.
func (LogRecord) SetEventName ¶ added in v1.23.0
SetEventName replaces the eventname associated with this LogRecord.
func (LogRecord) SetFlags ¶ added in v0.59.0
func (ms LogRecord) SetFlags(v LogRecordFlags)
SetFlags replaces the flags associated with this LogRecord.
func (LogRecord) SetObservedTimestamp ¶ added in v0.59.0
SetObservedTimestamp replaces the observedtimestamp associated with this LogRecord.
func (LogRecord) SetSeverityNumber ¶ added in v0.59.0
func (ms LogRecord) SetSeverityNumber(v SeverityNumber)
SetSeverityNumber replaces the severitynumber associated with this LogRecord.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
severities := []struct {
level plog.SeverityNumber
text string
msg string
}{
{plog.SeverityNumberDebug, "DEBUG", "Debug information"},
{plog.SeverityNumberInfo, "INFO", "Application started"},
{plog.SeverityNumberWarn, "WARN", "Configuration file not found, using defaults"},
{plog.SeverityNumberError, "ERROR", "Failed to connect to database"},
{plog.SeverityNumberFatal, "FATAL", "Critical system failure"},
}
for _, s := range severities {
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.SetSeverityNumber(s.level)
logRecord.SetSeverityText(s.text)
logRecord.Body().SetStr(s.msg)
logRecord.SetTimestamp(pcommon.Timestamp(1640995200000000000))
}
fmt.Printf("Total log records: %d\n", scopeLogs.LogRecords().Len())
first := scopeLogs.LogRecords().At(0)
last := scopeLogs.LogRecords().At(scopeLogs.LogRecords().Len() - 1)
fmt.Printf("First log: %s - %s\n", first.SeverityText(), first.Body().Str())
fmt.Printf("Last log: %s - %s\n", last.SeverityText(), last.Body().Str())
}
Output: Total log records: 5 First log: DEBUG - Debug information Last log: FATAL - Critical system failure
func (LogRecord) SetSeverityText ¶ added in v0.59.0
SetSeverityText replaces the severitytext associated with this LogRecord.
func (LogRecord) SetSpanID ¶ added in v0.59.0
SetSpanID replaces the spanid associated with this LogRecord.
func (LogRecord) SetTimestamp ¶ added in v0.59.0
SetTimestamp replaces the timestamp associated with this LogRecord.
func (LogRecord) SetTraceID ¶ added in v0.59.0
SetTraceID replaces the traceid associated with this LogRecord.
func (LogRecord) SeverityNumber ¶ added in v0.59.0
func (ms LogRecord) SeverityNumber() SeverityNumber
SeverityNumber returns the severitynumber associated with this LogRecord.
func (LogRecord) SeverityText ¶ added in v0.59.0
SeverityText returns the severitytext associated with this LogRecord.
func (LogRecord) SpanID ¶ added in v0.59.0
SpanID returns the spanid associated with this LogRecord.
func (LogRecord) Timestamp ¶ added in v0.59.0
Timestamp returns the timestamp associated with this LogRecord.
func (LogRecord) TraceID ¶ added in v0.59.0
TraceID returns the traceid associated with this LogRecord.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.Body().SetStr("Processing request")
logRecord.SetSeverityNumber(plog.SeverityNumberInfo)
traceID := pcommon.TraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
spanID := pcommon.SpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})
logRecord.SetTraceID(traceID)
logRecord.SetSpanID(spanID)
logRecord.SetFlags(plog.DefaultLogRecordFlags.WithIsSampled(true))
fmt.Printf("Log message: %s\n", logRecord.Body().Str())
fmt.Printf("TraceID: %s\n", logRecord.TraceID())
fmt.Printf("SpanID: %s\n", logRecord.SpanID())
fmt.Printf("Is sampled: %t\n", logRecord.Flags().IsSampled())
}
Output: Log message: Processing request TraceID: 0102030405060708090a0b0c0d0e0f10 SpanID: 0102030405060708 Is sampled: true
type LogRecordFlags ¶ added in v0.59.0
type LogRecordFlags uint32
LogRecordFlags defines flags for the LogRecord. The 8 least significant bits are the trace flags as defined in W3C Trace Context specification. 24 most significant bits are reserved and must be set to 0.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.Body().SetStr("Log with flags")
logRecord.SetSeverityNumber(plog.SeverityNumberInfo)
// Test default flags
defaultFlags := plog.DefaultLogRecordFlags
logRecord.SetFlags(defaultFlags)
fmt.Printf("Default flags IsSampled: %t\n", logRecord.Flags().IsSampled())
// Test with sampled flag
flagsWithSampled := defaultFlags.WithIsSampled(true)
logRecord.SetFlags(flagsWithSampled)
fmt.Printf("With sampled flag: %t\n", logRecord.Flags().IsSampled())
// Test removing sampled flag
flagsWithoutSampled := flagsWithSampled.WithIsSampled(false)
logRecord.SetFlags(flagsWithoutSampled)
fmt.Printf("Without sampled flag: %t\n", logRecord.Flags().IsSampled())
}
Output: Default flags IsSampled: false With sampled flag: true Without sampled flag: false
func (LogRecordFlags) IsSampled ¶ added in v0.59.0
func (ms LogRecordFlags) IsSampled() bool
IsSampled returns true if the LogRecordFlags contains the IsSampled flag.
func (LogRecordFlags) WithIsSampled ¶ added in v0.59.0
func (ms LogRecordFlags) WithIsSampled(b bool) LogRecordFlags
WithIsSampled returns a new LogRecordFlags, with the IsSampled flag set to the given value.
type LogRecordSlice ¶
type LogRecordSlice struct {
// contains filtered or unexported fields
}
LogRecordSlice logically represents a slice of LogRecord.
This is a reference type. If passed by value and callee modifies it, the caller will see the modification.
Must use NewLogRecordSlice function to create new instances. Important: zero-initialized instance is not valid for use.
func NewLogRecordSlice ¶
func NewLogRecordSlice() LogRecordSlice
NewLogRecordSlice creates a LogRecordSliceWrapper with 0 elements. Can use "EnsureCapacity" to initialize with a given capacity.
func (LogRecordSlice) All ¶ added in v1.28.0
func (es LogRecordSlice) All() iter.Seq2[int, LogRecord]
All returns an iterator over index-value pairs in the slice.
for i, v := range es.All() {
... // Do something with index-value pair
}
func (LogRecordSlice) AppendEmpty ¶ added in v0.59.0
func (es LogRecordSlice) AppendEmpty() LogRecord
AppendEmpty will append to the end of the slice an empty LogRecord. It returns the newly added LogRecord.
func (LogRecordSlice) At ¶ added in v0.59.0
func (es LogRecordSlice) At(i int) LogRecord
At returns the element at the given index.
This function is used mostly for iterating over all the values in the slice:
for i := 0; i < es.Len(); i++ {
e := es.At(i)
... // Do something with the element
}
func (LogRecordSlice) CopyTo ¶ added in v0.59.0
func (es LogRecordSlice) CopyTo(dest LogRecordSlice)
CopyTo copies all elements from the current slice overriding the destination.
func (LogRecordSlice) EnsureCapacity ¶ added in v0.59.0
func (es LogRecordSlice) EnsureCapacity(newCap int)
EnsureCapacity is an operation that ensures the slice has at least the specified capacity. 1. If the newCap <= cap then no change in capacity. 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
Here is how a new LogRecordSlice can be initialized:
es := NewLogRecordSlice()
es.EnsureCapacity(4)
for i := 0; i < 4; i++ {
e := es.AppendEmpty()
// Here should set all the values for e.
}
func (LogRecordSlice) Len ¶ added in v0.59.0
func (es LogRecordSlice) Len() int
Len returns the number of elements in the slice.
Returns "0" for a newly instance created with "NewLogRecordSlice()".
func (LogRecordSlice) MoveAndAppendTo ¶ added in v0.59.0
func (es LogRecordSlice) MoveAndAppendTo(dest LogRecordSlice)
MoveAndAppendTo moves all elements from the current slice and appends them to the dest. The current slice will be cleared.
func (LogRecordSlice) RemoveIf ¶ added in v0.59.0
func (es LogRecordSlice) RemoveIf(f func(LogRecord) bool)
RemoveIf calls f sequentially for each element present in the slice. If f returns true, the element is removed from the slice.
func (LogRecordSlice) Sort ¶ added in v0.59.0
func (es LogRecordSlice) Sort(less func(a, b LogRecord) bool)
Sort sorts the LogRecord elements within LogRecordSlice given the provided less function so that two instances of LogRecordSlice can be compared.
type Logs ¶
type Logs internal.LogsWrapper
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.
This is a reference type, if passed by value and callee modifies it the caller will see the modification.
Must use NewLogs function to create new instances. Important: zero-initialized instance is not valid for use.
func NewLogs ¶
func NewLogs() Logs
NewLogs creates a new empty Logs.
This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, OR directly access the member if this is embedded in another struct.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
resourceLogs.Resource().Attributes().PutStr("service.name", "my-service")
resourceLogs.Resource().Attributes().PutStr("service.version", "1.0.0")
resourceLogs.Resource().Attributes().PutStr("host.name", "server-01")
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
scopeLogs.Scope().SetName("my-logger")
scopeLogs.Scope().SetVersion("1.0.0")
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.SetTimestamp(pcommon.Timestamp(1640995200000000000))
logRecord.SetSeverityNumber(plog.SeverityNumberInfo)
logRecord.SetSeverityText("INFO")
logRecord.Body().SetStr("User login successful")
logRecord.Attributes().PutStr("user.id", "user123")
logRecord.Attributes().PutStr("session.id", "session456")
logRecord.Attributes().PutStr("action", "login")
fmt.Printf("Resource logs count: %d\n", logs.ResourceLogs().Len())
fmt.Printf("Log records count: %d\n", scopeLogs.LogRecords().Len())
fmt.Printf("Log message: %s\n", logRecord.Body().Str())
fmt.Printf("Severity: %s\n", logRecord.SeverityText())
}
Output: Resource logs count: 1 Log records count: 1 Log message: User login successful Severity: INFO
func (Logs) CopyTo ¶ added in v0.61.0
CopyTo copies all properties from the current struct overriding the destination.
func (Logs) IsReadOnly ¶ added in v1.0.0
IsReadOnly returns true if this Logs instance is read-only.
func (Logs) LogRecordCount ¶ added in v0.59.0
LogRecordCount calculates the total number of log records.
func (Logs) MarkReadOnly ¶ added in v1.0.0
func (ms Logs) MarkReadOnly()
MarkReadOnly marks the Logs as shared so that no further modifications can be done on it.
func (Logs) MoveTo ¶ added in v0.59.0
MoveTo moves all properties from the current struct overriding the destination and resetting the current instance to its zero value
func (Logs) ResourceLogs ¶ added in v0.59.0
func (ms Logs) ResourceLogs() ResourceLogsSlice
ResourceLogs returns the ResourceLogs associated with this Logs.
type MarshalSizer ¶ added in v0.60.0
MarshalSizer is the interface that groups the basic Marshal and Size methods
type Marshaler ¶
type Marshaler interface {
// MarshalLogs the given Logs into bytes.
// If the error is not nil, the returned bytes slice cannot be used.
MarshalLogs(ld Logs) ([]byte, error)
}
Marshaler marshals Logs into bytes.
type ProtoMarshaler ¶ added in v0.63.0
type ProtoMarshaler struct{}
func (*ProtoMarshaler) LogRecordSize ¶ added in v1.27.0
func (e *ProtoMarshaler) LogRecordSize(ld LogRecord) int
func (*ProtoMarshaler) LogsSize ¶ added in v0.63.0
func (e *ProtoMarshaler) LogsSize(ld Logs) int
func (*ProtoMarshaler) MarshalLogs ¶ added in v0.63.0
func (e *ProtoMarshaler) MarshalLogs(ld Logs) ([]byte, error)
func (*ProtoMarshaler) ResourceLogsSize ¶ added in v1.27.0
func (e *ProtoMarshaler) ResourceLogsSize(ld ResourceLogs) int
func (*ProtoMarshaler) ScopeLogsSize ¶ added in v1.27.0
func (e *ProtoMarshaler) ScopeLogsSize(ld ScopeLogs) int
type ProtoUnmarshaler ¶ added in v0.63.0
type ProtoUnmarshaler struct{}
func (*ProtoUnmarshaler) UnmarshalLogs ¶ added in v0.63.0
func (d *ProtoUnmarshaler) UnmarshalLogs(buf []byte) (Logs, error)
type ResourceLogs ¶
type ResourceLogs struct {
// contains filtered or unexported fields
}
ResourceLogs is a collection of logs from a Resource.
This is a reference type, if passed by value and callee modifies it the caller will see the modification.
Must use NewResourceLogs function to create new instances. Important: zero-initialized instance is not valid for use.
func NewResourceLogs ¶
func NewResourceLogs() ResourceLogs
NewResourceLogs creates a new empty ResourceLogs.
This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, OR directly access the member if this is embedded in another struct.
func (ResourceLogs) CopyTo ¶ added in v0.59.0
func (ms ResourceLogs) CopyTo(dest ResourceLogs)
CopyTo copies all properties from the current struct overriding the destination.
func (ResourceLogs) MoveTo ¶ added in v0.59.0
func (ms ResourceLogs) MoveTo(dest ResourceLogs)
MoveTo moves all properties from the current struct overriding the destination and resetting the current instance to its zero value
func (ResourceLogs) Resource ¶ added in v0.59.0
func (ms ResourceLogs) Resource() pcommon.Resource
Resource returns the resource associated with this ResourceLogs.
func (ResourceLogs) SchemaUrl ¶ added in v0.59.0
func (ms ResourceLogs) SchemaUrl() string
SchemaUrl returns the schemaurl associated with this ResourceLogs.
func (ResourceLogs) ScopeLogs ¶ added in v0.59.0
func (ms ResourceLogs) ScopeLogs() ScopeLogsSlice
ScopeLogs returns the ScopeLogs associated with this ResourceLogs.
func (ResourceLogs) SetSchemaUrl ¶ added in v0.59.0
func (ms ResourceLogs) SetSchemaUrl(v string)
SetSchemaUrl replaces the schemaurl associated with this ResourceLogs.
type ResourceLogsSlice ¶
type ResourceLogsSlice struct {
// contains filtered or unexported fields
}
ResourceLogsSlice logically represents a slice of ResourceLogs.
This is a reference type. If passed by value and callee modifies it, the caller will see the modification.
Must use NewResourceLogsSlice function to create new instances. Important: zero-initialized instance is not valid for use.
func NewResourceLogsSlice ¶
func NewResourceLogsSlice() ResourceLogsSlice
NewResourceLogsSlice creates a ResourceLogsSliceWrapper with 0 elements. Can use "EnsureCapacity" to initialize with a given capacity.
func (ResourceLogsSlice) All ¶ added in v1.28.0
func (es ResourceLogsSlice) All() iter.Seq2[int, ResourceLogs]
All returns an iterator over index-value pairs in the slice.
for i, v := range es.All() {
... // Do something with index-value pair
}
func (ResourceLogsSlice) AppendEmpty ¶ added in v0.59.0
func (es ResourceLogsSlice) AppendEmpty() ResourceLogs
AppendEmpty will append to the end of the slice an empty ResourceLogs. It returns the newly added ResourceLogs.
func (ResourceLogsSlice) At ¶ added in v0.59.0
func (es ResourceLogsSlice) At(i int) ResourceLogs
At returns the element at the given index.
This function is used mostly for iterating over all the values in the slice:
for i := 0; i < es.Len(); i++ {
e := es.At(i)
... // Do something with the element
}
func (ResourceLogsSlice) CopyTo ¶ added in v0.59.0
func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice)
CopyTo copies all elements from the current slice overriding the destination.
func (ResourceLogsSlice) EnsureCapacity ¶ added in v0.59.0
func (es ResourceLogsSlice) EnsureCapacity(newCap int)
EnsureCapacity is an operation that ensures the slice has at least the specified capacity. 1. If the newCap <= cap then no change in capacity. 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
Here is how a new ResourceLogsSlice can be initialized:
es := NewResourceLogsSlice()
es.EnsureCapacity(4)
for i := 0; i < 4; i++ {
e := es.AppendEmpty()
// Here should set all the values for e.
}
func (ResourceLogsSlice) Len ¶ added in v0.59.0
func (es ResourceLogsSlice) Len() int
Len returns the number of elements in the slice.
Returns "0" for a newly instance created with "NewResourceLogsSlice()".
func (ResourceLogsSlice) MoveAndAppendTo ¶ added in v0.59.0
func (es ResourceLogsSlice) MoveAndAppendTo(dest ResourceLogsSlice)
MoveAndAppendTo moves all elements from the current slice and appends them to the dest. The current slice will be cleared.
func (ResourceLogsSlice) RemoveIf ¶ added in v0.59.0
func (es ResourceLogsSlice) RemoveIf(f func(ResourceLogs) bool)
RemoveIf calls f sequentially for each element present in the slice. If f returns true, the element is removed from the slice.
func (ResourceLogsSlice) Sort ¶ added in v0.59.0
func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool)
Sort sorts the ResourceLogs elements within ResourceLogsSlice given the provided less function so that two instances of ResourceLogsSlice can be compared.
type ScopeLogs ¶
type ScopeLogs struct {
// contains filtered or unexported fields
}
ScopeLogs is a collection of logs from a LibraryInstrumentation.
This is a reference type, if passed by value and callee modifies it the caller will see the modification.
Must use NewScopeLogs function to create new instances. Important: zero-initialized instance is not valid for use.
func NewScopeLogs ¶
func NewScopeLogs() ScopeLogs
NewScopeLogs creates a new empty ScopeLogs.
This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice, OR directly access the member if this is embedded in another struct.
func (ScopeLogs) CopyTo ¶ added in v0.59.0
CopyTo copies all properties from the current struct overriding the destination.
func (ScopeLogs) LogRecords ¶ added in v0.59.0
func (ms ScopeLogs) LogRecords() LogRecordSlice
LogRecords returns the LogRecords associated with this ScopeLogs.
func (ScopeLogs) MoveTo ¶ added in v0.59.0
MoveTo moves all properties from the current struct overriding the destination and resetting the current instance to its zero value
func (ScopeLogs) SchemaUrl ¶ added in v0.59.0
SchemaUrl returns the schemaurl associated with this ScopeLogs.
func (ScopeLogs) Scope ¶ added in v0.59.0
func (ms ScopeLogs) Scope() pcommon.InstrumentationScope
Scope returns the scope associated with this ScopeLogs.
func (ScopeLogs) SetSchemaUrl ¶ added in v0.59.0
SetSchemaUrl replaces the schemaurl associated with this ScopeLogs.
type ScopeLogsSlice ¶
type ScopeLogsSlice struct {
// contains filtered or unexported fields
}
ScopeLogsSlice logically represents a slice of ScopeLogs.
This is a reference type. If passed by value and callee modifies it, the caller will see the modification.
Must use NewScopeLogsSlice function to create new instances. Important: zero-initialized instance is not valid for use.
func NewScopeLogsSlice ¶
func NewScopeLogsSlice() ScopeLogsSlice
NewScopeLogsSlice creates a ScopeLogsSliceWrapper with 0 elements. Can use "EnsureCapacity" to initialize with a given capacity.
func (ScopeLogsSlice) All ¶ added in v1.28.0
func (es ScopeLogsSlice) All() iter.Seq2[int, ScopeLogs]
All returns an iterator over index-value pairs in the slice.
for i, v := range es.All() {
... // Do something with index-value pair
}
func (ScopeLogsSlice) AppendEmpty ¶ added in v0.59.0
func (es ScopeLogsSlice) AppendEmpty() ScopeLogs
AppendEmpty will append to the end of the slice an empty ScopeLogs. It returns the newly added ScopeLogs.
func (ScopeLogsSlice) At ¶ added in v0.59.0
func (es ScopeLogsSlice) At(i int) ScopeLogs
At returns the element at the given index.
This function is used mostly for iterating over all the values in the slice:
for i := 0; i < es.Len(); i++ {
e := es.At(i)
... // Do something with the element
}
func (ScopeLogsSlice) CopyTo ¶ added in v0.59.0
func (es ScopeLogsSlice) CopyTo(dest ScopeLogsSlice)
CopyTo copies all elements from the current slice overriding the destination.
func (ScopeLogsSlice) EnsureCapacity ¶ added in v0.59.0
func (es ScopeLogsSlice) EnsureCapacity(newCap int)
EnsureCapacity is an operation that ensures the slice has at least the specified capacity. 1. If the newCap <= cap then no change in capacity. 2. If the newCap > cap then the slice capacity will be expanded to equal newCap.
Here is how a new ScopeLogsSlice can be initialized:
es := NewScopeLogsSlice()
es.EnsureCapacity(4)
for i := 0; i < 4; i++ {
e := es.AppendEmpty()
// Here should set all the values for e.
}
func (ScopeLogsSlice) Len ¶ added in v0.59.0
func (es ScopeLogsSlice) Len() int
Len returns the number of elements in the slice.
Returns "0" for a newly instance created with "NewScopeLogsSlice()".
func (ScopeLogsSlice) MoveAndAppendTo ¶ added in v0.59.0
func (es ScopeLogsSlice) MoveAndAppendTo(dest ScopeLogsSlice)
MoveAndAppendTo moves all elements from the current slice and appends them to the dest. The current slice will be cleared.
func (ScopeLogsSlice) RemoveIf ¶ added in v0.59.0
func (es ScopeLogsSlice) RemoveIf(f func(ScopeLogs) bool)
RemoveIf calls f sequentially for each element present in the slice. If f returns true, the element is removed from the slice.
func (ScopeLogsSlice) Sort ¶ added in v0.59.0
func (es ScopeLogsSlice) Sort(less func(a, b ScopeLogs) bool)
Sort sorts the ScopeLogs elements within ScopeLogsSlice given the provided less function so that two instances of ScopeLogsSlice can be compared.
type SeverityNumber ¶
type SeverityNumber int32
SeverityNumber represents severity number of a log record.
Example ¶
package main
import (
"fmt"
"go.opentelemetry.io/collector/pdata/plog"
)
func main() {
logs := plog.NewLogs()
resourceLogs := logs.ResourceLogs().AppendEmpty()
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
// Test all severity levels
severityLevels := []struct {
level plog.SeverityNumber
name string
}{
{plog.SeverityNumberUnspecified, "Unspecified"},
{plog.SeverityNumberTrace, "Trace"},
{plog.SeverityNumberTrace2, "Trace2"},
{plog.SeverityNumberTrace3, "Trace3"},
{plog.SeverityNumberTrace4, "Trace4"},
{plog.SeverityNumberDebug, "Debug"},
{plog.SeverityNumberDebug2, "Debug2"},
{plog.SeverityNumberDebug3, "Debug3"},
{plog.SeverityNumberDebug4, "Debug4"},
{plog.SeverityNumberInfo, "Info"},
{plog.SeverityNumberInfo2, "Info2"},
{plog.SeverityNumberInfo3, "Info3"},
{plog.SeverityNumberInfo4, "Info4"},
{plog.SeverityNumberWarn, "Warn"},
{plog.SeverityNumberWarn2, "Warn2"},
{plog.SeverityNumberWarn3, "Warn3"},
{plog.SeverityNumberWarn4, "Warn4"},
{plog.SeverityNumberError, "Error"},
{plog.SeverityNumberError2, "Error2"},
{plog.SeverityNumberError3, "Error3"},
{plog.SeverityNumberError4, "Error4"},
{plog.SeverityNumberFatal, "Fatal"},
{plog.SeverityNumberFatal2, "Fatal2"},
{plog.SeverityNumberFatal3, "Fatal3"},
{plog.SeverityNumberFatal4, "Fatal4"},
}
for i, s := range severityLevels {
if i < 5 { // Only create first 5 to keep output manageable
logRecord := scopeLogs.LogRecords().AppendEmpty()
logRecord.SetSeverityNumber(s.level)
logRecord.SetSeverityText(s.name)
logRecord.Body().SetStr("Log at " + s.name + " level")
}
}
fmt.Printf("Total severity levels tested: %d\n", len(severityLevels))
fmt.Printf("Created log records: %d\n", scopeLogs.LogRecords().Len())
fmt.Printf("First severity: %s\n", scopeLogs.LogRecords().At(0).SeverityText())
fmt.Printf("Last severity: %s\n", scopeLogs.LogRecords().At(4).SeverityText())
}
Output: Total severity levels tested: 25 Created log records: 5 First severity: Unspecified Last severity: Trace4
func (SeverityNumber) String ¶ added in v0.59.0
func (sn SeverityNumber) String() string
String returns the string representation of the SeverityNumber.
type Sizer ¶
type Sizer interface {
// LogsSize returns the size in bytes of a marshaled Logs.
LogsSize(ld Logs) int
}
Sizer is an optional interface implemented by the Marshaler, that calculates the size of a marshaled Logs.
type Unmarshaler ¶
type Unmarshaler interface {
// UnmarshalLogs the given bytes into Logs.
// If the error is not nil, the returned Logs cannot be used.
UnmarshalLogs(buf []byte) (Logs, error)
}
Unmarshaler unmarshalls bytes into Logs.