Skip to content
This repository was archived by the owner on Oct 29, 2021. It is now read-only.

Commit 17ccc99

Browse files
author
Brandon Gonzalez
committed
Checkpoint
1 parent ffef430 commit 17ccc99

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎python/appdash/event.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ def __init__(self, msg):
6363
def marshal(self):
6464
return {"Msg": self.msg, "Time": self.time}
6565

66+
class TimespanEvent:
67+
68+
schema = "Timespan"
69+
start = ""
70+
end = ""
71+
72+
def __init__(self, start, end):
73+
self.start = timeString(start)
74+
self.end = timeString(end)
75+
76+
def marshal(self)
77+
return {"Span.Start": self.start, "Span.End": self.end}
78+
6679
# SQLEvent is an SQL query event with send and receive times, as well as the
6780
# actual SQL that was ran, and a optional tag.
6881
class SQLEvent:
@@ -71,7 +84,7 @@ class SQLEvent:
7184
# sql is literally the SQL query that was ran.
7285
sql = ""
7386

74-
# tag is a optional user-created tag associated with the SQL event.
87+
# tag is a optional user-created tag associated with the SQL event.
7588
tag = ""
7689

7790
# RFC3339-UTC timestamp of when the query was sent, and later a result received.

‎python/appdash/recorder.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from spanid import SpanID, Annotation
2+
3+
class AppdashRecorder(object):
4+
def __init__(self, collector):
5+
self._collector = collector
6+
7+
def record_span(self, span):
8+
if not span.context.sampled:
9+
return
10+
annotations = []
11+
span_id = SpanID()
12+
span_id.trace = span.context.trace_id
13+
span_id.span = span.context.span
14+
span_id.parent = span.context.parent_span_id
15+
16+
# It might not be right to build a list, maybe send events one at a time.
17+
annotations.append(MarshalEvent(SpanNameEvent(span.operation_name)))
18+
19+
approx_endtime = span.context.start_time + span.duration
20+
annotations.append(MarshalEvent(
21+
TimespanEvent(span.context.start_time, approx_endtime)))
22+
23+
for key in span.tags:
24+
annotations.append(Annotation(key, span.tag[key])
25+
26+
for key in span.context.baggage_items:
27+
annotations.append(Annotation(key, span.contex.baggage_items[value])
28+
29+
self._collector.collect(span_id, events)
30+
31+
32+
class AppdashTracer(BasicTracer):
33+
34+
def __init__(self, collector, sampler=None):
35+
self._recorder = AppdashRecorder(collector)
36+
super(AppdashTracer, self).__init__(recorder=self._recorder,
37+
sampler=sampler)

‎python/setup.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
author_email = 'hi@sourcegraph.com',
1111
url = 'https://sourcegraph.com/sourcegraph/appdash',
1212
packages = ['appdash'],
13+
install_requires = ['basictracer'],
1314
)

0 commit comments

Comments
 (0)