forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraceviewer.py
More file actions
61 lines (49 loc) · 1.59 KB
/
traceviewer.py
File metadata and controls
61 lines (49 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import sys
print("digraph mytrace {")
print("rankdir=LR")
all_spans = []
for line in sys.stdin:
event = json.loads(line)
if event.get("type") != "transaction":
continue
trace_ctx = event["contexts"]["trace"]
trace_span = dict(trace_ctx) # fake a span entry from transaction event
trace_span["description"] = event["transaction"]
trace_span["start_timestamp"] = event["start_timestamp"]
trace_span["timestamp"] = event["timestamp"]
if "parent_span_id" not in trace_ctx:
print(
'{} [label="trace:{} ({})"];'.format(
int(trace_ctx["trace_id"], 16),
event["transaction"],
trace_ctx["trace_id"],
)
)
for span in event["spans"] + [trace_span]:
print(
'{} [label="span:{} ({})"];'.format(
int(span["span_id"], 16), span["description"], span["span_id"]
)
)
if "parent_span_id" in span:
print(
"{} -> {};".format(
int(span["parent_span_id"], 16), int(span["span_id"], 16)
)
)
print(
"{} -> {} [style=dotted];".format(
int(span["trace_id"], 16), int(span["span_id"], 16)
)
)
all_spans.append(span)
for s1 in all_spans:
for s2 in all_spans:
if s1["start_timestamp"] > s2["timestamp"]:
print(
'{} -> {} [color="#efefef"];'.format(
int(s1["span_id"], 16), int(s2["span_id"], 16)
)
)
print("}")