Skip to content

Commit

Permalink
[exporter/Logzioexporter] bug fix export log attributes (#33231)
Browse files Browse the repository at this point in the history
**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
  • Loading branch information
yotamloe authored Jun 5, 2024
1 parent ce5c28f commit c99b5f7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .chloggen/logzioexporter-bug-fix-export-attributes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: logzioexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix issue where log attributes were not correctly exported

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [33231]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: [user]
4 changes: 2 additions & 2 deletions exporter/logzioexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func (exporter *logzioExporter) pushLogData(ctx context.Context, ld plog.Logs) e
for j := 0; j < scopeLogs.Len(); j++ {
logRecords := scopeLogs.At(j).LogRecords()
scope := scopeLogs.At(j).Scope()
details := mergeMapEntries(resource.Attributes(), scope.Attributes())
details.PutStr(`scopeName`, scope.Name())
for k := 0; k < logRecords.Len(); k++ {
log := logRecords.At(k)
details := mergeMapEntries(resource.Attributes(), scope.Attributes(), log.Attributes())
details.PutStr(`scopeName`, scope.Name())
jsonLog, err := json.Marshal(convertLogRecordToJSON(log, details))
if err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion exporter/logzioexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func TestPushLogsData(tester *testing.T) {
},
}
defer server.Close()
ld := testdata.GenerateLogs(2)
ld := generateLogsOneEmptyTimestamp()
res := ld.ResourceLogs().At(0).Resource()
res.Attributes().PutStr(conventions.AttributeServiceName, testService)
res.Attributes().PutStr(conventions.AttributeHostName, testHost)
Expand All @@ -294,6 +294,12 @@ func TestPushLogsData(tester *testing.T) {
assert.NoError(tester, json.Unmarshal([]byte(requests[0]), &jsonLog))
assert.Equal(tester, testHost, jsonLog["host.name"])
assert.Equal(tester, testService, jsonLog["service.name"])
assert.Equal(tester, "server", jsonLog["app"])
assert.Equal(tester, 1.0, jsonLog["instance_num"])
assert.Equal(tester, "logScopeName", jsonLog["scopeName"])
assert.Equal(tester, "hello there", jsonLog["message"])
assert.Equal(tester, "bar", jsonLog["foo"])
assert.Equal(tester, 45.0, jsonLog["23"])
}

func TestMergeMapEntries(tester *testing.T) {
Expand Down

0 comments on commit c99b5f7

Please sign in to comment.