Commit 8c5e12e 1 parent 64549d7 commit 8c5e12e Copy full SHA for 8c5e12e
File tree 3 files changed +26
-13
lines changed
opentelemetry-sdk/src/logs
3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,6 @@ impl SdkLogger {
18
18
pub ( crate ) fn new ( scope : InstrumentationScope , provider : SdkLoggerProvider ) -> Self {
19
19
SdkLogger { scope, provider }
20
20
}
21
-
22
- #[ cfg( test) ]
23
- pub ( crate ) fn instrumentation_scope ( & self ) -> & InstrumentationScope {
24
- & self . scope
25
- }
26
21
}
27
22
28
23
impl opentelemetry:: logs:: Logger for SdkLogger {
Original file line number Diff line number Diff line change @@ -700,21 +700,23 @@ mod tests {
700
700
scoped_logger. emit ( scoped_record) ;
701
701
702
702
// Assert: Verify that the emitted logs are processed correctly
703
- let emitted_logs = exporter. get_emitted_logs ( ) . unwrap ( ) ;
703
+ let mut emitted_logs = exporter. get_emitted_logs ( ) . unwrap ( ) ;
704
704
assert_eq ! ( emitted_logs. len( ) , 2 ) ;
705
+ let log1 = emitted_logs. remove ( 0 ) ;
705
706
// Assert the first log
706
707
assert_eq ! (
707
- emitted_logs [ 0 ] . clone ( ) . record. body,
708
+ log1 . record. body,
708
709
Some ( AnyValue :: String ( "Testing empty logger name" . into( ) ) )
709
710
) ;
710
- assert_eq ! ( logger . instrumentation_scope ( ) . name( ) , "" ) ;
711
+ assert_eq ! ( log1 . instrumentation . name( ) , "" ) ;
711
712
712
713
// Assert the second log created through the scope
714
+ let log2 = emitted_logs. remove ( 0 ) ;
713
715
assert_eq ! (
714
- emitted_logs [ 1 ] . clone ( ) . record. body,
716
+ log2 . record. body,
715
717
Some ( AnyValue :: String ( "Testing empty logger scope name" . into( ) ) )
716
718
) ;
717
- assert_eq ! ( scoped_logger . instrumentation_scope ( ) . name( ) , "" ) ;
719
+ assert_eq ! ( log1 . instrumentation . name( ) , "" ) ;
718
720
}
719
721
720
722
#[ test]
Original file line number Diff line number Diff line change @@ -115,16 +115,32 @@ mod tests {
115
115
}
116
116
117
117
#[ test]
118
- #[ allow( deprecated) ]
119
118
fn logger_attributes ( ) {
120
- let provider = SdkLoggerProvider :: builder ( ) . build ( ) ;
119
+ let exporter: InMemoryLogExporter = InMemoryLogExporter :: default ( ) ;
120
+ let provider = SdkLoggerProvider :: builder ( )
121
+ . with_log_processor ( SimpleLogProcessor :: new ( exporter. clone ( ) ) )
122
+ . build ( ) ;
123
+
121
124
let scope = InstrumentationScope :: builder ( "test_logger" )
122
125
. with_schema_url ( "https://opentelemetry.io/schema/1.0.0" )
123
126
. with_attributes ( vec ! [ ( KeyValue :: new( "test_k" , "test_v" ) ) ] )
124
127
. build ( ) ;
125
128
126
129
let logger = provider. logger_with_scope ( scope) ;
127
- let instrumentation_scope = logger. instrumentation_scope ( ) ;
130
+
131
+ let mut log_record = logger. create_log_record ( ) ;
132
+ log_record. set_severity_number ( Severity :: Error ) ;
133
+
134
+ logger. emit ( log_record) ;
135
+
136
+ let mut exported_logs = exporter
137
+ . get_emitted_logs ( )
138
+ . expect ( "Logs are expected to be exported." ) ;
139
+ assert_eq ! ( exported_logs. len( ) , 1 ) ;
140
+ let log = exported_logs. remove ( 0 ) ;
141
+ assert_eq ! ( log. record. severity_number, Some ( Severity :: Error ) ) ;
142
+
143
+ let instrumentation_scope = log. instrumentation ;
128
144
assert_eq ! ( instrumentation_scope. name( ) , "test_logger" ) ;
129
145
assert_eq ! (
130
146
instrumentation_scope. schema_url( ) ,
You can’t perform that action at this time.
0 commit comments