File: trivial_client.py

package info (click to toggle)
golang-github-grpc-ecosystem-grpc-opentracing 0.0~git20180507.8e809c8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates, bullseye
  • size: 576 kB
  • sloc: python: 2,021; java: 1,077; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download | duplicates (2)
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
from __future__ import print_function

import time
import argparse

import grpc
from jaeger_client import Config

from grpc_opentracing import open_tracing_client_interceptor
from grpc_opentracing.grpcext import intercept_channel

import command_line_pb2


def run():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--log_payloads',
        action='store_true',
        help='log request/response objects to open-tracing spans')
    args = parser.parse_args()

    config = Config(
        config={
            'sampler': {
                'type': 'const',
                'param': 1,
            },
            'logging': True,
        },
        service_name='trivial-client')
    tracer = config.initialize_tracer()
    tracer_interceptor = open_tracing_client_interceptor(
        tracer, log_payloads=args.log_payloads)
    channel = grpc.insecure_channel('localhost:50051')
    channel = intercept_channel(channel, tracer_interceptor)
    stub = command_line_pb2.CommandLineStub(channel)
    response = stub.Echo(command_line_pb2.CommandRequest(text='Hello, hello'))
    print(response.text)

    time.sleep(2)
    tracer.close()
    time.sleep(2)


if __name__ == '__main__':
    run()