56
56
57
57
_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT = 128
58
58
_ENV_VALUE_UNSET = ""
59
- _EXCLUDED_ATTRIBUTES = {
60
- # pseudo-private log-record attributes, they should always be dropped
61
- "args" ,
62
- "msg" ,
63
- "message" ,
64
- "stack_info" ,
65
- "exc_info" ,
66
- "exc_text" ,
67
- # attributes that are retained, but with a different name
68
- # following semantic conventions
69
- "pathname" ,
70
- "funcName" ,
71
- "lineno" ,
72
- "thread" ,
73
- "threadName" ,
74
- # attributes that are omitted because no semantic convention exists for them yet
75
- "asctime" ,
76
- "created" ,
77
- "filename" ,
78
- "levelname" ,
79
- "levelno" ,
80
- "module" ,
81
- "msecs" ,
82
- "name" ,
83
- "process" ,
84
- "processName" ,
85
- "relativeCreated" ,
86
- "taskName" ,
87
- }
88
59
89
60
90
61
class LogDroppedAttributesWarning (UserWarning ):
@@ -456,6 +427,37 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
456
427
return True
457
428
458
429
430
+ # skip natural LogRecord attributes
431
+ # http://docs.python.org/library/logging.html#logrecord-attributes
432
+ _RESERVED_ATTRS = frozenset (
433
+ (
434
+ "asctime" ,
435
+ "args" ,
436
+ "created" ,
437
+ "exc_info" ,
438
+ "exc_text" ,
439
+ "filename" ,
440
+ "funcName" ,
441
+ "message" ,
442
+ "levelname" ,
443
+ "levelno" ,
444
+ "lineno" ,
445
+ "module" ,
446
+ "msecs" ,
447
+ "msg" ,
448
+ "name" ,
449
+ "pathname" ,
450
+ "process" ,
451
+ "processName" ,
452
+ "relativeCreated" ,
453
+ "stack_info" ,
454
+ "thread" ,
455
+ "threadName" ,
456
+ "taskName" ,
457
+ )
458
+ )
459
+
460
+
459
461
class LoggingHandler (logging .Handler ):
460
462
"""A handler class which writes logging records, in OTLP format, to
461
463
a network destination or file. Supports signals from the `logging` module.
@@ -476,18 +478,13 @@ def __init__(
476
478
@staticmethod
477
479
def _get_attributes (record : logging .LogRecord ) -> Attributes :
478
480
attributes = {
479
- k : v
480
- for k , v in vars (record ).items ()
481
- if k not in _EXCLUDED_ATTRIBUTES and v is not None
481
+ k : v for k , v in vars (record ).items () if k not in _RESERVED_ATTRS
482
482
}
483
483
484
484
# Add standard code attributes for logs.
485
485
attributes [SpanAttributes .CODE_FILEPATH ] = record .pathname
486
486
attributes [SpanAttributes .CODE_FUNCTION ] = record .funcName
487
487
attributes [SpanAttributes .CODE_LINENO ] = record .lineno
488
- # Add thread identifiers for logs.
489
- attributes [SpanAttributes .THREAD_ID ] = record .thread
490
- attributes [SpanAttributes .THREAD_NAME ] = record .threadName
491
488
492
489
if record .exc_info :
493
490
exctype , value , tb = record .exc_info
0 commit comments