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

Add custom log source support #28745

Merged
merged 4 commits into from
Aug 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ func (e *Exporter) ConsumeLogs(ctx context.Context, ld plog.Logs) (err error) {
origin := message.NewOrigin(e.logSource)
origin.SetTags(tags)
origin.SetService(service)
origin.SetSource(e.logSource.Name)
if src, ok := ddLog.AdditionalProperties["datadog.log.source"]; ok {
origin.SetSource(src)
} else {
origin.SetSource(e.logSource.Name)
}

content, err := ddLog.MarshalJSON()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestLogsExporter(t *testing.T) {
lrr := testutil.GenerateLogsOneLogRecord()
ldd := lrr.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0)
ldd.Attributes().PutStr("message", "hello")
ldd.Attributes().PutStr("datadog.log.source", "custom_source")
songy23 marked this conversation as resolved.
Show resolved Hide resolved
return lrr
}(),
otelSource: otelSource,
Expand All @@ -83,6 +84,41 @@ func TestLogsExporter(t *testing.T) {
"message": "hello",
"app": "server",
"instance_num": "1",
"datadog.log.source": "custom_source",
"@timestamp": testutil.TestLogTime.Format("2006-01-02T15:04:05.000Z07:00"),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
"dd.trace_id": fmt.Sprintf("%d", traceIDToUint64(ld.TraceID())),
"otel.severity_text": "Info",
"otel.severity_number": "9",
"otel.span_id": spanIDToHexOrEmptyString(ld.SpanID()),
"otel.trace_id": traceIDToHexOrEmptyString(ld.TraceID()),
"otel.timestamp": fmt.Sprintf("%d", testutil.TestLogTime.UnixNano()),
"resource-attr": "resource-attr-val-1",
},
},
expectedTags: [][]string{{"otel_source:datadog_agent"}},
},
{
name: "resource-attribute-source",
args: args{
ld: func() plog.Logs {
l := testutil.GenerateLogsOneLogRecord()
rl := l.ResourceLogs().At(0)
resourceAttrs := rl.Resource().Attributes()
resourceAttrs.PutStr("datadog.log.source", "custom_source_rattr")
return l
}(),
otelSource: otelSource,
logSourceName: LogSourceName,
},

want: testutil.JSONLogs{
{
"message": "This is a log message",
"app": "server",
"instance_num": "1",
"datadog.log.source": "custom_source_rattr",
"@timestamp": testutil.TestLogTime.Format("2006-01-02T15:04:05.000Z07:00"),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
Expand Down Expand Up @@ -186,7 +222,7 @@ func TestLogsExporter(t *testing.T) {
return lrr
}(),
otelSource: "datadog_exporter",
logSourceName: "custom_source",
logSourceName: "",
},

want: testutil.JSONLogs{
Expand Down Expand Up @@ -241,7 +277,11 @@ func TestLogsExporter(t *testing.T) {
output := <-testChannel
outputJSON := make(map[string]interface{})
json.Unmarshal(output.GetContent(), &outputJSON)
assert.Equal(t, tt.args.logSourceName, output.Origin.Source())
if src, ok := outputJSON["datadog.log.source"]; ok {
assert.Equal(t, src, output.Origin.Source())
} else {
assert.Equal(t, tt.args.logSourceName, output.Origin.Source())
}
assert.Equal(t, tt.expectedTags[i], output.Origin.Tags(nil))
ans = append(ans, outputJSON)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
enhancements:
- |
Add support for setting a custom log source from resource attribute or log attribute `datadog.log.source`.
Loading