Skip to content

Commit 7925225

Browse files
beniwohlibasepi
andauthored
fix issue in span serialization when using APM Server < 7.16 (#1510)
* fix issue in span serialization when using APM Server < 7.16 the issue wasn't originally caught in testing because we hardcode the server_version to a certain value (currently 8.0.0), and this bug was in a branch that only is hit with a server version lower than 7.16 fixes #1509 * CHANGELOG Co-authored-by: Colton Myers <[email protected]>
1 parent 2e53a43 commit 7925225

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
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+
33+
=== Unreleased
34+
35+
// Unreleased changes go here
36+
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
37+
//[float]
38+
//===== Features
39+
//
40+
[float]
41+
===== Bug fixes
42+
43+
* Fix `otel_attributes`-related regression with older versions of APM Server (<7.16) {pull}1510[#1510]
44+
3245
[[release-notes-6.x]]
3346
=== Python Agent version 6.x
3447

elasticapm/traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def to_dict(self) -> dict:
577577
result["otel"]["attributes"] = self.context.pop("otel_attributes")
578578
else:
579579
# Attributes map to labels for older versions
580-
attributes = self.context.pop("otel_attributes")
580+
attributes = self.context.pop("otel_attributes", {})
581581
if attributes and ("tags" not in self.context):
582582
self.context["tags"] = {}
583583
for key, value in attributes.items():

tests/client/transaction_tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@
3838
from elasticapm.utils.disttracing import TraceParent
3939

4040

41+
@pytest.mark.parametrize("elasticapm_client", [{"server_version": (7, 15)}, {"server_version": (7, 16)}], indirect=True)
42+
def test_transaction_span(elasticapm_client):
43+
elasticapm_client.begin_transaction("test")
44+
with elasticapm.capture_span("test", extra={"a": "b"}):
45+
pass
46+
elasticapm_client.end_transaction("test", constants.OUTCOME.SUCCESS)
47+
transactions = elasticapm_client.events[constants.TRANSACTION]
48+
assert len(transactions) == 1
49+
assert transactions[0]["name"] == "test"
50+
assert transactions[0]["type"] == "test"
51+
assert transactions[0]["result"] == constants.OUTCOME.SUCCESS
52+
53+
spans = elasticapm_client.events[constants.SPAN]
54+
assert len(spans) == 1
55+
assert spans[0]["name"] == "test"
56+
57+
4158
@pytest.mark.parametrize(
4259
"elasticapm_client", [{"transactions_ignore_patterns": ["^OPTIONS", "views.api.v2"]}], indirect=True
4360
)

0 commit comments

Comments
 (0)