From c99b5f7d46554bfc5bb9d8e2ae96214430d15d76 Mon Sep 17 00:00:00 2001 From: Yotam loewenbach <48534558+yotamloe@users.noreply.github.com> Date: Wed, 5 Jun 2024 19:07:29 +0300 Subject: [PATCH] [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> https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11409 **Testing:** <Describe what testing was performed and which tests were added.> Updated unit tests **Documentation:** <Describe the documentation added.> No documentation added --- ...zioexporter-bug-fix-export-attributes.yaml | 27 +++++++++++++++++++ exporter/logzioexporter/exporter.go | 4 +-- exporter/logzioexporter/exporter_test.go | 8 +++++- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 .chloggen/logzioexporter-bug-fix-export-attributes.yaml diff --git a/.chloggen/logzioexporter-bug-fix-export-attributes.yaml b/.chloggen/logzioexporter-bug-fix-export-attributes.yaml new file mode 100644 index 000000000000..573d3bf4b772 --- /dev/null +++ b/.chloggen/logzioexporter-bug-fix-export-attributes.yaml @@ -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] diff --git a/exporter/logzioexporter/exporter.go b/exporter/logzioexporter/exporter.go index 9ce04c26effc..27eb38b04bc1 100644 --- a/exporter/logzioexporter/exporter.go +++ b/exporter/logzioexporter/exporter.go @@ -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 diff --git a/exporter/logzioexporter/exporter_test.go b/exporter/logzioexporter/exporter_test.go index 190afaa825c6..f3bfe6482209 100644 --- a/exporter/logzioexporter/exporter_test.go +++ b/exporter/logzioexporter/exporter_test.go @@ -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) @@ -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) {