def test_create_span_explicit(self): from google.cloud._helpers import _datetime_to_pb_timestamp from google.cloud.trace._gapic import ( _dict_mapping_to_pb, _span_attrs_to_pb, _status_mapping_to_pb, _value_to_pb, ) from google.cloud.trace_v2.gapic import trace_service_client gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) api.create_span( name=self.span_name, span_id=self.span_id, display_name=_str_to_truncatablestr(self.display_name), start_time=self.start_time, end_time=self.end_time, parent_span_id=self.parent_span_id, attributes=self.attributes, stack_trace=self.stack_trace, time_events=self.time_events, links=self.links, status=self.status, same_process_as_parent_span=self.same_process_as_parent_span, child_span_count=self.child_span_count, ) display_name_pb = _dict_mapping_to_pb( _str_to_truncatablestr(self.display_name), "TruncatableString" ) start_time_pb = _datetime_to_pb_timestamp(self.start_time) end_time_pb = _datetime_to_pb_timestamp(self.end_time) attributes_pb = _span_attrs_to_pb(self.attributes, "Attributes") stack_trace_pb = _dict_mapping_to_pb(self.stack_trace, "StackTrace") time_events_pb = _span_attrs_to_pb(self.time_events, "TimeEvents") links_pb = _span_attrs_to_pb(self.links, "Links") status_pb = _status_mapping_to_pb(self.status) same_process_as_parent_span_pb = _value_to_pb( self.same_process_as_parent_span, "BoolValue" ) child_span_count_pb = _value_to_pb(self.child_span_count, "Int32Value") gapic_api.create_span.assert_called_with( name=self.span_name, span_id=self.span_id, display_name=display_name_pb, start_time=start_time_pb, end_time=end_time_pb, parent_span_id=self.parent_span_id, attributes=attributes_pb, stack_trace=stack_trace_pb, time_events=time_events_pb, links=links_pb, status=status_pb, same_process_as_parent_span=same_process_as_parent_span_pb, child_span_count=child_span_count_pb, )
def test_create_span_explicit(self): from google.cloud._helpers import _datetime_to_pb_timestamp from google.cloud.trace._gapic import ( _dict_mapping_to_pb, _span_attrs_to_pb, _status_mapping_to_pb, _value_to_pb, ) from google.cloud.trace_v2.gapic import trace_service_client gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) api.create_span( name=self.span_name, span_id=self.span_id, display_name=_str_to_truncatablestr(self.display_name), start_time=self.start_time, end_time=self.end_time, parent_span_id=self.parent_span_id, attributes=self.attributes, stack_trace=self.stack_trace, time_events=self.time_events, links=self.links, status=self.status, same_process_as_parent_span=self.same_process_as_parent_span, child_span_count=self.child_span_count, ) display_name_pb = _dict_mapping_to_pb( _str_to_truncatablestr(self.display_name), "TruncatableString" ) start_time_pb = _datetime_to_pb_timestamp(self.start_time) end_time_pb = _datetime_to_pb_timestamp(self.end_time) attributes_pb = _span_attrs_to_pb(self.attributes, "Attributes") stack_trace_pb = _dict_mapping_to_pb(self.stack_trace, "StackTrace") time_events_pb = _span_attrs_to_pb(self.time_events, "TimeEvents") links_pb = _span_attrs_to_pb(self.links, "Links") status_pb = _status_mapping_to_pb(self.status) same_process_as_parent_span_pb = _value_to_pb( self.same_process_as_parent_span, "BoolValue" ) child_span_count_pb = _value_to_pb(self.child_span_count, "Int32Value") gapic_api.create_span.assert_called_with( name=self.span_name, span_id=self.span_id, display_name=display_name_pb, start_time=start_time_pb, end_time=end_time_pb, parent_span_id=self.parent_span_id, attributes=attributes_pb, stack_trace=stack_trace_pb, time_events=time_events_pb, links=links_pb, status=status_pb, same_process_as_parent_span=same_process_as_parent_span_pb, child_span_count=child_span_count_pb, )
def test_create_span_default(self): from google.cloud.trace_v2.gapic import trace_service_client from google.cloud.trace._gapic import _dict_mapping_to_pb from google.cloud._helpers import _datetime_to_pb_timestamp gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) api.create_span( name=self.span_name, span_id=self.span_id, display_name=_str_to_truncatablestr(self.display_name), start_time=self.start_time, end_time=self.end_time) display_name_pb = _dict_mapping_to_pb( _str_to_truncatablestr(self.display_name), 'TruncatableString') start_time_pb = _datetime_to_pb_timestamp(self.start_time) end_time_pb = _datetime_to_pb_timestamp(self.end_time) gapic_api.create_span.assert_called_with( name=self.span_name, span_id=self.span_id, display_name=display_name_pb, start_time=start_time_pb, end_time=end_time_pb, parent_span_id=None, attributes=None, stack_trace=None, time_events=None, links=None, status=None, same_process_as_parent_span=None, child_span_count=None)
def test_batch_write_spans(self): from google.cloud.trace_v2.gapic import trace_service_client from google.cloud.trace_v2.proto.trace_pb2 import Span from google.cloud.trace._gapic import _dict_mapping_to_pb spans = { 'spans': [ { 'name': self.span_name, 'span_id': self.span_id, 'parent_span_id': self.parent_span_id, 'display_name': _str_to_truncatablestr(self.display_name), 'start_time': self.start_time.isoformat() + 'Z', 'end_time': self.end_time.isoformat() + 'Z', 'attributes': self.attributes, 'stack_trace': self.stack_trace, 'time_events': self.time_events, 'links': self.links, 'status': self.status, 'same_process_as_parent_span': self.same_process_as_parent_span, 'child_span_count': self.child_span_count, }, ], } spans_pb_list = [_dict_mapping_to_pb(spans['spans'][0], 'Span')] project_name = 'projects/{}'.format(self.project) gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) retry = mock.Mock() timeout = mock.Mock() api.batch_write_spans(project_name, spans, retry, timeout) gapic_api.batch_write_spans.assert_called_with( name=project_name, spans=spans_pb_list, retry=retry, timeout=timeout)
def test_batch_write_spans(self): from google.cloud.trace_v2.gapic import trace_service_client from google.cloud.trace._gapic import _dict_mapping_to_pb spans = { 'spans': [ { 'name': self.span_name, 'span_id': self.span_id, 'parent_span_id': self.parent_span_id, 'display_name': _str_to_truncatablestr(self.display_name), 'start_time': self.start_time.isoformat() + 'Z', 'end_time': self.end_time.isoformat() + 'Z', 'attributes': self.attributes, 'stack_trace': self.stack_trace, 'time_events': self.time_events, 'links': self.links, 'status': self.status, 'same_process_as_parent_span': self.same_process_as_parent_span, 'child_span_count': self.child_span_count, }, ], } spans_pb_list = [_dict_mapping_to_pb(spans['spans'][0], 'Span')] project_name = 'projects/{}'.format(self.project) gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) retry = mock.Mock() timeout = mock.Mock() api.batch_write_spans(project_name, spans, retry, timeout) gapic_api.batch_write_spans.assert_called_with( name=project_name, spans=spans_pb_list, retry=retry, timeout=timeout)
def test_batch_write_spans(self): from google.cloud.trace_v2.gapic import trace_service_client from google.cloud.trace._gapic import _dict_mapping_to_pb spans = { "spans": [ { "name": self.span_name, "span_id": self.span_id, "parent_span_id": self.parent_span_id, "display_name": _str_to_truncatablestr(self.display_name), "start_time": self.start_time.isoformat() + "Z", "end_time": self.end_time.isoformat() + "Z", "attributes": self.attributes, "stack_trace": self.stack_trace, "time_events": self.time_events, "links": self.links, "status": self.status, "same_process_as_parent_span": self.same_process_as_parent_span, "child_span_count": self.child_span_count, } ] } spans_pb_list = [_dict_mapping_to_pb(spans["spans"][0], "Span")] project_name = "projects/{}".format(self.project) gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) retry = mock.Mock() timeout = mock.Mock() api.batch_write_spans(project_name, spans, retry, timeout) gapic_api.batch_write_spans.assert_called_with( name=project_name, spans=spans_pb_list, retry=retry, timeout=timeout )
def test_batch_write_spans(self): from google.cloud.trace_v2.gapic import trace_service_client from google.cloud.trace._gapic import _dict_mapping_to_pb spans = { "spans": [{ "name": self.span_name, "span_id": self.span_id, "parent_span_id": self.parent_span_id, "display_name": _str_to_truncatablestr(self.display_name), "start_time": self.start_time.isoformat() + "Z", "end_time": self.end_time.isoformat() + "Z", "attributes": self.attributes, "stack_trace": self.stack_trace, "time_events": self.time_events, "links": self.links, "status": self.status, "same_process_as_parent_span": self.same_process_as_parent_span, "child_span_count": self.child_span_count, }] } spans_pb_list = [_dict_mapping_to_pb(spans["spans"][0], "Span")] project_name = "projects/{}".format(self.project) gapic_api = mock.Mock(spec=trace_service_client.TraceServiceClient) api = self._make_one(gapic_api, None) retry = mock.Mock() timeout = mock.Mock() api.batch_write_spans(project_name, spans, retry, timeout) gapic_api.batch_write_spans.assert_called_with(name=project_name, spans=spans_pb_list, retry=retry, timeout=timeout)