Exemple #1
0
    def test_registered_type(self):
        from google.cloud.trace_v1.proto.trace_pb2 import (
            TraceSpan, Trace)
        from google.protobuf.timestamp_pb2 import Timestamp

        project = u'PROJECT'
        trace_id = u'test_trace_id'
        span_id = 1234
        span_name = u'test_span_name'
        start_time = '2017-06-24T00:12:50.369990Z'
        end_time = '2017-06-24T00:13:39.633255Z'
        start_seconds = 1498263170
        start_nanos = 369990000
        end_seconds = 1498263219
        end_nanos = 633255000

        start_time_pb = Timestamp(seconds=start_seconds, nanos=start_nanos)
        end_time_pb = Timestamp(seconds=end_seconds, nanos=end_nanos)

        span_pb = TraceSpan(
            span_id=span_id,
            name=span_name,
            start_time=start_time_pb,
            end_time=end_time_pb)

        trace_pb = Trace(
            project_id=project,
            trace_id=trace_id,
            spans=[span_pb])

        parse_result = self._call_fut(trace_pb)

        expected_result = {
            'projectId': project,
            'traceId': trace_id,
            'spans': [
                {
                    'spanId': str(span_id),
                    'name': span_name,
                    'startTime': start_time,
                    'endTime': end_time,
                },
            ],
        }

        self.assertEqual(parse_result, expected_result)
    def test_registered_type(self):
        from google.cloud.trace_v1.proto.trace_pb2 import TraceSpan, Trace
        from google.protobuf.timestamp_pb2 import Timestamp

        project = u"PROJECT"
        trace_id = u"test_trace_id"
        span_id = 1234
        span_name = u"test_span_name"
        start_time = "2017-06-24T00:12:50.369990Z"
        end_time = "2017-06-24T00:13:39.633255Z"
        start_seconds = 1498263170
        start_nanos = 369990000
        end_seconds = 1498263219
        end_nanos = 633255000

        start_time_pb = Timestamp(seconds=start_seconds, nanos=start_nanos)
        end_time_pb = Timestamp(seconds=end_seconds, nanos=end_nanos)

        span_pb = TraceSpan(
            span_id=span_id,
            name=span_name,
            start_time=start_time_pb,
            end_time=end_time_pb,
        )

        trace_pb = Trace(project_id=project,
                         trace_id=trace_id,
                         spans=[span_pb])

        parse_result = self._call_fut(trace_pb)

        expected_result = {
            "projectId":
            project,
            "traceId":
            trace_id,
            "spans": [{
                "spanId": str(span_id),
                "name": span_name,
                "startTime": start_time,
                "endTime": end_time,
            }],
        }

        self.assertEqual(parse_result, expected_result)
Exemple #3
0
    def test_get_trace(self):
        from google.cloud.trace_v1.gapic import trace_service_client
        from google.cloud.trace_v1.proto.trace_pb2 import Trace

        trace_id = "test_trace_id"
        trace_pb = Trace(project_id=self.project, trace_id=trace_id)

        gapic_api = mock.create_autospec(
            trace_service_client.TraceServiceClient)
        gapic_api.get_trace.return_value = trace_pb
        api = self._make_one(gapic_api, None)

        trace = api.get_trace(project_id=self.project, trace_id=trace_id)

        expected_trace = {"projectId": self.project, "traceId": trace_id}
        self.assertEqual(trace, expected_trace)

        gapic_api.get_trace.assert_called_with(self.project, trace_id)
Exemple #4
0
    def _make_trace_pb(cls):
        from google.cloud.trace_v1.proto.trace_pb2 import Trace
        from google.cloud.trace_v1.proto.trace_pb2 import TraceSpan
        from google.protobuf.timestamp_pb2 import Timestamp

        start_time_pb = Timestamp(seconds=cls.start_seconds,
                                  nanos=cls.start_nanos)
        end_time_pb = Timestamp(seconds=cls.end_seconds, nanos=cls.end_nanos)

        span_pb = TraceSpan(
            span_id=cls.span_id,
            name=cls.span_name,
            start_time=start_time_pb,
            end_time=end_time_pb,
        )

        return Trace(project_id=cls.project,
                     trace_id=cls.trace_id,
                     spans=[span_pb])