2024-04-11 00:18:42 -07:00
|
|
|
// Copyright The OpenTelemetry Authors
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
package stdoutlog // import "go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel/log"
|
|
|
|
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
|
|
|
|
sdklog "go.opentelemetry.io/otel/sdk/log"
|
|
|
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
|
|
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// recordJSON is a JSON-serializable representation of a Record.
|
|
|
|
|
type recordJSON struct {
|
|
|
|
|
Timestamp time.Time
|
|
|
|
|
ObservedTimestamp time.Time
|
|
|
|
|
Severity log.Severity
|
|
|
|
|
SeverityText string
|
|
|
|
|
Body log.Value
|
|
|
|
|
Attributes []log.KeyValue
|
|
|
|
|
TraceID trace.TraceID
|
|
|
|
|
SpanID trace.SpanID
|
|
|
|
|
TraceFlags trace.TraceFlags
|
2024-04-22 04:33:26 -07:00
|
|
|
Resource *resource.Resource
|
2024-04-11 00:18:42 -07:00
|
|
|
Scope instrumentation.Scope
|
|
|
|
|
AttributeValueLengthLimit int
|
|
|
|
|
AttributeCountLimit int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (e *Exporter) newRecordJSON(r sdklog.Record) recordJSON {
|
2024-04-22 04:33:26 -07:00
|
|
|
res := r.Resource()
|
2024-04-11 00:18:42 -07:00
|
|
|
newRecord := recordJSON{
|
|
|
|
|
Severity: r.Severity(),
|
|
|
|
|
SeverityText: r.SeverityText(),
|
|
|
|
|
Body: r.Body(),
|
|
|
|
|
|
|
|
|
|
TraceID: r.TraceID(),
|
|
|
|
|
SpanID: r.SpanID(),
|
|
|
|
|
TraceFlags: r.TraceFlags(),
|
|
|
|
|
|
|
|
|
|
Attributes: make([]log.KeyValue, 0, r.AttributesLen()),
|
|
|
|
|
|
2024-04-22 04:33:26 -07:00
|
|
|
Resource: &res,
|
2024-04-16 11:48:17 -07:00
|
|
|
Scope: r.InstrumentationScope(),
|
2024-04-11 00:18:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r.WalkAttributes(func(kv log.KeyValue) bool {
|
|
|
|
|
newRecord.Attributes = append(newRecord.Attributes, kv)
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if e.timestamps {
|
|
|
|
|
newRecord.Timestamp = r.Timestamp()
|
|
|
|
|
newRecord.ObservedTimestamp = r.ObservedTimestamp()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newRecord
|
|
|
|
|
}
|