Skip to content

Commit 12b0369

Browse files
cijothomastraskcodeboten
authored
[DebugExporter] Add EventName from LogRecord to output (#11967)
#### Description 1. Adds event name from LogRecord to debug exporter. 2. Also modified the example config file to include logs too. (It only had traces/metrics). Not really required for this change, but hope that is okay to club into same PR! #### Link to tracking issue Fixes #11966 #### Testing Manually tested with Otel client that exported a LogRecord with event name and without event name. (1st time contributor here, still learning the process.) --------- Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Alex Boten <[email protected]>
1 parent 3132112 commit 12b0369

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: debugexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
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."
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [11966]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: []

examples/local/otel-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ service:
3333
receivers: [otlp]
3434
processors: [memory_limiter, batch]
3535
exporters: [debug]
36+
logs:
37+
receivers: [otlp]
38+
processors: [memory_limiter, batch]
39+
exporters: [debug]
3640

3741
extensions: [zpages]

exporter/debugexporter/internal/otlptext/logs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func (textLogsMarshaler) MarshalLogs(ld plog.Logs) ([]byte, error) {
3838
buf.logEntry("Timestamp: %s", lr.Timestamp())
3939
buf.logEntry("SeverityText: %s", lr.SeverityText())
4040
buf.logEntry("SeverityNumber: %s(%d)", lr.SeverityNumber(), lr.SeverityNumber())
41+
if lr.EventName() != "" {
42+
buf.logEntry("EventName: %s", lr.EventName())
43+
}
4144
buf.logEntry("Body: %s", valueToString(lr.Body()))
4245
buf.logAttributes("Attributes", lr.Attributes())
4346
buf.logEntry("Trace ID: %s", lr.TraceID())

exporter/debugexporter/internal/otlptext/logs_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ func TestLogsText(t *testing.T) {
3939
in: testdata.GenerateLogs(2),
4040
out: "two_records.out",
4141
},
42+
{
43+
name: "log_with_event_name",
44+
in: func() plog.Logs {
45+
ls := plog.NewLogs()
46+
l := ls.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty()
47+
l.SetTimestamp(pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC)))
48+
l.SetSeverityNumber(plog.SeverityNumberInfo)
49+
l.SetSeverityText("Info")
50+
l.SetEventName("event_name")
51+
l.Body().SetStr("This is a log message")
52+
attrs := l.Attributes()
53+
attrs.PutStr("app", "server")
54+
attrs.PutInt("instance_num", 1)
55+
l.SetSpanID([8]byte{0x01, 0x02, 0x04, 0x08})
56+
l.SetTraceID([16]byte{0x08, 0x04, 0x02, 0x01})
57+
return ls
58+
}(),
59+
out: "log_with_event_name.out",
60+
},
4261
{
4362
name: "logs_with_embedded_maps",
4463
in: func() plog.Logs {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ResourceLog #0
2+
Resource SchemaURL:
3+
ScopeLogs #0
4+
ScopeLogs SchemaURL:
5+
InstrumentationScope
6+
LogRecord #0
7+
ObservedTimestamp: 1970-01-01 00:00:00 +0000 UTC
8+
Timestamp: 2020-02-11 20:26:13.000000789 +0000 UTC
9+
SeverityText: Info
10+
SeverityNumber: Info(9)
11+
EventName: event_name
12+
Body: Str(This is a log message)
13+
Attributes:
14+
-> app: Str(server)
15+
-> instance_num: Int(1)
16+
Trace ID: 08040201000000000000000000000000
17+
Span ID: 0102040800000000
18+
Flags: 0

0 commit comments

Comments
 (0)