@@ -76,12 +76,12 @@ def _ns_to_time(nanoseconds):
7676 return ts .strftime ("%H:%M:%S.%f" )
7777
7878
79- def _child_to_tree (child : Tree , span : ReadableSpan ):
79+ def _child_to_tree (child : Tree , span : ReadableSpan , * , suppress_resource : bool ):
8080 child .add (
8181 Text .from_markup (f"[bold cyan]Kind :[/bold cyan] { span .kind .name } " )
8282 )
8383 _add_status (child , span )
84- _child_add_optional_attributes (child , span )
84+ _child_add_optional_attributes (child , span , suppress_resource = suppress_resource )
8585
8686
8787def _add_status (child : Tree , span : ReadableSpan ):
@@ -106,7 +106,7 @@ def _add_status(child: Tree, span: ReadableSpan):
106106 )
107107
108108
109- def _child_add_optional_attributes (child : Tree , span : ReadableSpan ):
109+ def _child_add_optional_attributes (child : Tree , span : ReadableSpan , * , suppress_resource : bool ):
110110 if span .events :
111111 events = child .add (
112112 label = Text .from_markup ("[bold cyan]Events :[/bold cyan] " )
@@ -133,7 +133,7 @@ def _child_add_optional_attributes(child: Tree, span: ReadableSpan):
133133 f"[bold cyan]{ attribute } :[/bold cyan] { span .attributes [attribute ]} "
134134 )
135135 )
136- if span .resource :
136+ if span .resource and not suppress_resource :
137137 resources = child .add (
138138 label = Text .from_markup ("[bold cyan]Resources :[/bold cyan] " )
139139 )
@@ -155,21 +155,23 @@ class RichConsoleSpanExporter(SpanExporter):
155155 def __init__ (
156156 self ,
157157 service_name : Optional [str ] = None ,
158+ suppress_resource : bool = False ,
158159 ):
159160 self .service_name = service_name
161+ self .suppress_resource = suppress_resource
160162 self .console = Console ()
161163
162164 def export (self , spans : typing .Sequence [ReadableSpan ]) -> SpanExportResult :
163165 if not spans :
164166 return SpanExportResult .SUCCESS
165167
166- for tree in self .spans_to_tree (spans ).values ():
168+ for tree in self .spans_to_tree (spans , suppress_resource = self . suppress_resource ).values ():
167169 self .console .print (tree )
168170
169171 return SpanExportResult .SUCCESS
170172
171173 @staticmethod
172- def spans_to_tree (spans : typing .Sequence [ReadableSpan ]) -> Dict [str , Tree ]:
174+ def spans_to_tree (spans : typing .Sequence [ReadableSpan ], * , suppress_resource : bool = False ) -> Dict [str , Tree ]:
173175 trees = {}
174176 parents = {}
175177 spans = list (spans )
@@ -186,7 +188,7 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
186188 )
187189 )
188190 parents [span .context .span_id ] = child
189- _child_to_tree (child , span )
191+ _child_to_tree (child , span , suppress_resource = suppress_resource )
190192 spans .remove (span )
191193 elif span .parent and span .parent .span_id in parents :
192194 child = parents [span .parent .span_id ].add (
@@ -195,6 +197,6 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
195197 )
196198 )
197199 parents [span .context .span_id ] = child
198- _child_to_tree (child , span )
200+ _child_to_tree (child , span , suppress_resource = suppress_resource )
199201 spans .remove (span )
200202 return trees
0 commit comments