6262 "exc_info" ,
6363 "exc_text" ,
6464}
65+ _SEMANTIC_CONVENTION_ATTRS = {
66+ "pathname" ,
67+ "funcName" ,
68+ "lineno" ,
69+ "thread" ,
70+ "threadName" ,
71+ }
6572
6673
6774class LogLimits :
@@ -416,26 +423,21 @@ class LoggingHandler(logging.Handler):
416423 https://docs.python.org/3/library/logging.html
417424 """
418425
419- def __init__ (
420- self ,
421- level = logging .NOTSET ,
422- logger_provider = None ,
423- exclude_attributes = None ,
424- ) -> None :
426+ def __init__ (self , level = logging .NOTSET , logger_provider = None ) -> None :
425427 super ().__init__ (level = level )
426428 self ._logger_provider = logger_provider or get_logger_provider ()
427429 self ._logger = get_logger (
428430 __name__ , logger_provider = self ._logger_provider
429431 )
430- if exclude_attributes is None :
431- exclude_attributes = set ()
432- self . exclude_attributes = _PRIVATE_RECORD_ATTRS | exclude_attributes
432+ self . _exclude_attributes = (
433+ _PRIVATE_RECORD_ATTRS | _SEMANTIC_CONVENTION_ATTRS
434+ )
433435
434436 def _get_attributes (self , record : logging .LogRecord ) -> Attributes :
435437 attributes = {
436438 k : v
437439 for k , v in vars (record ).items ()
438- if k not in self .exclude_attributes
440+ if k not in self ._exclude_attributes
439441 }
440442 if record .exc_info :
441443 exc_type = ""
@@ -454,6 +456,13 @@ def _get_attributes(self, record: logging.LogRecord) -> Attributes:
454456 attributes [SpanAttributes .EXCEPTION_TYPE ] = exc_type
455457 attributes [SpanAttributes .EXCEPTION_MESSAGE ] = message
456458 attributes [SpanAttributes .EXCEPTION_STACKTRACE ] = stack_trace
459+
460+ # adding these attributes with their semantic convention names
461+ attributes [SpanAttributes .CODE_FILEPATH ] = record .pathname
462+ attributes [SpanAttributes .CODE_FUNCTION ] = record .funcName
463+ attributes [SpanAttributes .CODE_LINENO ] = record .lineno
464+ attributes [SpanAttributes .THREAD_ID ] = record .thread
465+ attributes [SpanAttributes .THREAD_NAME ] = record .threadName
457466 return attributes
458467
459468 def _translate (self , record : logging .LogRecord ) -> LogRecord :
0 commit comments