Skip to content

Commit 8377ee7

Browse files
authored
fix(pdata/plog): unmarshal event_name from json (#13123)
#### Description This PR adds missing logic to process `event_name` field when unmarshaling LogRecords from JSON. #### Testing Added `eventName` to json (un)marshal tests. Fixes #13127
1 parent 6f269eb commit 8377ee7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: pdata
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix event_name skipped when unmarshalling LogRecord from JSON
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [13127]
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: [user]

pdata/plog/json.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ func (ms LogRecord) unmarshalJsoniter(iter *jsoniter.Iterator) {
108108
ms.orig.SeverityNumber = otlplogs.SeverityNumber(json.ReadEnumValue(iter, otlplogs.SeverityNumber_value))
109109
case "severity_text", "severityText":
110110
ms.orig.SeverityText = iter.ReadString()
111+
case "event_name", "eventName":
112+
ms.orig.EventName = iter.ReadString()
111113
case "body":
112114
json.ReadValue(iter, &ms.orig.Body)
113115
case "attributes":

pdata/plog/json_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var logsOTLP = func() Logs {
4444
lg.SetObservedTimestamp(pcommon.Timestamp(1684623646539558000))
4545
lg.Attributes().PutStr("sdkVersion", "1.0.1")
4646
lg.SetFlags(DefaultLogRecordFlags.WithIsSampled(true))
47+
lg.SetEventName("someEvent")
4748
return ld
4849
}()
4950

@@ -57,7 +58,7 @@ func TestLogsJSON(t *testing.T) {
5758
assert.Equal(t, logsOTLP, got)
5859
}
5960

60-
var logsJSON = `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"testHost"}}],"droppedAttributesCount":1},"scopeLogs":[{"scope":{"name":"name","version":"version","droppedAttributesCount":1},"logRecords":[{"timeUnixNano":"1684617382541971000","observedTimeUnixNano":"1684623646539558000","severityNumber":17,"severityText":"Error","body":{"stringValue":"hello world"},"attributes":[{"key":"sdkVersion","value":{"stringValue":"1.0.1"}}],"droppedAttributesCount":1,"flags":1,"traceId":"0102030405060708090a0b0c0d0e0f10","spanId":"1112131415161718"}],"schemaUrl":"scope_schema"}],"schemaUrl":"resource_schema"}]}`
61+
var logsJSON = `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"testHost"}}],"droppedAttributesCount":1},"scopeLogs":[{"scope":{"name":"name","version":"version","droppedAttributesCount":1},"logRecords":[{"eventName":"someEvent","timeUnixNano":"1684617382541971000","observedTimeUnixNano":"1684623646539558000","severityNumber":17,"severityText":"Error","body":{"stringValue":"hello world"},"attributes":[{"key":"sdkVersion","value":{"stringValue":"1.0.1"}}],"droppedAttributesCount":1,"flags":1,"traceId":"0102030405060708090a0b0c0d0e0f10","spanId":"1112131415161718"}],"schemaUrl":"scope_schema"}],"schemaUrl":"resource_schema"}]}`
6162

6263
func TestJSONUnmarshal(t *testing.T) {
6364
decoder := &JSONUnmarshaler{}

0 commit comments

Comments
 (0)