-
Notifications
You must be signed in to change notification settings - Fork 234
Closed
Description
Describe the bug: Sampled ES queries that use a datetime object in the query body raise a TypeError: datetime.date() is not JSON serializable exception.
To Reproduce
- In a sampled transaction, make a ES call that uses a datetime object in the query body.
- Results in an exception inside of the APM instrumentation code.
Sample stack trace:
File "/srv/env/local/lib/python2.7/site-packages/elasticapm/instrumentation/packages/base.py", line 107, in call_if_sampling
return self.call(module, method, wrapped, instance, args, kwargs)
File "/srv/env/local/lib/python2.7/site-packages/elasticapm/instrumentation/packages/elasticsearch.py", line 145, in call
return wrapped(*args, **kwargs)
File "/srv/env/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 71, in _wrapped
return func(*args, params=params, **kwargs)
File "/srv/env/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 388, in search
params=params, body=body)
File "/srv/env/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 276, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/srv/env/local/lib/python2.7/site-packages/elasticapm/instrumentation/packages/base.py", line 107, in call_if_sampling
return self.call(module, method, wrapped, instance, args, kwargs)
File "/srv/env/local/lib/python2.7/site-packages/elasticapm/instrumentation/packages/elasticsearch.py", line 47, in call
query.append(json.dumps(body["query"]))
File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.date(2018, 12, 1) is not JSON serializable
Expected behavior: ...
Environment (please complete the following information)
- OS: Ubuntu 14.04
- Python version: Python 2.7
- Framework and version [e.g. Django 2.1]: Django==1.10.8
- APM Server version: 6.4.0
- Agent version: elastic-apm==3.0.3
Additional context
I've created a fork and patch that we are using internally: shareablee@0099b66
I can submit that as a PR if that is the direction you want to go, and I manage to get the CLA signed. The CLA site doesn't appear to be working for me right now.
Metadata
Metadata
Assignees
Labels
No labels