예제 #1
0
    def test_setters(self):
        span = Span.new(self.trace, Span.new_span_id())
        self.assertEqual(span.name, '')

        new_name = '1324'
        span.name = new_name
        self.assertEqual(span.name, new_name)

        new_span_kind = SpanKind.client
        span.span_kind = new_span_kind
        self.assertEqual(span.span_kind, new_span_kind)

        new_span_kind = SpanKind.client.value
        span.span_kind = new_span_kind
        self.assertEqual(span.span_kind, SpanKind.client)

        self.assertIsNone(span.parent_span_id)
        new_span = Span.new(self.trace, Span.new_span_id())
        span.parent_span_id = new_span.span_id
        self.assertIs(span.parent_span_id, new_span.span_id)

        self.assertIsNone(span.start_time)
        self.assertIsNone(span.end_time)

        start_time = datetime.datetime.utcnow()
        span.start_time = start_time
        self.assertEqual(span.start_time, start_time)

        end_time = datetime.datetime.utcnow()
        span.end_time = end_time
        self.assertEqual(span.end_time, end_time)
예제 #2
0
    def test_lshift_span(self):
        span_id = Span.new_span_id()
        span_a = Span.new(self.trace, span_id)

        new_span_id = Span.new_span_id()
        span_b = Span.new(self.trace, new_span_id)

        operator.lshift(span_b, span_a)
        self.assertIs(span_a.parent_span, span_b)
예제 #3
0
    def test_rshift_span(self):
        span_id = Span.new_span_id()
        span_a = Span.new(self.trace, span_id)

        new_span_id = Span.new_span_id()
        span_b = Span.new(self.trace, new_span_id)

        operator.rshift(span_a, span_b)
        self.assertIs(span_a.parent_span_id, span_b.span_id)
예제 #4
0
    def test_add_span(self):
        span_id = Span.new_span_id()
        parent_span = Span.new(self.trace, span_id)

        new_span_id = Span.new_span_id()
        span = Span.new(self.trace, new_span_id)

        operator.add(parent_span, span)
        self.assertIs(span.parent_span_id, span_id)
예제 #5
0
    def test_iadd_span(self):
        span_id = Span.new_span_id()
        parent_span = Span.new(self.trace, span_id)

        new_span_id = Span.new_span_id()
        span = Span.new(self.trace, new_span_id)

        result = operator.iadd(parent_span, span)
        self.assertIs(span.parent_span_id, span_id)
        self.assertIsInstance(result, Span)
예제 #6
0
    def test_ilshift_span(self):
        span_id = Span.new_span_id()
        span_a = Span.new(self.trace, span_id)

        new_span_id = Span.new_span_id()
        span_b = Span.new(self.trace, new_span_id)

        result = operator.ilshift(span_b, span_a)
        self.assertIs(span_a.parent_span, span_b)
        self.assertIsInstance(result, Span)
예제 #7
0
    def test_add_span_adds_at_top_level(self):
        trace = self.sdk.current_trace

        span_id = Span.new_span_id()
        span_a = Span.new(trace, span_id)

        operator.add(trace, span_a)
        self.assertEqual(len(trace), 1)

        new_span_id = Span.new_span_id()
        span_b = Span.new(trace, new_span_id)
        operator.add(trace, span_b)
        self.assertEqual(len(trace), 2)
예제 #8
0
    def test_iadd_span_adds_at_top_level(self):
        trace = self.sdk.current_trace

        span_id = Span.new_span_id()
        span_a = Span.new(trace, span_id)

        result = operator.iadd(trace, span_a)
        self.assertEqual(len(trace), 1)
        self.assertIsInstance(result, Trace)

        new_span_id = Span.new_span_id()
        span_b = Span.new(trace, new_span_id)

        operator.iadd(trace, span_b)
        self.assertEqual(len(trace), 2)
        self.assertIsInstance(result, Trace)
예제 #9
0
    def test_isub_not_in_trace_raises(self):
        trace = self.sdk.current_trace

        span_id = Span.new_span_id()
        span = Span.new(trace, span_id)

        self.assertRaises(ValueError, operator.isub, trace, span)
예제 #10
0
    def test_rshift_trace(self):
        trace = self.sdk.current_trace
        other_trace = self.sdk.current_trace
        span = Span.new(other_trace, Span.new_span_id())

        operator.rshift(span, trace)
        self.assertIn(span, trace.spans)
        self.assertIn(span.span_id, trace.span_ids)
