elastic / elastic/apm-agent-python

Refactor serialization mechanism to be extendable

Open
#182 2 comments 1 reaction 0 assignees View on GitHub
agent-python
Dominant language
Python
Stars
431
Forks
239
Avg merge
5d 10h
Merged PRs (30d)
7

Description

At the moment, our serialization code is just a really long `if-elif-elif-...` block: https://github.com/elastic/apm-agent-python/blob/ee45d21ff43be495089a005863b7f6af0707fe34/elasticapm/utils/encoding.py#L85-L138.

This has several drawbacks:
* it's not extendable (we e.g. might want to serialize Django `QuerySet` objects in a sane way that doesn't evaluate the queryset unnecessarily, but only if Django is installed)
* it's brittle
* it's hard to read
* ideally, serialization would also include shortening of values, which is hard to do in its current state

One option could be to have a registry, to which transformers can register themselves, together with a list of supported types for that transformer.

Contributor guide

Open the contributing guide

Research direction

Start by reading elasticapm/utils/encoding.py around lines 85-138, where serialization is currently implemented as a long conditional chain. Compare the proposed registry approach with the need for optional Django QuerySet handling and value shortening. Done means the serialization mechanism is extensible, less brittle, and avoids unnecessarily evaluating QuerySets when Django is installed.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.