diff --git a/Makefile b/Makefile index 7314596..d49545c 100644 --- a/Makefile +++ b/Makefile @@ -82,3 +82,6 @@ proto: protoc --proto_path "$(PWD)/../googleapis:$(PWD)/../lightstep-tracer-common/" \ --python_out="$(PWD)/lightstep" \ collector.proto + +conformance: build cloudbuild.yaml + gcloud builds submit --config cloudbuild.yaml . diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 0000000..5f842b7 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,9 @@ +steps: + - name: 'gcr.io/cloud-builders/git' + args: ['clone', 'https://github.com/lightstep/conformance.git'] + - name: 'gcr.io/cloud-builders/go:debian' + args: ['install', 'github.com/lightstep/conformance/ls_conformance_runner'] + env: ['PROJECT_ROOT=github.com/lightstep'] + - name: 'python:2' + entrypoint: 'sh' + args: ['-c', 'pip install -r requirements.txt && gopath/bin/ls_conformance_runner python tests/conformance/conformance_client.py'] diff --git a/tests/conformance/__init__.py b/tests/conformance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conformance/conformance_client.py b/tests/conformance/conformance_client.py new file mode 100644 index 0000000..232ed95 --- /dev/null +++ b/tests/conformance/conformance_client.py @@ -0,0 +1,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()