Skip to content

Commit 67f29fa

Browse files
committed
Fix exit_span_min_duration to properly use ms (elastic#1483)
* Fix exit_span_min_duration to properly use ms * CHANGELOG * Disable dropping fast exit spans by default * Fix another test
1 parent 85e3bfb commit 67f29fa

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

CHANGELOG.asciidoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ endif::[]
2929
//===== Bug fixes
3030
//
3131
32+
=== Unreleased
33+
34+
// Unreleased changes go here
35+
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
36+
[float]
37+
===== Features
38+
39+
* Add OpenTelemetry API bridge {pull}1411[#1411]
40+
41+
[float]
42+
===== Bug fixes
43+
44+
* Fix `exit_span_min_duration` and disable by default {pull}1483[#1483]
3245
3346
3447
[[release-notes-6.x]]

docs/configuration.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,12 +761,14 @@ Two spans are considered to be of the same kind if the following attributes are
761761
[options="header"]
762762
|============
763763
| Environment | Django/Flask | Default
764-
| `ELASTIC_APM_EXIT_SPAN_MIN_DURATION` | `EXIT_SPAN_MIN_DURATION` | `"1ms"`
764+
| `ELASTIC_APM_EXIT_SPAN_MIN_DURATION` | `EXIT_SPAN_MIN_DURATION` | `"0ms"`
765765
|============
766766

767767
Exit spans are spans that represent a call to an external service, like a database.
768768
If such calls are very short, they are usually not relevant and can be ignored.
769769

770+
This feature is disabled by default.
771+
770772
NOTE: if a span propagates distributed tracing IDs, it will not be ignored, even if it is shorter than the configured threshold.
771773
This is to ensure that no broken traces are recorded.
772774

elasticapm/conf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ class Config(_ConfigBase):
598598
)
599599
exit_span_min_duration = _ConfigValue(
600600
"EXIT_SPAN_MIN_DURATION",
601-
default=1,
601+
default=0,
602602
validators=[duration_validator],
603603
type=float,
604604
)

elasticapm/traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def end(self, skip_frames: int = 0, duration: Optional[float] = None):
616616
p.child_ended(self)
617617

618618
def report(self) -> None:
619-
if self.discardable and self.duration < self.transaction.config_exit_span_min_duration:
619+
if self.discardable and (self.duration * 1000) < self.transaction.config_exit_span_min_duration:
620620
self.transaction.track_dropped_span(self)
621621
self.transaction.dropped_spans += 1
622622
else:

tests/client/dropped_spans_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ def test_transaction_max_span_dropped_statistics_not_collected_for_incompatible_
124124
@pytest.mark.parametrize("elasticapm_client", [{"exit_span_min_duration": "1ms"}], indirect=True)
125125
def test_transaction_fast_exit_span(elasticapm_client):
126126
elasticapm_client.begin_transaction("test_type")
127-
with elasticapm.capture_span(span_type="x", name="x", leaf=True, duration=2): # not dropped, too long
127+
with elasticapm.capture_span(span_type="x", name="x", leaf=True, duration=0.002): # not dropped, too long
128128
pass
129-
with elasticapm.capture_span(span_type="y", name="y", leaf=True, duration=0.1): # dropped
129+
with elasticapm.capture_span(span_type="y", name="y", leaf=True, duration=0.0001): # dropped
130130
pass
131-
with elasticapm.capture_span(span_type="z", name="z", leaf=False, duration=0.1): # not dropped, not exit
131+
with elasticapm.capture_span(span_type="z", name="z", leaf=False, duration=0.0001): # not dropped, not exit
132132
pass
133133
elasticapm_client.end_transaction("foo", duration=2.2)
134134
transaction = elasticapm_client.events[constants.TRANSACTION][0]
@@ -139,6 +139,6 @@ def test_transaction_fast_exit_span(elasticapm_client):
139139
assert transaction["span_count"]["started"] == 3
140140
assert transaction["span_count"]["dropped"] == 1
141141
assert metrics[0]["span"]["type"] == "x"
142-
assert metrics[0]["samples"]["span.self_time.sum.us"]["value"] == 2000000
142+
assert metrics[0]["samples"]["span.self_time.sum.us"]["value"] == 2000
143143
assert metrics[1]["span"]["type"] == "y"
144-
assert metrics[1]["samples"]["span.self_time.sum.us"]["value"] == 100000
144+
assert metrics[1]["samples"]["span.self_time.sum.us"]["value"] == 100

tests/config/config_snapshotting_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_config_snapshotting_span_compression_drop_exit_span(elasticapm_client):
115115
span_subtype="b",
116116
span_action="c",
117117
extra={"destination": {"service": {"resource": "x"}}},
118-
duration=5,
118+
duration=0.005,
119119
):
120120
pass
121121
elasticapm_client.end_transaction()

0 commit comments

Comments
 (0)