Skip to content

Commit b9f0de9

Browse files
committed
fix: remove attribute extension to keep this PR on the enabling of formatting only
1 parent cbc0920 commit b9f0de9

File tree

1 file changed

+32
-35
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal

1 file changed

+32
-35
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py

+32-35
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,6 @@
5656

5757
_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT = 128
5858
_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-
}
8859

8960

9061
class LogDroppedAttributesWarning(UserWarning):
@@ -456,6 +427,37 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
456427
return True
457428

458429

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+
459461
class LoggingHandler(logging.Handler):
460462
"""A handler class which writes logging records, in OTLP format, to
461463
a network destination or file. Supports signals from the `logging` module.
@@ -476,18 +478,13 @@ def __init__(
476478
@staticmethod
477479
def _get_attributes(record: logging.LogRecord) -> Attributes:
478480
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
482482
}
483483

484484
# Add standard code attributes for logs.
485485
attributes[SpanAttributes.CODE_FILEPATH] = record.pathname
486486
attributes[SpanAttributes.CODE_FUNCTION] = record.funcName
487487
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
491488

492489
if record.exc_info:
493490
exctype, value, tb = record.exc_info

0 commit comments

Comments
 (0)