def test_links(self):
        ids_generator = RandomIdsGenerator()
        other_context1 = trace_api.SpanContext(
            trace_id=ids_generator.generate_trace_id(),
            span_id=ids_generator.generate_span_id(),
            is_remote=False,
        )
        other_context2 = trace_api.SpanContext(
            trace_id=ids_generator.generate_trace_id(),
            span_id=ids_generator.generate_span_id(),
            is_remote=False,
        )

        links = (
            trace_api.Link(other_context1),
            trace_api.Link(other_context2, {"name": "neighbor"}),
        )
        with self.tracer.start_as_current_span("root", links=links) as root:

            self.assertEqual(len(root.links), 2)
            self.assertEqual(root.links[0].context.trace_id,
                             other_context1.trace_id)
            self.assertEqual(root.links[0].context.span_id,
                             other_context1.span_id)
            self.assertEqual(root.links[0].attributes, None)
            self.assertEqual(root.links[1].context.trace_id,
                             other_context2.trace_id)
            self.assertEqual(root.links[1].context.span_id,
                             other_context2.span_id)
            self.assertEqual(root.links[1].attributes, {"name": "neighbor"})
示例#2
0
    def test_span_environment_limits(self):
        reload(trace)
        tracer = new_tracer()
        ids_generator = RandomIdsGenerator()
        some_links = [
            trace_api.Link(
                trace_api.SpanContext(
                    trace_id=ids_generator.generate_trace_id(),
                    span_id=ids_generator.generate_span_id(),
                    is_remote=False,
                )
            )
            for _ in range(100)
        ]
        with pytest.raises(ValueError):
            with tracer.start_as_current_span("root", links=some_links):
                pass

        with tracer.start_as_current_span("root") as root:
            for idx in range(100):
                root.set_attribute("my_attribute_{}".format(idx), 0)
                root.add_event("my_event_{}".format(idx))

            self.assertEqual(len(root.attributes), 10)
            self.assertEqual(len(root.events), 20)
 def setUpClass(cls):
     ids_generator = RandomIdsGenerator()
     cls.serialized_trace_id = propagator.format_trace_id(
         ids_generator.generate_trace_id())
     cls.serialized_parent_id = propagator.format_span_id(
         ids_generator.generate_span_id())
     cls.serialized_origin = "origin-service"