Exemple #1
0
    def test_span_propagation(self):
        # ensure spans getter and setter works properly
        @self.app.task
        def fn_task():
            return 42

        # propagate and retrieve a Span
        task_id = "7c6731af-9533-40c3-83a9-25b58f0d837f"
        span_before = self.tracer.trace("celery.run")
        attach_span(fn_task, task_id, span_before)
        span_after = retrieve_span(fn_task, task_id)
        assert span_before is span_after
Exemple #2
0
    def test_span_delete(self):
        # ensure the helper removes properly a propagated Span
        @self.app.task
        def fn_task():
            return 42

        # propagate a Span
        task_id = "7c6731af-9533-40c3-83a9-25b58f0d837f"
        span = self.tracer.trace("celery.run")
        attach_span(fn_task, task_id, span)
        # delete the Span
        weak_dict = getattr(fn_task, "__dd_task_span")
        detach_span(fn_task, task_id)
        assert weak_dict.get((task_id, False)) is None
Exemple #3
0
    def test_span_delete(self):
        # ensure the helper removes properly a propagated Span
        @self.app.task
        def fn_task():
            return 42

        # propagate a Span
        task_id = '7c6731af-9533-40c3-83a9-25b58f0d837f'
        span = self.tracer.trace('celery.run')
        attach_span(fn_task, task_id, span)
        # delete the Span
        weak_dict = getattr(fn_task, '__dd_task_span')
        detach_span(fn_task, task_id)
        ok_(weak_dict.get(task_id) is None)
Exemple #4
0
    def test_memory_leak_safety(self):
        # Spans are shared between signals using a Dictionary (task_id -> span).
        # This test ensures the GC correctly cleans finished spans. If this test
        # fails a memory leak will happen for sure.
        @self.app.task
        def fn_task():
            return 42

        # propagate and finish a Span for `fn_task`
        task_id = '7c6731af-9533-40c3-83a9-25b58f0d837f'
        attach_span(fn_task, task_id, self.tracer.trace('celery.run'))
        weak_dict = getattr(fn_task, '__dd_task_span')
        ok_(weak_dict.get(task_id))
        # flush data and force the GC
        weak_dict.get(task_id).finish()
        self.tracer.writer.pop()
        self.tracer.writer.pop_traces()
        gc.collect()
        ok_(weak_dict.get(task_id) is None)