@@ -169,6 +169,74 @@ defmodule Neurow.EcsLogFormatterTest do
169
169
}
170
170
end
171
171
172
+ test "supports optional http_method metadata" do
173
+ metadata = % {
174
+ time: 1_728_556_213_722_376 ,
175
+ mfa: { Neurow.EcsLogFormatterTest , :fake_function , 4 } ,
176
+ file: "test/neurow/ecs_log_formatter_test.exs" ,
177
+ line: 10 ,
178
+ http_method: "POST"
179
+ }
180
+
181
+ json_log =
182
+ Neurow.EcsLogFormatter . format ( :info , "Hello, world!" , nil , metadata )
183
+ |> :jiffy . decode ( [ :return_maps ] )
184
+
185
+ assert json_log == % {
186
+ "@timestamp" => "2024-10-10T10:30:13.722376Z" ,
187
+ "log.level" => "info" ,
188
+ "log.name" => "Elixir.Neurow.EcsLogFormatterTest.fake_function/4" ,
189
+ "log.source" => % {
190
+ "file" => % {
191
+ "name" => "test/neurow/ecs_log_formatter_test.exs" ,
192
+ "line" => 10
193
+ }
194
+ } ,
195
+ "ecs.version" => "8.11.0" ,
196
+ "message" => "Hello, world!" ,
197
+ "category" => "app" ,
198
+ "service" => % {
199
+ "name" => "neurow" ,
200
+ "version" => "unknown"
201
+ } ,
202
+ "http.request.method" => "POST"
203
+ }
204
+ end
205
+
206
+ test "supports optional http_path metadata" do
207
+ metadata = % {
208
+ time: 1_728_556_213_722_376 ,
209
+ mfa: { Neurow.EcsLogFormatterTest , :fake_function , 4 } ,
210
+ file: "test/neurow/ecs_log_formatter_test.exs" ,
211
+ line: 10 ,
212
+ http_path: "/foobar"
213
+ }
214
+
215
+ json_log =
216
+ Neurow.EcsLogFormatter . format ( :info , "Hello, world!" , nil , metadata )
217
+ |> :jiffy . decode ( [ :return_maps ] )
218
+
219
+ assert json_log == % {
220
+ "@timestamp" => "2024-10-10T10:30:13.722376Z" ,
221
+ "log.level" => "info" ,
222
+ "log.name" => "Elixir.Neurow.EcsLogFormatterTest.fake_function/4" ,
223
+ "log.source" => % {
224
+ "file" => % {
225
+ "name" => "test/neurow/ecs_log_formatter_test.exs" ,
226
+ "line" => 10
227
+ }
228
+ } ,
229
+ "ecs.version" => "8.11.0" ,
230
+ "message" => "Hello, world!" ,
231
+ "category" => "app" ,
232
+ "service" => % {
233
+ "name" => "neurow" ,
234
+ "version" => "unknown"
235
+ } ,
236
+ "http.request.path" => "/foobar"
237
+ }
238
+ end
239
+
172
240
test "multiline messages are inlined" do
173
241
metadata = % {
174
242
time: 1_728_556_213_722_376 ,
0 commit comments