mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-24 03:47:19 +02:00
sdk/log: Add EventName (#6193)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/6183 Fixes https://github.com/open-telemetry/opentelemetry-go/issues/6184 Towards https://github.com/open-telemetry/opentelemetry-go/issues/6181 Prior-art: https://github.com/open-telemetry/opentelemetry-go/pull/6018
This commit is contained in:
parent
185547c846
commit
62e4225a42
@ -14,6 +14,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- Add `EventName` and `SetEventName` to `Record` in `go.opentelemetry.io/otel/log`. (#6187)
|
||||
- Add `EventName` to `RecordFactory` in `go.opentelemetry.io/otel/log/logtest`. (#6187)
|
||||
- `AssertRecordEqual` in `go.opentelemetry.io/otel/log/logtest` checks `Record.EventName`. (#6187)
|
||||
- Add `EventName` and `SetEventName` to `Record` in `go.opentelemetry.io/otel/sdk/log`. (#6193)
|
||||
- Add `EventName` to `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest`. (#6193)
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
@ -46,7 +46,7 @@ type Record struct {
|
||||
back []KeyValue
|
||||
}
|
||||
|
||||
// Event returns the event name.
|
||||
// EventName returns the event name.
|
||||
// A log record with non-empty event name is interpreted as an event record.
|
||||
func (r *Record) EventName() string {
|
||||
return r.eventName
|
||||
|
@ -73,6 +73,7 @@ func (l *logger) newRecord(ctx context.Context, r log.Record) Record {
|
||||
sc := trace.SpanContextFromContext(ctx)
|
||||
|
||||
newRecord := Record{
|
||||
eventName: r.EventName(),
|
||||
timestamp: r.Timestamp(),
|
||||
observedTimestamp: r.ObservedTimestamp(),
|
||||
severity: r.Severity(),
|
||||
|
@ -33,6 +33,7 @@ func TestLoggerEmit(t *testing.T) {
|
||||
p2WithError.Err = errors.New("error")
|
||||
|
||||
r := log.Record{}
|
||||
r.SetEventName("testing.name")
|
||||
r.SetTimestamp(time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC))
|
||||
r.SetBody(log.StringValue("testing body value"))
|
||||
r.SetSeverity(log.SeverityInfo)
|
||||
@ -78,6 +79,7 @@ func TestLoggerEmit(t *testing.T) {
|
||||
record: r,
|
||||
expectedRecords: []Record{
|
||||
{
|
||||
eventName: r.EventName(),
|
||||
timestamp: r.Timestamp(),
|
||||
body: r.Body(),
|
||||
severity: r.Severity(),
|
||||
@ -118,6 +120,7 @@ func TestLoggerEmit(t *testing.T) {
|
||||
record: r,
|
||||
expectedRecords: []Record{
|
||||
{
|
||||
eventName: r.EventName(),
|
||||
timestamp: r.Timestamp(),
|
||||
body: r.Body(),
|
||||
severity: r.Severity(),
|
||||
@ -151,6 +154,7 @@ func TestLoggerEmit(t *testing.T) {
|
||||
record: r,
|
||||
expectedRecords: []Record{
|
||||
{
|
||||
eventName: r.EventName(),
|
||||
timestamp: r.Timestamp(),
|
||||
body: r.Body(),
|
||||
severity: r.Severity(),
|
||||
@ -181,6 +185,7 @@ func TestLoggerEmit(t *testing.T) {
|
||||
record: rWithNoObservedTimestamp,
|
||||
expectedRecords: []Record{
|
||||
{
|
||||
eventName: rWithNoObservedTimestamp.EventName(),
|
||||
timestamp: rWithNoObservedTimestamp.Timestamp(),
|
||||
body: rWithNoObservedTimestamp.Body(),
|
||||
severity: rWithNoObservedTimestamp.Severity(),
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
//
|
||||
// Do not use RecordFactory to create records in production code.
|
||||
type RecordFactory struct {
|
||||
EventName string
|
||||
Timestamp time.Time
|
||||
ObservedTimestamp time.Time
|
||||
Severity log.Severity
|
||||
@ -49,6 +50,7 @@ func (f RecordFactory) NewRecord() sdklog.Record {
|
||||
set(r, "attributeCountLimit", -1)
|
||||
set(r, "attributeValueLengthLimit", -1)
|
||||
|
||||
r.SetEventName(f.EventName)
|
||||
r.SetTimestamp(f.Timestamp)
|
||||
r.SetObservedTimestamp(f.ObservedTimestamp)
|
||||
r.SetSeverity(f.Severity)
|
||||
|
@ -25,6 +25,7 @@ func TestRecordFactoryEmpty(t *testing.T) {
|
||||
func TestRecordFactory(t *testing.T) {
|
||||
now := time.Now()
|
||||
observed := now.Add(time.Second)
|
||||
eventName := "testing.name"
|
||||
severity := log.SeverityDebug
|
||||
severityText := "DBG"
|
||||
body := log.StringValue("Message")
|
||||
@ -43,6 +44,7 @@ func TestRecordFactory(t *testing.T) {
|
||||
r := resource.NewSchemaless(attribute.Bool("works", true))
|
||||
|
||||
got := RecordFactory{
|
||||
EventName: eventName,
|
||||
Timestamp: now,
|
||||
ObservedTimestamp: observed,
|
||||
Severity: severity,
|
||||
@ -57,6 +59,7 @@ func TestRecordFactory(t *testing.T) {
|
||||
Resource: r,
|
||||
}.NewRecord()
|
||||
|
||||
assert.Equal(t, eventName, got.EventName())
|
||||
assert.Equal(t, now, got.Timestamp())
|
||||
assert.Equal(t, observed, got.ObservedTimestamp())
|
||||
assert.Equal(t, severity, got.Severity())
|
||||
|
@ -42,6 +42,7 @@ func putIndex(index map[string]int) {
|
||||
}
|
||||
|
||||
// Record is a log record emitted by the Logger.
|
||||
// A log record with non-empty event name is interpreted as an event record.
|
||||
//
|
||||
// Do not create instances of Record on your own in production code.
|
||||
// You can use [go.opentelemetry.io/otel/sdk/log/logtest.RecordFactory]
|
||||
@ -50,6 +51,7 @@ type Record struct {
|
||||
// Do not embed the log.Record. Attributes need to be overwrite-able and
|
||||
// deep-copying needs to be possible.
|
||||
|
||||
eventName string
|
||||
timestamp time.Time
|
||||
observedTimestamp time.Time
|
||||
severity log.Severity
|
||||
@ -104,6 +106,18 @@ func (r *Record) setDropped(n int) {
|
||||
r.dropped = n
|
||||
}
|
||||
|
||||
// EventName returns the event name.
|
||||
// A log record with non-empty event name is interpreted as an event record.
|
||||
func (r *Record) EventName() string {
|
||||
return r.eventName
|
||||
}
|
||||
|
||||
// SetEventName sets the event name.
|
||||
// A log record with non-empty event name is interpreted as an event record.
|
||||
func (r *Record) SetEventName(s string) {
|
||||
r.eventName = s
|
||||
}
|
||||
|
||||
// Timestamp returns the time when the log record occurred.
|
||||
func (r *Record) Timestamp() time.Time {
|
||||
return r.timestamp
|
||||
|
@ -19,6 +19,14 @@ import (
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
func TestRecordEventName(t *testing.T) {
|
||||
const text = "testing text"
|
||||
|
||||
r := new(Record)
|
||||
r.SetEventName(text)
|
||||
assert.Equal(t, text, r.EventName())
|
||||
}
|
||||
|
||||
func TestRecordTimestamp(t *testing.T) {
|
||||
now := time.Now()
|
||||
r := new(Record)
|
||||
|
Loading…
x
Reference in New Issue
Block a user