From 6ff42e2accc1c1bd4db733b5110963123eec5f18 Mon Sep 17 00:00:00 2001 From: Dinesh Gurumurthy Date: Wed, 28 Sep 2022 17:08:17 +0000 Subject: [PATCH 1/2] [exporter/datadog] Bug fix for json logs --- .../internal/logs/translator.go | 20 +++++++---- .../internal/logs/translator_test.go | 33 +++++++++++++++++++ unreleased/bug-fix-datadog-exporter.yaml | 16 +++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 unreleased/bug-fix-datadog-exporter.yaml diff --git a/exporter/datadogexporter/internal/logs/translator.go b/exporter/datadogexporter/internal/logs/translator.go index bead49a9f7ff..9f9da57b4091 100644 --- a/exporter/datadogexporter/internal/logs/translator.go +++ b/exporter/datadogexporter/internal/logs/translator.go @@ -75,10 +75,14 @@ func Transform(lr plog.LogRecord, res pcommon.Resource) datadogV2.HTTPLogItem { // we need to set log attributes as AdditionalProperties // AdditionalProperties are treated as Datadog Log Attributes + var status string lr.Attributes().Range(func(k string, v pcommon.Value) bool { switch strings.ToLower(k) { - case "msg", "message": + // set of remapping are taken from https://github.com/DataDog/logs-backend/blob/prod/domains/event-platform/libs/processing/processing-model/src/main/java/com/fsmatic/workload/processing/RemappingConfiguration.java + case "msg", "message", "log": l.Message = v.AsString() + case "status", "severity", "level", "syslog.severity": + status = v.AsString() default: l.AdditionalProperties[k] = v.AsString() } @@ -92,20 +96,22 @@ func Transform(lr plog.LogRecord, res pcommon.Resource) datadogV2.HTTPLogItem { l.AdditionalProperties[ddSpanID] = strconv.FormatUint(spanIDToUint64(lr.SpanID()), 10) l.AdditionalProperties[otelSpanID] = lr.SpanID().HexString() } - var status string - // we want to use the serverity that client has set on the log and let datadog backend + // we want to use the serverity that client has set on the log and let Datadog backend // decide the appropriate level if lr.SeverityText() != "" { - status = lr.SeverityText() + if status == "" { + status = lr.SeverityText() + } l.AdditionalProperties[otelSeverityText] = lr.SeverityText() - } else if lr.SeverityNumber() != 0 { - status = statusFromSeverityNumber(lr.SeverityNumber()) } - l.AdditionalProperties[ddStatus] = status if lr.SeverityNumber() != 0 { + if status == "" { + status = statusFromSeverityNumber(lr.SeverityNumber()) + } l.AdditionalProperties[otelSeverityNumber] = strconv.Itoa(int(lr.SeverityNumber())) } + l.AdditionalProperties[ddStatus] = status // for Datadog to use the same timestamp we need to set the additional property of "@timestamp" if lr.Timestamp() != 0 { // we are retaining the nano second precision in this property diff --git a/exporter/datadogexporter/internal/logs/translator_test.go b/exporter/datadogexporter/internal/logs/translator_test.go index 882813d7bb9b..71a85d21d0d7 100644 --- a/exporter/datadogexporter/internal/logs/translator_test.go +++ b/exporter/datadogexporter/internal/logs/translator_test.go @@ -218,6 +218,39 @@ func TestTransform(t *testing.T) { }, }, }, + { + name: "log-level", + args: args{ + lr: func() plog.LogRecord { + l := plog.NewLogRecord() + l.Attributes().PutString("app", "test") + l.SetSpanID(spanID) + l.SetTraceID(traceID) + l.Attributes().PutString(conventions.AttributeServiceName, "otlp_col") + l.Attributes().PutString("level", "error") + l.Body().SetStr("This is log") + return l + }(), + res: func() pcommon.Resource { + r := pcommon.NewResource() + return r + }(), + }, + want: datadogV2.HTTPLogItem{ + Message: *datadog.PtrString(""), + Service: datadog.PtrString("otlp_col"), + AdditionalProperties: map[string]string{ + "message": "This is log", + "app": "test", + "status": "error", + otelSpanID: fmt.Sprintf("%x", string(spanID[:])), + otelTraceID: fmt.Sprintf("%x", string(traceID[:])), + ddSpanID: fmt.Sprintf("%d", ddSp), + ddTraceID: fmt.Sprintf("%d", ddTr), + "service.name": "otlp_col", + }, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/unreleased/bug-fix-datadog-exporter.yaml b/unreleased/bug-fix-datadog-exporter.yaml new file mode 100644 index 000000000000..bfa764888c5c --- /dev/null +++ b/unreleased/bug-fix-datadog-exporter.yaml @@ -0,0 +1,16 @@ +# 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: exporter/datadogexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Fix log level issue for Json logs + +# One or more tracking issues related to the change +issues: [2651] + +# (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: From 9d5b75d7b6a2cce9a093ed8fd63af7856e145129 Mon Sep 17 00:00:00 2001 From: Dinesh Gurumurthy Date: Wed, 28 Sep 2022 18:26:47 +0000 Subject: [PATCH 2/2] PR comments - remove release notes --- .../datadogexporter/internal/logs/translator.go | 2 +- unreleased/bug-fix-datadog-exporter.yaml | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 unreleased/bug-fix-datadog-exporter.yaml diff --git a/exporter/datadogexporter/internal/logs/translator.go b/exporter/datadogexporter/internal/logs/translator.go index 9f9da57b4091..da15469f3774 100644 --- a/exporter/datadogexporter/internal/logs/translator.go +++ b/exporter/datadogexporter/internal/logs/translator.go @@ -78,7 +78,7 @@ func Transform(lr plog.LogRecord, res pcommon.Resource) datadogV2.HTTPLogItem { var status string lr.Attributes().Range(func(k string, v pcommon.Value) bool { switch strings.ToLower(k) { - // set of remapping are taken from https://github.com/DataDog/logs-backend/blob/prod/domains/event-platform/libs/processing/processing-model/src/main/java/com/fsmatic/workload/processing/RemappingConfiguration.java + // set of remapping are taken from Datadog Backend case "msg", "message", "log": l.Message = v.AsString() case "status", "severity", "level", "syslog.severity": diff --git a/unreleased/bug-fix-datadog-exporter.yaml b/unreleased/bug-fix-datadog-exporter.yaml deleted file mode 100644 index bfa764888c5c..000000000000 --- a/unreleased/bug-fix-datadog-exporter.yaml +++ /dev/null @@ -1,16 +0,0 @@ -# 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: exporter/datadogexporter - -# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Fix log level issue for Json logs - -# One or more tracking issues related to the change -issues: [2651] - -# (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: