Skip to content

Commit

Permalink
Fix span_frames_min_duration to be dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
basepi committed Mar 27, 2020
1 parent 920640d commit 8595816
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions elasticapm/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,13 @@ def __init__(self, frames_collector_func, frames_processing_func, queue_func, co
self.frames_collector_func = frames_collector_func
self._agent = agent
self._ignore_patterns = [re.compile(p) for p in config.transactions_ignore_patterns or []]
if config.span_frames_min_duration in (-1, None):
# both None and -1 mean "no minimum"
self.span_frames_min_duration = None

@property
def span_frames_min_duration(self):
if self.config.span_frames_min_duration in (-1, None):
return None
else:
self.span_frames_min_duration = config.span_frames_min_duration / 1000.0
return self.config.span_frames_min_duration / 1000.0

def begin_transaction(self, transaction_type, trace_parent=None, start=None):
"""
Expand Down
36 changes: 36 additions & 0 deletions tests/client/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,42 @@ def test_transaction_span_frames_min_duration_no_limit(elasticapm_client):
assert spans[1]["stacktrace"] is not None


def test_transaction_span_frames_min_duration_dynamic(elasticapm_client):
elasticapm_client.config.update(version="1", span_frames_min_duration=20)
elasticapm_client.begin_transaction("test_type")
with elasticapm.capture_span("noframes", duration=0.001):
pass
with elasticapm.capture_span("frames", duration=0.04):
pass
elasticapm_client.end_transaction("test")

spans = elasticapm_client.events[SPAN]

assert len(spans) == 2
assert spans[0]["name"] == "noframes"
assert "stacktrace" not in spans[0]

assert spans[1]["name"] == "frames"
assert spans[1]["stacktrace"] is not None

elasticapm_client.config.update(version="1", span_frames_min_duration=-1)
elasticapm_client.begin_transaction("test_type")
with elasticapm.capture_span("frames"):
pass
with elasticapm.capture_span("frames", duration=0.04):
pass
elasticapm_client.end_transaction("test")

spans = elasticapm_client.events[SPAN]

assert len(spans) == 4
assert spans[2]["name"] == "frames"
assert spans[2]["stacktrace"] is not None

assert spans[3]["name"] == "frames"
assert spans[3]["stacktrace"] is not None


@pytest.mark.parametrize("elasticapm_client", [{"transaction_max_spans": 3}], indirect=True)
def test_transaction_max_span_nested(elasticapm_client):
elasticapm_client.begin_transaction("test_type")
Expand Down

0 comments on commit 8595816

Please sign in to comment.