@@ -7,6 +7,7 @@ import io.sentry.clientreport.DiscardReason
7
7
import io.sentry.clientreport.DiscardedEvent
8
8
import io.sentry.hints.SessionEndHint
9
9
import io.sentry.hints.SessionStartHint
10
+ import io.sentry.logger.SentryLogParameters
10
11
import io.sentry.protocol.Feedback
11
12
import io.sentry.protocol.SentryId
12
13
import io.sentry.protocol.SentryTransaction
@@ -2648,12 +2649,12 @@ class ScopesTest {
2648
2649
}
2649
2650
2650
2651
@Test
2651
- fun `creating log with attributes works` () {
2652
+ fun `creating log with attributes from map works` () {
2652
2653
val (sut, mockClient) = getEnabledScopes {
2653
2654
it.logs.isEnabled = true
2654
2655
}
2655
2656
2656
- sut.logger().log(mapOf (" attrname1" to " attrval1" ), SentryLogLevel . WARN , " log message" )
2657
+ sut.logger().log(SentryLogLevel . WARN , SentryLogParameters .create( SentryAttributes .fromMap( mapOf (" attrname1" to " attrval1" ))) , " log message" )
2657
2658
2658
2659
verify(mockClient).captureLog(
2659
2660
check {
@@ -2669,13 +2670,78 @@ class ScopesTest {
2669
2670
)
2670
2671
}
2671
2672
2673
+ @Test
2674
+ fun `creating log with attributes works` () {
2675
+ val (sut, mockClient) = getEnabledScopes {
2676
+ it.logs.isEnabled = true
2677
+ }
2678
+
2679
+ sut.logger().log(
2680
+ SentryLogLevel .WARN ,
2681
+ SentryLogParameters .create(
2682
+ SentryAttributes .of(
2683
+ SentryAttribute .stringAttribute(" strattr" , " strval" ),
2684
+ SentryAttribute .booleanAttribute(" boolattr" , true ),
2685
+ SentryAttribute .integerAttribute(" intattr" , 17 ),
2686
+ SentryAttribute .doubleAttribute(" doubleattr" , 3.8 ),
2687
+ SentryAttribute .named(" namedstrattr" , " namedstrval" ),
2688
+ SentryAttribute .named(" namedboolattr" , false ),
2689
+ SentryAttribute .named(" namedintattr" , 18 ),
2690
+ SentryAttribute .named(" nameddoubleattr" , 4.9 )
2691
+ )
2692
+ ),
2693
+ " log message"
2694
+ )
2695
+
2696
+ verify(mockClient).captureLog(
2697
+ check {
2698
+ assertEquals(" log message" , it.body)
2699
+ assertEquals(SentryLogLevel .WARN , it.level)
2700
+ assertEquals(13 , it.severityNumber)
2701
+
2702
+ val strattr = it.attributes?.get(" strattr" )!!
2703
+ assertEquals(" strval" , strattr.value)
2704
+ assertEquals(" string" , strattr.type)
2705
+
2706
+ val boolattr = it.attributes?.get(" boolattr" )!!
2707
+ assertEquals(true , boolattr.value)
2708
+ assertEquals(" boolean" , boolattr.type)
2709
+
2710
+ val intattr = it.attributes?.get(" intattr" )!!
2711
+ assertEquals(17 , intattr.value)
2712
+ assertEquals(" integer" , intattr.type)
2713
+
2714
+ val doubleattr = it.attributes?.get(" doubleattr" )!!
2715
+ assertEquals(3.8 , doubleattr.value)
2716
+ assertEquals(" double" , doubleattr.type)
2717
+
2718
+ val namedstrattr = it.attributes?.get(" namedstrattr" )!!
2719
+ assertEquals(" namedstrval" , namedstrattr.value)
2720
+ assertEquals(" string" , namedstrattr.type)
2721
+
2722
+ val namedboolattr = it.attributes?.get(" namedboolattr" )!!
2723
+ assertEquals(false , namedboolattr.value)
2724
+ assertEquals(" boolean" , namedboolattr.type)
2725
+
2726
+ val namedintattr = it.attributes?.get(" namedintattr" )!!
2727
+ assertEquals(18 , namedintattr.value)
2728
+ assertEquals(" integer" , namedintattr.type)
2729
+
2730
+ val nameddoubleattr = it.attributes?.get(" nameddoubleattr" )!!
2731
+ assertEquals(4.9 , nameddoubleattr.value)
2732
+ assertEquals(" double" , nameddoubleattr.type)
2733
+ },
2734
+ anyOrNull()
2735
+ )
2736
+ }
2737
+
2672
2738
@Test
2673
2739
fun `creating log with attributes and timestamp works` () {
2674
2740
val (sut, mockClient) = getEnabledScopes {
2675
2741
it.logs.isEnabled = true
2676
2742
}
2677
2743
2678
- sut.logger().log(mapOf ( " attrname1" to " attrval1" ), SentryLogLevel . WARN , SentryLongDate ( 123 ), " log message" )
2744
+ sut.logger().log(SentryLogLevel . WARN , SentryLogParameters .create( SentryLongDate ( 123 ), SentryAttributes .of( SentryAttribute .named( " attrname1" , " attrval1" )) ), " log message" )
2679
2745
2680
2746
verify(mockClient).captureLog(
2681
2747
check {
@@ -2698,7 +2764,7 @@ class ScopesTest {
2698
2764
it.logs.isEnabled = true
2699
2765
}
2700
2766
2701
- sut.logger().log(mapOf ( " attrname1" to " attrval1" ), SentryLogLevel . WARN , SentryLongDate ( 123 ), " log %s %d %b %.0f" , " message" , 1 , true , 3.2 )
2767
+ sut.logger().log(SentryLogLevel . WARN , SentryLogParameters .create( SentryLongDate ( 123 ), SentryAttributes .of( SentryAttribute .named( " attrname1" , " attrval1" )) ), " log %s %d %b %.0f" , " message" , 1 , true , 3.2 )
2702
2768
2703
2769
verify(mockClient).captureLog(
2704
2770
check {
0 commit comments