Skip to content

Commit 5efefd0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into useragent
2 parents b548061 + 371061a commit 5efefd0

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ endif::[]
5353
===== Bug fixes
5454
5555
* Fix some context fields and metadata handling in AWS Lambda support {pull}1368[#1368]
56+
* Fix an issue where compressed spans would count against `transaction_max_spans` {pull}1377[#1377]
5657
5758
[[release-notes-6.6.0]]
5859
==== 6.6.0 - 2021-10-18

elasticapm/traces.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def _begin_span(
274274
elif tracer.config.transaction_max_spans and self._span_counter > tracer.config.transaction_max_spans - 1:
275275
self.dropped_spans += 1
276276
span = DroppedSpan(parent_span, context=context)
277-
self._span_counter += 1
278277
else:
279278
span = Span(
280279
transaction=self,
@@ -375,7 +374,7 @@ def to_dict(self) -> dict:
375374
"timestamp": int(self.timestamp * 1000000), # microseconds
376375
"outcome": self.outcome,
377376
"sampled": self.is_sampled,
378-
"span_count": {"started": self._span_counter - self.dropped_spans, "dropped": self.dropped_spans},
377+
"span_count": {"started": self._span_counter, "dropped": self.dropped_spans},
379378
}
380379
if self._dropped_span_statistics:
381380
result["dropped_spans_stats"] = [
@@ -639,6 +638,7 @@ def try_to_compress(self, sibling: SpanType) -> bool:
639638
self.composite["count"] += 1
640639
self.composite["sum"] += sibling.duration
641640
self.duration = sibling.ended_time - self.start_time
641+
self.transaction._span_counter -= 1
642642
return True
643643

644644
def _try_to_compress_composite(self, sibling: SpanType) -> Optional[str]:

tests/client/span_compression_tests.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import pytest
3131

3232
import elasticapm
33-
from elasticapm.conf.constants import SPAN
33+
from elasticapm.conf.constants import SPAN, TRANSACTION
3434

3535

3636
@pytest.mark.parametrize(
@@ -220,3 +220,37 @@ def test_buffer_is_reported_if_next_child_ineligible(elasticapm_client):
220220
elasticapm_client.end_transaction("test")
221221
spans = elasticapm_client.events[SPAN]
222222
assert len(spans) == 3
223+
224+
225+
@pytest.mark.parametrize(
226+
"elasticapm_client",
227+
[{"span_compression_same_kind_max_duration": "5ms", "span_compression_exact_match_max_duration": "5ms"}],
228+
indirect=True,
229+
)
230+
def test_compressed_spans_not_counted(elasticapm_client):
231+
elasticapm_client.begin_transaction("test")
232+
with elasticapm.capture_span(
233+
"test1",
234+
span_type="a",
235+
span_subtype="b",
236+
span_action="c",
237+
leaf=True,
238+
duration=2,
239+
extra={"destination": {"service": {"resource": "x"}}},
240+
) as span1:
241+
pass
242+
with elasticapm.capture_span(
243+
"test2",
244+
span_type="a",
245+
span_subtype="b",
246+
span_action="c",
247+
leaf=True,
248+
duration=3,
249+
extra={"destination": {"service": {"resource": "x"}}},
250+
) as span2:
251+
pass
252+
elasticapm_client.end_transaction("test")
253+
transaction = elasticapm_client.events[TRANSACTION][0]
254+
spans = elasticapm_client.events[SPAN]
255+
assert len(spans) == transaction["span_count"]["started"] == 1
256+
assert transaction["span_count"]["dropped"] == 0

tests/upstream/json-specs/error.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,14 @@
10961096
"object"
10971097
],
10981098
"properties": {
1099+
"name": {
1100+
"description": "Name is the generic designation of a transaction in the scope of a single service, eg: 'GET /users/:id'.",
1101+
"type": [
1102+
"null",
1103+
"string"
1104+
],
1105+
"maxLength": 1024
1106+
},
10991107
"sampled": {
11001108
"description": "Sampled indicates whether or not the full information for a transaction is captured. If a transaction is unsampled no spans and less context information will be reported.",
11011109
"type": [

0 commit comments

Comments
 (0)