Skip to content

Commit

Permalink
client: fix overriding of transport json serializer
Browse files Browse the repository at this point in the history
We get a string from config so need to import it.
  • Loading branch information
xrmx committed Mar 29, 2024
1 parent 37e4f7f commit 2c3bd1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elasticapm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def __init__(self, config=None, **inline) -> None:
"processors": self.load_processors(),
}
if config.transport_json_serializer:
transport_kwargs["json_serializer"] = config.transport_json_serializer
json_serializer_func = import_string(config.transport_json_serializer)
transport_kwargs["json_serializer"] = json_serializer_func

self._api_endpoint_url = urllib.parse.urljoin(
self.config.server_url if self.config.server_url.endswith("/") else self.config.server_url + "/",
Expand Down
13 changes: 13 additions & 0 deletions tests/client/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
import elasticapm
from elasticapm.base import Client
from elasticapm.conf.constants import ERROR

try:
from elasticapm.utils.simplejson_encoder import dumps as simplejson_dumps
except ImportError:
simplejson_dumps = None
from tests.fixtures import DummyTransport, TempStoreClient
from tests.utils import assert_any_record_contains

Expand Down Expand Up @@ -228,6 +233,14 @@ def test_custom_transport(elasticapm_client):
assert isinstance(elasticapm_client._transport, DummyTransport)


@pytest.mark.skipIf(simplejson_dumps is None)
@pytest.mark.parametrize(
"elasticapm_client", [{"transport_json_serializer": "elasticapm.utils.simplejson_encoder.dumps"}], indirect=True
)
def test_custom_transport_json_serializer(elasticapm_client):
assert elasticapm_client._transport._json_serializer == simplejson_dumps


@pytest.mark.parametrize("elasticapm_client", [{"processors": []}], indirect=True)
def test_empty_processor_list(elasticapm_client):
assert elasticapm_client.processors == []
Expand Down

0 comments on commit 2c3bd1a

Please sign in to comment.