1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-24 03:47:19 +02:00
Robert Pająk 2025-01-22 17:46:47 +01:00 committed by GitHub
parent 185547c846
commit 62e4225a42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 36 additions and 1 deletions

View File

@ -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 -->

View File

@ -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

View File

@ -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(),

View File

@ -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(),

View File

@ -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)

View File

@ -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())

View File

@ -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

View File

@ -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)