File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
src/opentelemetry/sdk/_logs Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## [ Unreleased] ( https://github.com/open-telemetry/opentelemetry-python/compare/v1.11.1-0.30b1...HEAD )
99
10+ - Fix LoggingHandler to handle LogRecord with exc_info=False
11+ ([ #2690 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2690 ) )
1012- Make metrics components public
1113 ([ #2684 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/2684 ) )
1214- Update to semantic conventions v1.11.0
Original file line number Diff line number Diff line change @@ -321,7 +321,7 @@ def _get_attributes(record: logging.LogRecord) -> Attributes:
321321 attributes = {
322322 k : v for k , v in vars (record ).items () if k not in _RESERVED_ATTRS
323323 }
324- if record .exc_info is not None :
324+ if record .exc_info :
325325 exc_type = ""
326326 message = ""
327327 stack_trace = ""
Original file line number Diff line number Diff line change @@ -107,6 +107,27 @@ def test_log_record_exception(self):
107107 self .assertTrue ("division by zero" in stack_trace )
108108 self .assertTrue (__file__ in stack_trace )
109109
110+ def test_log_exc_info_false (self ):
111+ """Exception information will be included in attributes"""
112+ emitter_mock = Mock (spec = LogEmitter )
113+ logger = get_logger (log_emitter = emitter_mock )
114+ try :
115+ raise ZeroDivisionError ("division by zero" )
116+ except ZeroDivisionError :
117+ logger .error ("Zero Division Error" , exc_info = False )
118+ args , _ = emitter_mock .emit .call_args_list [0 ]
119+ log_record = args [0 ]
120+
121+ self .assertIsNotNone (log_record )
122+ self .assertEqual (log_record .body , "Zero Division Error" )
123+ self .assertNotIn (SpanAttributes .EXCEPTION_TYPE , log_record .attributes )
124+ self .assertNotIn (
125+ SpanAttributes .EXCEPTION_MESSAGE , log_record .attributes
126+ )
127+ self .assertNotIn (
128+ SpanAttributes .EXCEPTION_STACKTRACE , log_record .attributes
129+ )
130+
110131 def test_log_record_trace_correlation (self ):
111132 emitter_mock = Mock (spec = LogEmitter )
112133 logger = get_logger (log_emitter = emitter_mock )
You can’t perform that action at this time.
0 commit comments