Skip to content

Commit 37d47cf

Browse files
author
Emanuele Palazzetti
committed
[encoder] use the DD_MSGPACK_ENCODING (not documented) to enable experimental support for msgpack
1 parent 7bf0935 commit 37d47cf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ddtrace/encoding.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import os
12
import json
23
import logging
34

45

56
# check msgpack CPP implementation; if the import fails, we're using the
67
# pure Python implementation that is really slow, so the ``Encoder`` should use
7-
# a different encoding format
8+
# a different encoding format. To enable msgpack encoding, you should set
9+
# the ``DD_MSGPACK_ENCODING=1`` environment variable otherwise, the ``JSONEncoder``
10+
# will be used as a default.
811
try:
912
import msgpack
1013
from msgpack._packer import Packer # noqa
1114
from msgpack._unpacker import unpack, unpackb, Unpacker # noqa
12-
MSGPACK_CPP = True
15+
MSGPACK_ENCODING = os.getenv('DD_MSGPACK_ENCODING') == '1' # shortcut to accept only '1'
1316
except ImportError:
14-
MSGPACK_CPP = False
17+
MSGPACK_ENCODING = False
1518

1619
log = logging.getLogger(__name__)
1720

@@ -82,7 +85,7 @@ def get_encoder():
8285
The default behavior is to use Msgpack if we have a CPP implementation
8386
installed, falling back to the Python built-in JSON encoder.
8487
"""
85-
if MSGPACK_CPP:
88+
if MSGPACK_ENCODING:
8689
return MsgpackEncoder()
8790
else:
8891
return JSONEncoder()

0 commit comments

Comments
 (0)