예제 #11
0
    def test_irshift_trace(self):
        trace = self.sdk.current_trace
        other_trace = self.sdk.current_trace
        span = Span.new(other_trace, Span.new_span_id())

        result = operator.irshift(span, trace)
        self.assertIn(span, trace.spans)
        self.assertIn(span.span_id, trace.span_ids)
        self.assertIsInstance(result, Span)
예제 #12
0
    def test_span_parent(self):
        trace_id = Trace.new_trace_id()
        trace = Trace.new(self.sdk, trace_id=trace_id)
        parent_span = Span.new(trace, Span.new_span_id())

        span = trace.span(parent_span=parent_span)
        self.assertIsInstance(span, Span)
        self.assertEqual(trace.spans, [span])
        self.assertIs(span.parent_span_id, parent_span.span_id)
예제 #13
0
    def test_context_manager_raises_DuplicateSpanEntryError(self):
        span = Span.new(self.trace, Span.new_span_id(), name='bob')

        with span as s:
            try:
                with s:
                    pass
            except DuplicateSpanEntryError as e:
                self.assertIs(e.span, span)
            else:
                assert False
예제 #14
0
    def test_export(self):
        parent_span_id = Span.new_span_id()

        e_labels = {'a': '1', 'b': '2', 'c': 'None'}
        span_kind = SpanKind.server

        start_time = datetime.datetime(2017, 1, 20)
        end_time = datetime.datetime(2017, 1, 23)
        e_start_time = datetime_to_timestamp(start_time)
        e_end_time = datetime_to_timestamp(end_time)

        span_id = Span.new_span_id()
        span = Span.new(
            self.trace,
            span_id,
            parent_span_id=parent_span_id,
            name='child',
            span_kind=span_kind,
            start_time=start_time,
            end_time=end_time,
            labels=e_labels,
        )

        for data in [span.export(), json.loads(span.json)]:
            self.assertIsInstance(data, {}.__class__)
            self.assertSetEqual(
                set(data.keys()),
                {
                    'spanId', 'kind', 'name', 'startTime', 'endTime',
                    'parentSpanId', 'labels'
                },
            )
            self.assertEqual(data['spanId'], str(span_id))
            self.assertEqual(data['kind'], span_kind.value)
            self.assertEqual(data['name'], 'child')
            self.assertEqual(data['startTime'], e_start_time)
            self.assertEqual(data['endTime'], e_end_time)
            self.assertEqual(data['parentSpanId'], str(parent_span_id))
            self.assertEqual(data['labels'], e_labels)
예제 #15
0
    def test_init(self):
        span_id = Span.new_span_id()

        span = Span.new(self.trace, span_id)
        self.assertIs(span.trace, self.trace)
        self.assertEqual(span.span_id, span_id)
        self.assertIsNone(span.parent_span_id)
        self.assertEqual(span.name, '')
        self.assertIsNone(span.start_time)
        self.assertIsNone(span.end_time)
        self.assertEqual(span.span_kind, SpanKind.unspecified)
        self.assertEqual(len(span.labels), 0)
        self.assertEqual(span.project_id, self.project_id)
        self.assertEqual(span.sdk, self.sdk)
예제 #16
0
    def test_context_manager(self):
        parent_span_id = Span.new_span_id()

        span = Span.new(self.trace, parent_span_id, name='parent')
        self.assertIsNone(span.start_time)
        self.assertIsNone(span.end_time)

        with span as s:
            self.assertIs(span, s)
            start_time = span.start_time
            self.assertIsNotNone(start_time)
            self.assertIsNone(span.end_time)

        self.assertIsNotNone(span.start_time)
        self.assertEqual(span.start_time, start_time)
        self.assertIsNotNone(span.end_time)
예제 #17
0
    def test_iadd_raises_ValueError(self):
        span_id = Span.new_span_id()

        span = Span.new(self.trace, span_id)
        self.assertRaises(TypeError, operator.iadd, span, 1)
예제 #18
0
    def test_irshift_raises(self):
        span_id = Span.new_span_id()
        span_a = Span.new(self.trace, span_id)

        self.assertRaises(TypeError, operator.irshift, span_a, 1)