Пример #1
0
    def __init__(self,
                 service_name,
                 host_name=None,
                 endpoint=None,
                 client=None,
                 transport=sync.SyncTransport):
        self.transport = transport(self)
        self.endpoint = DEFAULT_ENDPOINT if endpoint is None else endpoint

        if client is None:
            self.channel = grpc.insecure_channel(self.endpoint)
            self.client = trace_service_pb2_grpc.TraceServiceStub(
                channel=self.channel)
        else:
            self.client = client

        self.service_name = service_name
        self.node = common_pb2.Node(
            identifier=common_pb2.ProcessIdentifier(
                host_name=socket.gethostname()
                if host_name is None else host_name,
                pid=os.getpid(),
                start_timestamp=utils.proto_ts_from_datetime(
                    datetime.datetime.utcnow())),
            library_info=common_pb2.LibraryInfo(
                language=common_pb2.LibraryInfo.Language.Value('PYTHON'),
                exporter_version=EXPORTER_VERSION,
                core_library_version=__version__),
            service_info=common_pb2.ServiceInfo(name=self.service_name))
Пример #2
0
    def test_datetime_to_proto_ts_conversion(self):
        now = datetime.utcnow()
        delta = now - datetime(1970, 1, 1)
        expected_seconds = int(delta.total_seconds())
        expected_nanos = delta.microseconds * 1000

        proto_ts = utils.proto_ts_from_datetime(now)
        self.assertEqual(proto_ts.seconds, int(expected_seconds))
        self.assertEqual(proto_ts.nanos, expected_nanos)
Пример #3
0
    def test_datetime_to_proto_ts_conversion_zero(self):
        zero = datetime(1970, 1, 1)

        proto_ts = utils.proto_ts_from_datetime(zero)
        self.assertEqual(proto_ts.seconds, 0)
        self.assertEqual(proto_ts.nanos, 0)
Пример #4
0
 def test_datetime_to_proto_ts_conversion_none(self):
     proto_ts = utils.proto_ts_from_datetime(None)
     self.assertEquals(proto_ts.seconds, 0)
     self.assertEquals(proto_ts.nanos, 0)