Skip to content

Commit b4aaa29

Browse files
thiemanbrettlangdon
authored andcommitted
Prefer random.getrandbits on Python 3+, fall back to urandom implementation on 2 (#1183)
1 parent e8195a6 commit b4aaa29

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ddtrace/span.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
log = get_logger(__name__)
1313

1414

15+
if sys.version_info.major < 3:
16+
_getrandbits = random.SystemRandom().getrandbits
17+
else:
18+
_getrandbits = random.getrandbits
19+
20+
1521
class Span(object):
1622

1723
__slots__ = [
@@ -383,9 +389,6 @@ def __repr__(self):
383389
)
384390

385391

386-
_SystemRandom = random.SystemRandom()
387-
388-
389392
def _new_id():
390393
"""Generate a random trace_id or span_id"""
391-
return _SystemRandom.getrandbits(64)
394+
return _getrandbits(64)

0 commit comments

Comments
 (0)