Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/datadog] Correctly derive status for logs from 'level' #14571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions exporter/datadogexporter/internal/logs/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 Datadog Backend
case "msg", "message", "log":
l.Message = v.AsString()
case "status", "severity", "level", "syslog.severity":
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
status = v.AsString()
default:
l.AdditionalProperties[k] = v.AsString()
}
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions exporter/datadogexporter/internal/logs/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down