def test_constructor_explicit(self):
        stack_frames = [mock.Mock()]
        hash_id = 1100
        stack_trace = stack_trace_module.StackTrace(stack_frames, hash_id)

        self.assertEqual(stack_trace.stack_frames, stack_frames)
        self.assertEqual(stack_trace.stack_trace_hash_id, hash_id)
示例#2
0
 def test_format_legacy_trace_json(self):
     trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
     span_data = span_data_module.SpanData(
         name='root',
         context=span_context.SpanContext(trace_id=trace_id,
                                          span_id='6e0c63257de34c92'),
         span_id='6e0c63257de34c92',
         parent_span_id='6e0c63257de34c93',
         attributes={'key1': 'value1'},
         start_time=utils.to_iso_str(),
         end_time=utils.to_iso_str(),
         stack_trace=stack_trace.StackTrace(stack_trace_hash_id='111'),
         links=[link.Link('1111', span_id='6e0c63257de34c92')],
         status=status.Status(code=0, message='pok'),
         annotations=[
             time_event.Annotation(timestamp=datetime.datetime(1970, 1, 1),
                                   description='description')
         ],
         message_events=[
             time_event.MessageEvent(
                 timestamp=datetime.datetime(1970, 1, 1),
                 id=0,
             )
         ],
         same_process_as_parent_span=False,
         child_span_count=0,
         span_kind=0,
     )
     trace_json = span_data_module.format_legacy_trace_json([span_data])
     self.assertEqual(trace_json.get('traceId'), trace_id)
     self.assertEqual(len(trace_json.get('spans')), 1)
    def test_add_stack_frame(self):
        stack_trace = stack_trace_module.StackTrace()
        stack_frame = mock.Mock()
        stack_frame_json = 'test stack frame'
        stack_frame.format_stack_frame_json.return_value = stack_frame_json
        stack_trace.add_stack_frame(stack_frame)

        self.assertEqual(stack_trace.stack_frames, [stack_frame_json])
    def test_constructor_default(self):
        hash_id = 1100
        patch = mock.patch('opencensus.trace.stack_trace.generate_hash_id',
                           return_value=hash_id)

        with patch:
            stack_trace = stack_trace_module.StackTrace()

        self.assertEqual(stack_trace.stack_frames, [])
        self.assertEqual(stack_trace.stack_trace_hash_id, hash_id)
    def test_format_stack_trace_json_without_stack_frame(self):
        hash_id = 1100

        stack_trace = stack_trace_module.StackTrace(
            stack_trace_hash_id=hash_id)

        stack_trace_json = stack_trace.format_stack_trace_json()

        expected_stack_trace_json = {'stack_trace_hash_id': hash_id}

        self.assertEqual(expected_stack_trace_json, stack_trace_json)
    def test_format_stack_trace_json_with_stack_frame(self):
        hash_id = 1100
        stack_frame = [mock.Mock()]

        stack_trace = stack_trace_module.StackTrace(
            stack_frames=stack_frame, stack_trace_hash_id=hash_id)

        stack_trace_json = stack_trace.format_stack_trace_json()

        expected_stack_trace_json = {
            'stack_frames': {
                'frame': stack_frame,
                'dropped_frames_count': 0
            },
            'stack_trace_hash_id': hash_id
        }

        self.assertEqual(expected_stack_trace_json, stack_trace_json)
 def test_constructor_max_frames(self):
     stack_frames = [mock.Mock()] * (stack_trace_module.MAX_FRAMES + 1)
     stack_trace = stack_trace_module.StackTrace(stack_frames, 100)
     self.assertEqual(stack_trace.dropped_frames_count, 1)
     self.assertEqual(len(stack_trace.stack_frames),
                      stack_trace_module.MAX_FRAMES)