Skip to content

Commit d8cd4df

Browse files
committed
chore(tracing): limit strings to 25000 chars
1 parent 52d40ac commit d8cd4df

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

ddtrace/internal/_encoding.pyx

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from ..constants import _ORIGIN_KEY as ORIGIN_KEY
2323
from .constants import SPAN_LINKS_KEY
2424
from .constants import SPAN_EVENTS_KEY
2525
from .constants import MAX_UINT_64BITS
26+
from .._trace._limits import MAX_SPAN_META_VALUE_LEN
2627
from ..settings._agent import config as agent_config
2728

2829

@@ -135,7 +136,7 @@ cdef inline int pack_text(msgpack_packer *pk, object text) except? -1:
135136

136137
if PyBytesLike_Check(text):
137138
L = len(text)
138-
if L > ITEM_LIMIT:
139+
if L > MAX_SPAN_META_VALUE_LEN:
139140
PyErr_Format(ValueError, b"%.200s object is too large", Py_TYPE(text).tp_name)
140141
ret = msgpack_pack_raw(pk, L)
141142
if ret == 0:
@@ -144,13 +145,13 @@ cdef inline int pack_text(msgpack_packer *pk, object text) except? -1:
144145

145146
if PyUnicode_Check(text):
146147
IF PY_MAJOR_VERSION >= 3:
147-
ret = msgpack_pack_unicode(pk, text, ITEM_LIMIT)
148+
ret = msgpack_pack_unicode(pk, text, MAX_SPAN_META_VALUE_LEN)
148149
if ret == -2:
149150
raise ValueError("unicode string is too large")
150151
ELSE:
151152
text = PyUnicode_AsEncodedString(text, "utf-8", NULL)
152153
L = len(text)
153-
if L > ITEM_LIMIT:
154+
if L > MAX_SPAN_META_VALUE_LEN:
154155
raise ValueError("unicode string is too large")
155156
ret = msgpack_pack_raw(pk, L)
156157
if ret == 0:
@@ -226,7 +227,6 @@ cdef class ListStringTable(StringTable):
226227
cdef class MsgpackStringTable(StringTable):
227228
cdef msgpack_packer pk
228229
cdef int max_size
229-
cdef int _max_string_length
230230
cdef int _sp_len
231231
cdef stdint.uint32_t _sp_id
232232
cdef object _lock
@@ -238,7 +238,6 @@ cdef class MsgpackStringTable(StringTable):
238238
if self.pk.buf == NULL:
239239
raise MemoryError("Unable to allocate internal buffer.")
240240
self.max_size = max_size
241-
self._max_string_length = int(0.1*max_size)
242241
self.pk.length = MSGPACK_STRING_TABLE_LENGTH_PREFIX_SIZE
243242
self._sp_len = 0
244243
self._lock = threading.RLock()
@@ -254,9 +253,9 @@ cdef class MsgpackStringTable(StringTable):
254253
cdef insert(self, object string):
255254
cdef int ret
256255

257-
if len(string) > self._max_string_length:
256+
if len(string) > self.MAX_SPAN_META_VALUE_LEN:
258257
string = "<dropped string of length %d because it's too long (max allowed length %d)>" % (
259-
len(string), self._max_string_length
258+
len(string), self.MAX_SPAN_META_VALUE_LEN
260259
)
261260

262261
if self.pk.length + len(string) > self.max_size:

0 commit comments

Comments
 (0)