Skip to content

Commit

Permalink
fix issue in span serialization when using APM Server < 7.16
Browse files Browse the repository at this point in the history
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 elastic#1509
  • Loading branch information
beniwohli committed Mar 30, 2022
1 parent 685b78f commit 6d75928
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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 6d75928

Please sign in to comment.