@@ -72,6 +72,7 @@ func TestLogsExporter(t *testing.T) {
72
72
lrr := testutil .GenerateLogsOneLogRecord ()
73
73
ldd := lrr .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (0 )
74
74
ldd .Attributes ().PutStr ("message" , "hello" )
75
+ ldd .Attributes ().PutStr ("datadog.log.source" , "custom_source" )
75
76
return lrr
76
77
}(),
77
78
otelSource : otelSource ,
@@ -83,6 +84,41 @@ func TestLogsExporter(t *testing.T) {
83
84
"message" : "hello" ,
84
85
"app" : "server" ,
85
86
"instance_num" : "1" ,
87
+ "datadog.log.source" : "custom_source" ,
88
+ "@timestamp" : testutil .TestLogTime .Format ("2006-01-02T15:04:05.000Z07:00" ),
89
+ "status" : "Info" ,
90
+ "dd.span_id" : fmt .Sprintf ("%d" , spanIDToUint64 (ld .SpanID ())),
91
+ "dd.trace_id" : fmt .Sprintf ("%d" , traceIDToUint64 (ld .TraceID ())),
92
+ "otel.severity_text" : "Info" ,
93
+ "otel.severity_number" : "9" ,
94
+ "otel.span_id" : spanIDToHexOrEmptyString (ld .SpanID ()),
95
+ "otel.trace_id" : traceIDToHexOrEmptyString (ld .TraceID ()),
96
+ "otel.timestamp" : fmt .Sprintf ("%d" , testutil .TestLogTime .UnixNano ()),
97
+ "resource-attr" : "resource-attr-val-1" ,
98
+ },
99
+ },
100
+ expectedTags : [][]string {{"otel_source:datadog_agent" }},
101
+ },
102
+ {
103
+ name : "resource-attribute-source" ,
104
+ args : args {
105
+ ld : func () plog.Logs {
106
+ l := testutil .GenerateLogsOneLogRecord ()
107
+ rl := l .ResourceLogs ().At (0 )
108
+ resourceAttrs := rl .Resource ().Attributes ()
109
+ resourceAttrs .PutStr ("datadog.log.source" , "custom_source_rattr" )
110
+ return l
111
+ }(),
112
+ otelSource : otelSource ,
113
+ logSourceName : LogSourceName ,
114
+ },
115
+
116
+ want : testutil.JSONLogs {
117
+ {
118
+ "message" : "This is a log message" ,
119
+ "app" : "server" ,
120
+ "instance_num" : "1" ,
121
+ "datadog.log.source" : "custom_source_rattr" ,
86
122
"@timestamp" : testutil .TestLogTime .Format ("2006-01-02T15:04:05.000Z07:00" ),
87
123
"status" : "Info" ,
88
124
"dd.span_id" : fmt .Sprintf ("%d" , spanIDToUint64 (ld .SpanID ())),
@@ -186,7 +222,7 @@ func TestLogsExporter(t *testing.T) {
186
222
return lrr
187
223
}(),
188
224
otelSource : "datadog_exporter" ,
189
- logSourceName : "custom_source " ,
225
+ logSourceName : "" ,
190
226
},
191
227
192
228
want : testutil.JSONLogs {
@@ -241,7 +277,11 @@ func TestLogsExporter(t *testing.T) {
241
277
output := <- testChannel
242
278
outputJSON := make (map [string ]interface {})
243
279
json .Unmarshal (output .GetContent (), & outputJSON )
244
- assert .Equal (t , tt .args .logSourceName , output .Origin .Source ())
280
+ if src , ok := outputJSON ["datadog.log.source" ]; ok {
281
+ assert .Equal (t , src , output .Origin .Source ())
282
+ } else {
283
+ assert .Equal (t , tt .args .logSourceName , output .Origin .Source ())
284
+ }
245
285
assert .Equal (t , tt .expectedTags [i ], output .Origin .Tags (nil ))
246
286
ans = append (ans , outputJSON )
247
287
}
0 commit comments