Skip to content

Commit

Permalink
Assign mapped hostname from OTLP logs in logs agent pipeline (#28870)
Browse files Browse the repository at this point in the history
  • Loading branch information
liustanley authored and truthbk committed Sep 11, 2024
1 parent b622ffb commit 926afcf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func (e *Exporter) ConsumeLogs(ctx context.Context, ld plog.Logs) (err error) {
// ingestionTs is an internal field used for latency tracking on the status page, not the actual log timestamp.
ingestionTs := time.Now().UnixNano()
message := message.NewMessage(content, origin, status, ingestionTs)
if ddLog.Hostname != nil {
message.Hostname = *ddLog.Hostname
}

e.logsAgentChannel <- message
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestLogsExporter(t *testing.T) {
ldd := lrr.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0)
ldd.Attributes().PutStr("message", "hello")
ldd.Attributes().PutStr("datadog.log.source", "custom_source")
ldd.Attributes().PutStr("host.name", "test-host")
return lrr
}(),
otelSource: otelSource,
Expand All @@ -95,6 +96,8 @@ func TestLogsExporter(t *testing.T) {
"otel.trace_id": traceIDToHexOrEmptyString(ld.TraceID()),
"otel.timestamp": fmt.Sprintf("%d", testutil.TestLogTime.UnixNano()),
"resource-attr": "resource-attr-val-1",
"host.name": "test-host",
"hostname": "test-host",
},
},
expectedTags: [][]string{{"otel_source:datadog_agent"}},
Expand Down

0 comments on commit 926afcf

Please sign in to comment.