Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions ddtrace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ def current_span(self):

def record(self, span):
""" Record the given finished span. """
if not self.enabled:
return

spans = []
with self._spans_lock:
self._spans.append(span)
Expand All @@ -108,12 +105,16 @@ def record(self, span):

def write(self, spans):
""" Submit the given spans to the agent. """
if spans:
if self.debug_logging:
log.debug("submitting %s spans", len(spans))
for span in spans:
log.debug("\n%s", span.pprint())
if not spans:
return # nothing to do

if self.debug_logging:
log.debug("writing %s spans (enabled:%s)", len(spans), self.enabled)
for span in spans:
log.debug("\n%s", span.pprint())

if self.enabled:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and to be sure: if self._writer and self.enabled ?

# only submit the spans if we're actually enabled.
self._writer.write(spans, self._services)

def set_service_info(self, service, app, app_type):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ def test_tracer_disabled():
s.set_tag("a", "b")
assert not writer.pop()

def test_tracer_disabled_mem_leak():
# ensure that if the tracer is disabled, we still remove things from the
# span buffer upon finishing.
writer = DummyWriter()
tracer = Tracer(writer=writer)
tracer.enabled = False
s1 = tracer.trace("foo")
s1.finish()
p1 = tracer.current_span()
s2 = tracer.trace("bar")
assert not s2._parent, s2._parent
s2.finish()
assert not p1, p1

def test_sampling():
writer = DummyWriter()
tracer = Tracer(writer=writer, sample_rate=0.5)
Expand Down