File tree Expand file tree Collapse file tree 3 files changed +26
-13
lines changed
opentelemetry-sdk/src/logs Expand file tree Collapse file tree 3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,6 @@ impl SdkLogger {
1818 pub ( crate ) fn new ( scope : InstrumentationScope , provider : SdkLoggerProvider ) -> Self {
1919 SdkLogger { scope, provider }
2020 }
21-
22- #[ cfg( test) ]
23- pub ( crate ) fn instrumentation_scope ( & self ) -> & InstrumentationScope {
24- & self . scope
25- }
2621}
2722
2823impl opentelemetry:: logs:: Logger for SdkLogger {
Original file line number Diff line number Diff line change @@ -700,21 +700,23 @@ mod tests {
700700 scoped_logger. emit ( scoped_record) ;
701701
702702 // 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 ( ) ;
704704 assert_eq ! ( emitted_logs. len( ) , 2 ) ;
705+ let log1 = emitted_logs. remove ( 0 ) ;
705706 // Assert the first log
706707 assert_eq ! (
707- emitted_logs [ 0 ] . clone ( ) . record. body,
708+ log1 . record. body,
708709 Some ( AnyValue :: String ( "Testing empty logger name" . into( ) ) )
709710 ) ;
710- assert_eq ! ( logger . instrumentation_scope ( ) . name( ) , "" ) ;
711+ assert_eq ! ( log1 . instrumentation . name( ) , "" ) ;
711712
712713 // Assert the second log created through the scope
714+ let log2 = emitted_logs. remove ( 0 ) ;
713715 assert_eq ! (
714- emitted_logs [ 1 ] . clone ( ) . record. body,
716+ log2 . record. body,
715717 Some ( AnyValue :: String ( "Testing empty logger scope name" . into( ) ) )
716718 ) ;
717- assert_eq ! ( scoped_logger . instrumentation_scope ( ) . name( ) , "" ) ;
719+ assert_eq ! ( log1 . instrumentation . name( ) , "" ) ;
718720 }
719721
720722 #[ test]
Original file line number Diff line number Diff line change @@ -115,16 +115,32 @@ mod tests {
115115 }
116116
117117 #[ test]
118- #[ allow( deprecated) ]
119118 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+
121124 let scope = InstrumentationScope :: builder ( "test_logger" )
122125 . with_schema_url ( "https://opentelemetry.io/schema/1.0.0" )
123126 . with_attributes ( vec ! [ ( KeyValue :: new( "test_k" , "test_v" ) ) ] )
124127 . build ( ) ;
125128
126129 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 ;
128144 assert_eq ! ( instrumentation_scope. name( ) , "test_logger" ) ;
129145 assert_eq ! (
130146 instrumentation_scope. schema_url( ) ,
You can’t perform that action at this time.
0 commit comments