@@ -89,10 +89,6 @@ def __init__(
8989 def export (self , spans : Sequence [ReadableSpan ]) -> SpanExportResult :
9090 """Export the spans to the console."""
9191 for span in spans :
92- if span .attributes : # pragma: no branch
93- log_level : int = span .attributes .get (ATTRIBUTES_LOG_LEVEL_NUM_KEY , _INFO_LEVEL ) # type: ignore
94- if log_level < self ._min_log_level_num :
95- continue
9692 self ._log_span (span )
9793
9894 return SpanExportResult .SUCCESS
@@ -102,18 +98,21 @@ def _log_span(self, span: ReadableSpan) -> None:
10298
10399 In this simple case we just print the span if its type is not "span" - e.g. the message at the end of a span.
104100 """
105- if span .attributes : # pragma: no branch
106- span_type = span .attributes .get (ATTRIBUTES_SPAN_TYPE_KEY , 'span' )
107- # only print for "pending_span" (received at the start of a span) and "log" (spans with no duration)
108- if span_type == 'span' or span .attributes .get (DISABLE_CONSOLE_KEY ):
109- return
110-
111101 self ._print_span (span )
112102
113103 def _print_span (self , span : ReadableSpan , indent : int = 0 ):
114104 """Build up a summary of the span, including formatting for rich, then print it."""
115105 _msg , parts = self ._span_text_parts (span , indent )
116106
107+ if span .attributes : # pragma: no branch
108+ span_type = span .attributes .get (ATTRIBUTES_SPAN_TYPE_KEY , 'span' )
109+ # only print for "pending_span" (received at the start of a span) and "log" (spans with no duration)
110+ if span_type == 'span' or span .attributes .get (DISABLE_CONSOLE_KEY ):
111+ return
112+ log_level : int = span .attributes .get (ATTRIBUTES_LOG_LEVEL_NUM_KEY , _INFO_LEVEL ) # type: ignore
113+ if log_level < self ._min_log_level_num :
114+ return
115+
117116 indent_str = (self ._timestamp_indent + indent * 2 ) * ' '
118117 details_parts = self ._details_parts (span , indent_str )
119118 if details_parts :
@@ -318,9 +317,6 @@ def _log_span(self, span: ReadableSpan) -> None:
318317 self ._indent_level .pop (span .context .span_id , None )
319318 return
320319
321- if attributes .get (DISABLE_CONSOLE_KEY ): # pragma: no cover
322- return
323-
324320 if span_type == 'pending_span' :
325321 parent_id = _pending_span_parent (attributes )
326322 indent = self ._indent_level .get (parent_id , 0 ) if parent_id else 0
@@ -372,9 +368,6 @@ def _log_span(self, span: ReadableSpan) -> None:
372368 self ._span_stack .pop ()
373369 return
374370
375- if attributes .get (DISABLE_CONSOLE_KEY ): # pragma: no cover
376- return
377-
378371 self ._print_span (span )
379372
380373 def _span_text_parts (self , span : ReadableSpan , indent : int ) -> tuple [str , TextParts ]:
0 commit comments