From 6d41b39785ede37f287838c509cac320f00a54b7 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 20 Dec 2024 11:21:04 -0800 Subject: [PATCH 1/6] [DebugExporter] Add EventName to output --- .chloggen/add-eventname-debug-exporter.yaml | 25 +++++++++++++++++++ CONTRIBUTING.md | 2 +- examples/local/otel-config.yaml | 4 +++ .../debugexporter/internal/otlptext/logs.go | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .chloggen/add-eventname-debug-exporter.yaml diff --git a/.chloggen/add-eventname-debug-exporter.yaml b/.chloggen/add-eventname-debug-exporter.yaml new file mode 100644 index 00000000000..8c7607847ce --- /dev/null +++ b/.chloggen/add-eventname-debug-exporter.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: debugexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: "Add EventName to debug exporter for Logs. EventName was added as top-level field in the LogRecord from 0.15 of proto definition." + +# One or more tracking issues or pull requests related to the change +issues: [11966] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0e0fe0531c..416f7a97b3c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,7 +239,7 @@ There are two Changelogs for this repository: An entry into the changelog is required for the following reasons: -- Changes made to the behaviour of the component +- Changes made to the behavior of the component - Changes to the configuration - Changes to default settings - New components being added diff --git a/examples/local/otel-config.yaml b/examples/local/otel-config.yaml index 20cbf6973f5..168a1631af6 100644 --- a/examples/local/otel-config.yaml +++ b/examples/local/otel-config.yaml @@ -33,5 +33,9 @@ service: receivers: [otlp] processors: [memory_limiter, batch] exporters: [debug] + logs: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [debug] extensions: [zpages] diff --git a/exporter/debugexporter/internal/otlptext/logs.go b/exporter/debugexporter/internal/otlptext/logs.go index 399e9f00d39..60fe22b31ba 100644 --- a/exporter/debugexporter/internal/otlptext/logs.go +++ b/exporter/debugexporter/internal/otlptext/logs.go @@ -38,6 +38,7 @@ func (textLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) { buf.logEntry("Timestamp: %s", lr.Timestamp()) buf.logEntry("SeverityText: %s", lr.SeverityText()) buf.logEntry("SeverityNumber: %s(%d)", lr.SeverityNumber(), lr.SeverityNumber()) + buf.logEntry("EventName: %s", lr.EventName()) buf.logEntry("Body: %s", valueToString(lr.Body())) buf.logAttributes("Attributes", lr.Attributes()) buf.logEntry("Trace ID: %s", lr.TraceID()) From 9708b556cf41b514ed6a66d200a39906e0b408a1 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 20 Dec 2024 11:32:06 -0800 Subject: [PATCH 2/6] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 416f7a97b3c..a0e0fe0531c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -239,7 +239,7 @@ There are two Changelogs for this repository: An entry into the changelog is required for the following reasons: -- Changes made to the behavior of the component +- Changes made to the behaviour of the component - Changes to the configuration - Changes to default settings - New components being added From f7b0a95638e8c63f7ea95c61cd36fdd41d742b78 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 20 Dec 2024 11:34:26 -0800 Subject: [PATCH 3/6] Update .chloggen/add-eventname-debug-exporter.yaml Co-authored-by: Trask Stalnaker --- .chloggen/add-eventname-debug-exporter.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/add-eventname-debug-exporter.yaml b/.chloggen/add-eventname-debug-exporter.yaml index 8c7607847ce..9d4e0649936 100644 --- a/.chloggen/add-eventname-debug-exporter.yaml +++ b/.chloggen/add-eventname-debug-exporter.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: debugexporter # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: "Add EventName to debug exporter for Logs. EventName was added as top-level field in the LogRecord from 0.15 of proto definition." +note: "Add EventName to debug exporter for Logs. EventName was added as top-level field in the LogRecord from 1.5.0 of proto definition." # One or more tracking issues or pull requests related to the change issues: [11966] From 5e55e8ff7923f914595c13800a8526f7d59947e8 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 20 Dec 2024 12:11:19 -0800 Subject: [PATCH 4/6] fix tests --- exporter/debugexporter/internal/otlptext/logs_test.go | 1 + .../internal/otlptext/testdata/logs/embedded_maps.out | 1 + .../internal/otlptext/testdata/logs/one_record.out | 1 + .../internal/otlptext/testdata/logs/two_records.out | 2 ++ pdata/testdata/log.go | 2 ++ 5 files changed, 7 insertions(+) diff --git a/exporter/debugexporter/internal/otlptext/logs_test.go b/exporter/debugexporter/internal/otlptext/logs_test.go index e8e23709459..c35343dabde 100644 --- a/exporter/debugexporter/internal/otlptext/logs_test.go +++ b/exporter/debugexporter/internal/otlptext/logs_test.go @@ -47,6 +47,7 @@ func TestLogsText(t *testing.T) { l.SetTimestamp(pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC))) l.SetSeverityNumber(plog.SeverityNumberInfo) l.SetSeverityText("INFO") + l.SetEventName("my.event") bm := l.Body().SetEmptyMap() bm.PutStr("key1", "val1") bmm := bm.PutEmptyMap("key2") diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out b/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out index 0da7f284706..8beebebff90 100644 --- a/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out @@ -8,6 +8,7 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: INFO SeverityNumber: Info(9) +EventName: my.event Body: Map({"key1":"val1","key2":{"key21":"val21","key22":"val22"}}) Attributes: -> key1: Map({"key11":"val11","key12":"val12","key13":{"key131":"val131"}}) diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out b/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out index f5548208a15..51238820e40 100644 --- a/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out @@ -10,6 +10,7 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info SeverityNumber: Info(9) +EventName: my.event Body: Str(This is a log message) Attributes: -> app: Str(server) diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out b/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out index 6d1eaf7b575..75ff5245e79 100644 --- a/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out @@ -10,6 +10,7 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info SeverityNumber: Info(9) +EventName: my.event Body: Str(This is a log message) Attributes: -> app: Str(server) @@ -22,6 +23,7 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info SeverityNumber: Info(9) +EventName: my.event Body: Str(something happened) Attributes: -> customer: Str(acme) diff --git a/pdata/testdata/log.go b/pdata/testdata/log.go index be9c8b2bce6..661966719fe 100644 --- a/pdata/testdata/log.go +++ b/pdata/testdata/log.go @@ -33,6 +33,7 @@ func fillLogOne(log plog.LogRecord) { log.SetDroppedAttributesCount(1) log.SetSeverityNumber(plog.SeverityNumberInfo) log.SetSeverityText("Info") + log.SetEventName("my.event") log.SetSpanID([8]byte{0x01, 0x02, 0x04, 0x08}) log.SetTraceID([16]byte{0x08, 0x04, 0x02, 0x01}) @@ -48,6 +49,7 @@ func fillLogTwo(log plog.LogRecord) { log.SetDroppedAttributesCount(1) log.SetSeverityNumber(plog.SeverityNumberInfo) log.SetSeverityText("Info") + log.SetEventName("my.event") attrs := log.Attributes() attrs.PutStr("customer", "acme") From e6f71df9f18384cf8fde91fa18b5e4b01858a6f3 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 20 Dec 2024 13:22:42 -0800 Subject: [PATCH 5/6] emit eventname only if not empty --- exporter/debugexporter/internal/otlptext/logs.go | 4 +++- exporter/debugexporter/internal/otlptext/logs_test.go | 1 - .../internal/otlptext/testdata/logs/embedded_maps.out | 1 - .../internal/otlptext/testdata/logs/one_record.out | 1 - .../internal/otlptext/testdata/logs/two_records.out | 2 -- pdata/testdata/log.go | 2 -- 6 files changed, 3 insertions(+), 8 deletions(-) diff --git a/exporter/debugexporter/internal/otlptext/logs.go b/exporter/debugexporter/internal/otlptext/logs.go index 60fe22b31ba..f2ab523b5c6 100644 --- a/exporter/debugexporter/internal/otlptext/logs.go +++ b/exporter/debugexporter/internal/otlptext/logs.go @@ -38,7 +38,9 @@ func (textLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) { buf.logEntry("Timestamp: %s", lr.Timestamp()) buf.logEntry("SeverityText: %s", lr.SeverityText()) buf.logEntry("SeverityNumber: %s(%d)", lr.SeverityNumber(), lr.SeverityNumber()) - buf.logEntry("EventName: %s", lr.EventName()) + if lr.EventName() != "" { + buf.logEntry("EventName: %s", lr.EventName()) + } buf.logEntry("Body: %s", valueToString(lr.Body())) buf.logAttributes("Attributes", lr.Attributes()) buf.logEntry("Trace ID: %s", lr.TraceID()) diff --git a/exporter/debugexporter/internal/otlptext/logs_test.go b/exporter/debugexporter/internal/otlptext/logs_test.go index c35343dabde..e8e23709459 100644 --- a/exporter/debugexporter/internal/otlptext/logs_test.go +++ b/exporter/debugexporter/internal/otlptext/logs_test.go @@ -47,7 +47,6 @@ func TestLogsText(t *testing.T) { l.SetTimestamp(pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC))) l.SetSeverityNumber(plog.SeverityNumberInfo) l.SetSeverityText("INFO") - l.SetEventName("my.event") bm := l.Body().SetEmptyMap() bm.PutStr("key1", "val1") bmm := bm.PutEmptyMap("key2") diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out b/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out index 8beebebff90..0da7f284706 100644 --- a/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/embedded_maps.out @@ -8,7 +8,6 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: INFO SeverityNumber: Info(9) -EventName: my.event Body: Map({"key1":"val1","key2":{"key21":"val21","key22":"val22"}}) Attributes: -> key1: Map({"key11":"val11","key12":"val12","key13":{"key131":"val131"}}) diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out b/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out index 51238820e40..f5548208a15 100644 --- a/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/one_record.out @@ -10,7 +10,6 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info SeverityNumber: Info(9) -EventName: my.event Body: Str(This is a log message) Attributes: -> app: Str(server) diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out b/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out index 75ff5245e79..6d1eaf7b575 100644 --- a/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/two_records.out @@ -10,7 +10,6 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info SeverityNumber: Info(9) -EventName: my.event Body: Str(This is a log message) Attributes: -> app: Str(server) @@ -23,7 +22,6 @@ ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC SeverityText: Info SeverityNumber: Info(9) -EventName: my.event Body: Str(something happened) Attributes: -> customer: Str(acme) diff --git a/pdata/testdata/log.go b/pdata/testdata/log.go index 661966719fe..be9c8b2bce6 100644 --- a/pdata/testdata/log.go +++ b/pdata/testdata/log.go @@ -33,7 +33,6 @@ func fillLogOne(log plog.LogRecord) { log.SetDroppedAttributesCount(1) log.SetSeverityNumber(plog.SeverityNumberInfo) log.SetSeverityText("Info") - log.SetEventName("my.event") log.SetSpanID([8]byte{0x01, 0x02, 0x04, 0x08}) log.SetTraceID([16]byte{0x08, 0x04, 0x02, 0x01}) @@ -49,7 +48,6 @@ func fillLogTwo(log plog.LogRecord) { log.SetDroppedAttributesCount(1) log.SetSeverityNumber(plog.SeverityNumberInfo) log.SetSeverityText("Info") - log.SetEventName("my.event") attrs := log.Attributes() attrs.PutStr("customer", "acme") From 553e8dbbbd75aff59dcd4d610c2ad2f102e1b483 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Sun, 22 Dec 2024 12:24:50 -0800 Subject: [PATCH 6/6] add test --- .../internal/otlptext/logs_test.go | 19 +++++++++++++++++++ .../testdata/logs/log_with_event_name.out | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 exporter/debugexporter/internal/otlptext/testdata/logs/log_with_event_name.out diff --git a/exporter/debugexporter/internal/otlptext/logs_test.go b/exporter/debugexporter/internal/otlptext/logs_test.go index e8e23709459..b973964fb96 100644 --- a/exporter/debugexporter/internal/otlptext/logs_test.go +++ b/exporter/debugexporter/internal/otlptext/logs_test.go @@ -39,6 +39,25 @@ func TestLogsText(t *testing.T) { in: testdata.GenerateLogs(2), out: "two_records.out", }, + { + name: "log_with_event_name", + in: func() plog.Logs { + ls := plog.NewLogs() + l := ls.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty() + l.SetTimestamp(pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC))) + l.SetSeverityNumber(plog.SeverityNumberInfo) + l.SetSeverityText("Info") + l.SetEventName("event_name") + l.Body().SetStr("This is a log message") + attrs := l.Attributes() + attrs.PutStr("app", "server") + attrs.PutInt("instance_num", 1) + l.SetSpanID([8]byte{0x01, 0x02, 0x04, 0x08}) + l.SetTraceID([16]byte{0x08, 0x04, 0x02, 0x01}) + return ls + }(), + out: "log_with_event_name.out", + }, { name: "logs_with_embedded_maps", in: func() plog.Logs { diff --git a/exporter/debugexporter/internal/otlptext/testdata/logs/log_with_event_name.out b/exporter/debugexporter/internal/otlptext/testdata/logs/log_with_event_name.out new file mode 100644 index 00000000000..5085adda620 --- /dev/null +++ b/exporter/debugexporter/internal/otlptext/testdata/logs/log_with_event_name.out @@ -0,0 +1,18 @@ +ResourceLog #0 +Resource SchemaURL: +ScopeLogs #0 +ScopeLogs SchemaURL: +InstrumentationScope +LogRecord #0 +ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC +Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC +SeverityText: Info +SeverityNumber: Info(9) +EventName: event_name +Body: Str(This is a log message) +Attributes: + -> app: Str(server) + -> instance_num: Int(1) +Trace ID: 08040201000000000000000000000000 +Span ID: 0102040800000000 +Flags: 0