Skip to content

Commit 9c751b6

Browse files
authored
feat: use FIPS validated CSPRNG for telemetry (#3554)
# What does this PR do? Switches from `random.getrandbits` to `secrets.randbits` in the telemetry module. <!-- If resolving an issue, uncomment and update the line below --> Closes #3553 ## Test Plan Unit tests from scripts/unit-tests.sh were ran to verify the tests still pass. Signed-off-by: Doug Edgar <[email protected]>
1 parent 28d83fa commit 9c751b6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

llama_stack/providers/utils/telemetry/tracing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import contextvars
99
import logging # allow-direct-logging
1010
import queue
11-
import random
11+
import secrets
1212
import sys
1313
import threading
1414
import time
@@ -76,16 +76,16 @@ def span_id_to_str(span_id: int) -> str:
7676

7777

7878
def generate_span_id() -> str:
79-
span_id = random.getrandbits(64)
79+
span_id = secrets.randbits(64)
8080
while span_id == INVALID_SPAN_ID:
81-
span_id = random.getrandbits(64)
81+
span_id = secrets.randbits(64)
8282
return span_id_to_str(span_id)
8383

8484

8585
def generate_trace_id() -> str:
86-
trace_id = random.getrandbits(128)
86+
trace_id = secrets.randbits(128)
8787
while trace_id == INVALID_TRACE_ID:
88-
trace_id = random.getrandbits(128)
88+
trace_id = secrets.randbits(128)
8989
return trace_id_to_str(trace_id)
9090

9191

0 commit comments

Comments
 (0)