Skip to content

Commit 1956862

Browse files
chore: [SVLS-5973] return optional instead of raising exceptions
1 parent 3532b2a commit 1956862

File tree

3 files changed

+237
-115
lines changed

3 files changed

+237
-115
lines changed

ddtrace/_trace/_span_pointer.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from ddtrace._trace._span_link import SpanLink
1010
from ddtrace._trace._span_link import SpanLinkKind
11+
from ddtrace._trace.telemetry import record_span_pointer_calculation_issue
1112
from ddtrace.internal.logger import get_logger
1213

1314

@@ -67,20 +68,28 @@ def __post_init__(self):
6768
def _standard_hashing_function(*elements: bytes) -> str:
6869
try:
6970
if not elements:
70-
raise ValueError("elements must not be empty")
71+
return _standard_hashing_function_failure("elements must not be empty")
7172

7273
# Please see the tests for more details about this logic.
7374
return sha256(b"|".join(elements)).hexdigest()[:32]
7475

7576
except Exception as e:
76-
log.warning(
77-
"failed to generate standard hash for span pointer: %s",
78-
str(e),
79-
)
80-
return _add_random_suffix(
81-
prefix=_STANDARD_HASHING_FUNCTION_FAILURE_PREFIX,
82-
minimum_length=32,
83-
)
77+
return _standard_hashing_function_failure(str(e))
78+
79+
80+
def _standard_hashing_function_failure(reason: str) -> str:
81+
log.debug(
82+
"failed to generate standard hash for span pointer: %s",
83+
reason,
84+
)
85+
record_span_pointer_calculation_issue(
86+
context="standard_hashing_function",
87+
)
88+
89+
return _add_random_suffix(
90+
prefix=_STANDARD_HASHING_FUNCTION_FAILURE_PREFIX,
91+
minimum_length=32,
92+
)
8493

8594

8695
def _add_random_suffix(*, prefix: str, minimum_length: int) -> str:

0 commit comments

Comments
 (0)