Skip to content

Commit c99b5f7

Browse files
authored
[exporter/Logzioexporter] bug fix export log attributes (#33231)
**Description:** Fix bug where log attributes were not correctly exported **Link to tracking Issue:** <Issue number if applicable> open-telemetry/opentelemetry-java-instrumentation#11409 **Testing:** <Describe what testing was performed and which tests were added.> Updated unit tests **Documentation:** <Describe the documentation added.> No documentation added
1 parent ce5c28f commit c99b5f7

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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. filelogreceiver)
7+
component: logzioexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix issue where log attributes were not correctly exported
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [33231]
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+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/logzioexporter/exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ func (exporter *logzioExporter) pushLogData(ctx context.Context, ld plog.Logs) e
130130
for j := 0; j < scopeLogs.Len(); j++ {
131131
logRecords := scopeLogs.At(j).LogRecords()
132132
scope := scopeLogs.At(j).Scope()
133-
details := mergeMapEntries(resource.Attributes(), scope.Attributes())
134-
details.PutStr(`scopeName`, scope.Name())
135133
for k := 0; k < logRecords.Len(); k++ {
136134
log := logRecords.At(k)
135+
details := mergeMapEntries(resource.Attributes(), scope.Attributes(), log.Attributes())
136+
details.PutStr(`scopeName`, scope.Name())
137137
jsonLog, err := json.Marshal(convertLogRecordToJSON(log, details))
138138
if err != nil {
139139
return err

exporter/logzioexporter/exporter_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestPushLogsData(tester *testing.T) {
282282
},
283283
}
284284
defer server.Close()
285-
ld := testdata.GenerateLogs(2)
285+
ld := generateLogsOneEmptyTimestamp()
286286
res := ld.ResourceLogs().At(0).Resource()
287287
res.Attributes().PutStr(conventions.AttributeServiceName, testService)
288288
res.Attributes().PutStr(conventions.AttributeHostName, testHost)
@@ -294,6 +294,12 @@ func TestPushLogsData(tester *testing.T) {
294294
assert.NoError(tester, json.Unmarshal([]byte(requests[0]), &jsonLog))
295295
assert.Equal(tester, testHost, jsonLog["host.name"])
296296
assert.Equal(tester, testService, jsonLog["service.name"])
297+
assert.Equal(tester, "server", jsonLog["app"])
298+
assert.Equal(tester, 1.0, jsonLog["instance_num"])
299+
assert.Equal(tester, "logScopeName", jsonLog["scopeName"])
300+
assert.Equal(tester, "hello there", jsonLog["message"])
301+
assert.Equal(tester, "bar", jsonLog["foo"])
302+
assert.Equal(tester, 45.0, jsonLog["23"])
297303
}
298304

299305
func TestMergeMapEntries(tester *testing.T) {

0 commit comments

Comments
 (0)