Skip to content

Instantly share code, notes, and snippets.

@danhurwit
Created February 15, 2022 21:54
Show Gist options
  • Select an option

  • Save danhurwit/5a7be3509f300c06041a2b8631ae17bf to your computer and use it in GitHub Desktop.

Select an option

Save danhurwit/5a7be3509f300c06041a2b8631ae17bf to your computer and use it in GitHub Desktop.
import operator
def print_span(span):
duration = span.end_time - span.start_time
value = ' ' * span.start_time + '-' * duration
print(value)
def print_nested_spans(parent_id, spans):
children = sorted(list(filter(lambda x: x.parent_id == parent_id, spans)),
key=operator.attrgetter('start_time'))
for child in children:
print_span(child)
print_nested_spans(child.id, spans)
def print_trace(spans):
root_span_id = ''
for span in spans:
if span.parent_id is None:
root_span_id = span.id
print_span(span)
print_nested_spans(root_span_id, spans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment