@@ -76,12 +76,16 @@ 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 (
80+ child : Tree , span : ReadableSpan , * , suppress_resource : bool
81+ ):
8082 child .add (
8183 Text .from_markup (f"[bold cyan]Kind :[/bold cyan] { span .kind .name } " )
8284 )
8385 _add_status (child , span )
84- _child_add_optional_attributes (child , span )
86+ _child_add_optional_attributes (
87+ child , span , suppress_resource = suppress_resource
88+ )
8589
8690
8791def _add_status (child : Tree , span : ReadableSpan ):
@@ -106,7 +110,9 @@ def _add_status(child: Tree, span: ReadableSpan):
106110 )
107111
108112
109- def _child_add_optional_attributes (child : Tree , span : ReadableSpan ):
113+ def _child_add_optional_attributes (
114+ child : Tree , span : ReadableSpan , * , suppress_resource : bool
115+ ):
110116 if span .events :
111117 events = child .add (
112118 label = Text .from_markup ("[bold cyan]Events :[/bold cyan] " )
@@ -133,7 +139,7 @@ def _child_add_optional_attributes(child: Tree, span: ReadableSpan):
133139 f"[bold cyan]{ attribute } :[/bold cyan] { span .attributes [attribute ]} "
134140 )
135141 )
136- if span .resource :
142+ if span .resource and not suppress_resource :
137143 resources = child .add (
138144 label = Text .from_markup ("[bold cyan]Resources :[/bold cyan] " )
139145 )
@@ -155,21 +161,29 @@ class RichConsoleSpanExporter(SpanExporter):
155161 def __init__ (
156162 self ,
157163 service_name : Optional [str ] = None ,
164+ suppress_resource : bool = False ,
158165 ):
159166 self .service_name = service_name
167+ self .suppress_resource = suppress_resource
160168 self .console = Console ()
161169
162170 def export (self , spans : typing .Sequence [ReadableSpan ]) -> SpanExportResult :
163171 if not spans :
164172 return SpanExportResult .SUCCESS
165173
166- for tree in self .spans_to_tree (spans ).values ():
174+ for tree in self .spans_to_tree (
175+ spans , suppress_resource = self .suppress_resource
176+ ).values ():
167177 self .console .print (tree )
168178
169179 return SpanExportResult .SUCCESS
170180
171181 @staticmethod
172- def spans_to_tree (spans : typing .Sequence [ReadableSpan ]) -> Dict [str , Tree ]:
182+ def spans_to_tree (
183+ spans : typing .Sequence [ReadableSpan ],
184+ * ,
185+ suppress_resource : bool = False ,
186+ ) -> Dict [str , Tree ]:
173187 trees = {}
174188 parents = {}
175189 spans = list (spans )
@@ -189,7 +203,9 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
189203 )
190204 )
191205 parents [span .context .span_id ] = child
192- _child_to_tree (child , span )
206+ _child_to_tree (
207+ child , span , suppress_resource = suppress_resource
208+ )
193209 spans .remove (span )
194210 elif span .parent and span .parent .span_id in parents :
195211 child = parents [span .parent .span_id ].add (
@@ -198,6 +214,8 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
198214 )
199215 )
200216 parents [span .context .span_id ] = child
201- _child_to_tree (child , span )
217+ _child_to_tree (
218+ child , span , suppress_resource = suppress_resource
219+ )
202220 spans .remove (span )
203221 return trees
0 commit comments