Skip to content

Commit

Permalink
fix issue in span serialization when using APM Server < 7.16 (#1510)
Browse files Browse the repository at this point in the history
* 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 <colton.myers@gmail.com>
  • Loading branch information
beniwohli and basepi authored Mar 30, 2022
1 parent 2e53a43 commit 7925225
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ endif::[]
//===== Bug fixes
//
=== Unreleased
// Unreleased changes go here
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
//[float]
//===== Features
//
[float]
===== Bug fixes
* Fix `otel_attributes`-related regression with older versions of APM Server (<7.16) {pull}1510[#1510]
[[release-notes-6.x]]
=== Python Agent version 6.x
Expand Down
2 changes: 1 addition & 1 deletion elasticapm/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def to_dict(self) -> dict:
result["otel"]["attributes"] = self.context.pop("otel_attributes")
else:
# Attributes map to labels for older versions
attributes = self.context.pop("otel_attributes")
attributes = self.context.pop("otel_attributes", {})
if attributes and ("tags" not in self.context):
self.context["tags"] = {}
for key, value in attributes.items():
Expand Down
17 changes: 17 additions & 0 deletions tests/client/transaction_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
from elasticapm.utils.disttracing import TraceParent


@pytest.mark.parametrize("elasticapm_client", [{"server_version": (7, 15)}, {"server_version": (7, 16)}], indirect=True)
def test_transaction_span(elasticapm_client):
elasticapm_client.begin_transaction("test")
with elasticapm.capture_span("test", extra={"a": "b"}):
pass
elasticapm_client.end_transaction("test", constants.OUTCOME.SUCCESS)
transactions = elasticapm_client.events[constants.TRANSACTION]
assert len(transactions) == 1
assert transactions[0]["name"] == "test"
assert transactions[0]["type"] == "test"
assert transactions[0]["result"] == constants.OUTCOME.SUCCESS

spans = elasticapm_client.events[constants.SPAN]
assert len(spans) == 1
assert spans[0]["name"] == "test"


@pytest.mark.parametrize(
"elasticapm_client", [{"transactions_ignore_patterns": ["^OPTIONS", "views.api.v2"]}], indirect=True
)
Expand Down

0 comments on commit 7925225

Please sign in to comment.