@@ -244,12 +244,14 @@ func TestLogsToLokiRequestWithGroupingByTenant(t *testing.T) {
244
244
245
245
func TestLogsToLokiRequestWithoutTenant (t * testing.T ) {
246
246
testCases := []struct {
247
- desc string
248
- hints map [string ]interface {}
249
- attrs map [string ]interface {}
250
- res map [string ]interface {}
251
- expectedLabel string
252
- expectedLines []string
247
+ desc string
248
+ hints map [string ]interface {}
249
+ attrs map [string ]interface {}
250
+ res map [string ]interface {}
251
+ severity plog.SeverityNumber
252
+ levelAttribute string
253
+ expectedLabel string
254
+ expectedLines []string
253
255
}{
254
256
{
255
257
desc : "with attribute to label and regular attribute" ,
@@ -300,6 +302,27 @@ func TestLogsToLokiRequestWithoutTenant(t *testing.T) {
300
302
`traceID=03000000000000000000000000000000 attribute_http.status=200` ,
301
303
},
302
304
},
305
+ {
306
+ desc : "with severity to label" ,
307
+ severity : plog .SeverityNumberDebug4 ,
308
+ expectedLabel : `{exporter="OTLP", level="DEBUG4"}` ,
309
+ expectedLines : []string {
310
+ `{"traceid":"01000000000000000000000000000000"}` ,
311
+ `{"traceid":"02000000000000000000000000000000"}` ,
312
+ `{"traceid":"03000000000000000000000000000000"}` ,
313
+ },
314
+ },
315
+ {
316
+ desc : "with severity, already existing level" ,
317
+ severity : plog .SeverityNumberDebug4 ,
318
+ levelAttribute : "dummy" ,
319
+ expectedLabel : `{exporter="OTLP", level="dummy"}` ,
320
+ expectedLines : []string {
321
+ `{"traceid":"01000000000000000000000000000000"}` ,
322
+ `{"traceid":"02000000000000000000000000000000"}` ,
323
+ `{"traceid":"03000000000000000000000000000000"}` ,
324
+ },
325
+ },
303
326
}
304
327
for _ , tt := range testCases {
305
328
t .Run (tt .desc , func (t * testing.T ) {
@@ -310,6 +333,10 @@ func TestLogsToLokiRequestWithoutTenant(t *testing.T) {
310
333
ld .ResourceLogs ().At (0 ).ScopeLogs ().AppendEmpty ()
311
334
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (i ).LogRecords ().AppendEmpty ()
312
335
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (i ).LogRecords ().At (0 ).SetTraceID ([16 ]byte {byte (i + 1 )})
336
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (i ).LogRecords ().At (0 ).SetSeverityNumber (tt .severity )
337
+ if len (tt .levelAttribute ) > 0 {
338
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (i ).LogRecords ().At (0 ).Attributes ().PutStr (levelAttributeName , tt .levelAttribute )
339
+ }
313
340
}
314
341
315
342
if len (tt .res ) > 0 {
@@ -355,12 +382,14 @@ func TestLogsToLokiRequestWithoutTenant(t *testing.T) {
355
382
356
383
func TestLogsToLoki (t * testing.T ) {
357
384
testCases := []struct {
358
- desc string
359
- hints map [string ]interface {}
360
- attrs map [string ]interface {}
361
- res map [string ]interface {}
362
- expectedLabel string
363
- expectedLines []string
385
+ desc string
386
+ hints map [string ]interface {}
387
+ attrs map [string ]interface {}
388
+ res map [string ]interface {}
389
+ severity plog.SeverityNumber
390
+ levelAttribute string
391
+ expectedLabel string
392
+ expectedLines []string
364
393
}{
365
394
{
366
395
desc : "with attribute to label and regular attribute" ,
@@ -411,6 +440,27 @@ func TestLogsToLoki(t *testing.T) {
411
440
`traceID=01020304050600000000000000000000 resource_region.az=eu-west-1a` ,
412
441
},
413
442
},
443
+ {
444
+ desc : "with severity to label" ,
445
+ severity : plog .SeverityNumberDebug4 ,
446
+ expectedLabel : `{exporter="OTLP", level="DEBUG4"}` ,
447
+ expectedLines : []string {
448
+ `{"traceid":"01020304000000000000000000000000"}` ,
449
+ `{"traceid":"01020304050000000000000000000000"}` ,
450
+ `{"traceid":"01020304050600000000000000000000"}` ,
451
+ },
452
+ },
453
+ {
454
+ desc : "with severity, already existing level" ,
455
+ severity : plog .SeverityNumberDebug4 ,
456
+ levelAttribute : "dummy" ,
457
+ expectedLabel : `{exporter="OTLP", level="dummy"}` ,
458
+ expectedLines : []string {
459
+ `{"traceid":"01020304000000000000000000000000"}` ,
460
+ `{"traceid":"01020304050000000000000000000000"}` ,
461
+ `{"traceid":"01020304050600000000000000000000"}` ,
462
+ },
463
+ },
414
464
}
415
465
for _ , tC := range testCases {
416
466
t .Run (tC .desc , func (t * testing.T ) {
@@ -421,8 +471,11 @@ func TestLogsToLoki(t *testing.T) {
421
471
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().AppendEmpty ()
422
472
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().AppendEmpty ()
423
473
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().AppendEmpty ()
474
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (0 ).SetSeverityNumber (tC .severity )
424
475
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (0 ).SetTraceID (pcommon .TraceID ([16 ]byte {1 , 2 , 3 , 4 }))
476
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (1 ).SetSeverityNumber (tC .severity )
425
477
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (1 ).SetTraceID (pcommon .TraceID ([16 ]byte {1 , 2 , 3 , 4 , 5 }))
478
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (2 ).SetSeverityNumber (tC .severity )
426
479
ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (2 ).SetTraceID (pcommon .TraceID ([16 ]byte {1 , 2 , 3 , 4 , 5 , 6 }))
427
480
428
481
// copy the attributes from the test case to the log entry
@@ -434,6 +487,11 @@ func TestLogsToLoki(t *testing.T) {
434
487
if len (tC .res ) > 0 {
435
488
ld .ResourceLogs ().At (0 ).Resource ().Attributes ().FromRaw (tC .res )
436
489
}
490
+ if len (tC .levelAttribute ) > 0 {
491
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (0 ).Attributes ().PutStr (levelAttributeName , tC .levelAttribute )
492
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (1 ).Attributes ().PutStr (levelAttributeName , tC .levelAttribute )
493
+ ld .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (2 ).Attributes ().PutStr (levelAttributeName , tC .levelAttribute )
494
+ }
437
495
438
496
// we can't use copy here, as the value (Value) will be used as string lookup later, so, we need to convert it to string now
439
497
for k , v := range tC .hints {
0 commit comments