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 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 )