Skip to content

Commit 1cc69a4

Browse files
committed
client: fix overriding of transport json serializer
We get a string from config so need to import it.
1 parent 37e4f7f commit 1cc69a4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

elasticapm/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def __init__(self, config=None, **inline) -> None:
155155
"processors": self.load_processors(),
156156
}
157157
if config.transport_json_serializer:
158-
transport_kwargs["json_serializer"] = config.transport_json_serializer
158+
json_serializer_func = import_string(config.transport_json_serializer)
159+
transport_kwargs["json_serializer"] = json_serializer_func
159160

160161
self._api_endpoint_url = urllib.parse.urljoin(
161162
self.config.server_url if self.config.server_url.endswith("/") else self.config.server_url + "/",

tests/client/client_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import elasticapm
4949
from elasticapm.base import Client
5050
from elasticapm.conf.constants import ERROR
51+
from elasticapm.utils.simplejson_encoder import dumps as simplejson_dumps
5152
from tests.fixtures import DummyTransport, TempStoreClient
5253
from tests.utils import assert_any_record_contains
5354

@@ -228,6 +229,13 @@ def test_custom_transport(elasticapm_client):
228229
assert isinstance(elasticapm_client._transport, DummyTransport)
229230

230231

232+
@pytest.mark.parametrize(
233+
"elasticapm_client", [{"transport_json_serializer": "elasticapm.utils.simplejson_encoder.dumps"}], indirect=True
234+
)
235+
def test_custom_transport_json_serializer(elasticapm_client):
236+
assert elasticapm_client._transport._json_serializer == simplejson_dumps
237+
238+
231239
@pytest.mark.parametrize("elasticapm_client", [{"processors": []}], indirect=True)
232240
def test_empty_processor_list(elasticapm_client):
233241
assert elasticapm_client.processors == []

0 commit comments

Comments
 (0)