-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathconformance_client.py
36 lines (26 loc) · 1.06 KB
/
conformance_client.py
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
import json
import sys
import base64
import lightstep.tracer
from lightstep.propagation import LightStepFormat
from opentracing import Format
def main():
tracer = lightstep.Tracer(periodic_flush_seconds=0, collector_host='localhost')
body = json.load(sys.stdin)
text_context = extract_http_headers(body, tracer)
text_carrier = {}
tracer.inject(text_context, Format.TEXT_MAP, text_carrier)
binary_context = extract_binary(body, tracer)
binary_carrier = bytearray()
tracer.inject(binary_context, LightStepFormat.LIGHTSTEP_BINARY, binary_carrier)
json.dump({"text_map": text_carrier, "binary": base64.b64encode(binary_carrier)}, sys.stdout)
def extract_http_headers(body, tracer):
span_context = tracer.extract(Format.TEXT_MAP, body['text_map'])
return span_context
def extract_binary(body, tracer):
bin64 = bytearray(base64.b64decode(body['binary']))
span_context = tracer.extract(LightStepFormat.LIGHTSTEP_BINARY, bin64)
return span_context
if __name__ == "__main__":
# execute only if run as a script
main()