From 6d759283877e30f5e680c25765ebe35c4e408cb2 Mon Sep 17 00:00:00 2001 From: Benjamin Wohlwend Date: Wed, 30 Mar 2022 13:50:41 +0200 Subject: [PATCH 1/2] 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 --- elasticapm/traces.py | 2 +- tests/client/transaction_tests.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/elasticapm/traces.py b/elasticapm/traces.py index 8d4df7dbc..815b9527d 100644 --- a/elasticapm/traces.py +++ b/elasticapm/traces.py @@ -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(): diff --git a/tests/client/transaction_tests.py b/tests/client/transaction_tests.py index 6ee0a7dce..1c7db2ede 100644 --- a/tests/client/transaction_tests.py +++ b/tests/client/transaction_tests.py @@ -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 ) From 3c0cb4d157e4015e2941e186e3970ee334585c2d Mon Sep 17 00:00:00 2001 From: Colton Myers Date: Wed, 30 Mar 2022 07:57:36 -0600 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.asciidoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 85cf3af45..462fd2e4f 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -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