Skip to content

Commit 3b59990

Browse files
jeremydvossCopilot
andauthored
Update sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py
Co-authored-by: Copilot <[email protected]>
1 parent 090ba59 commit 3b59990

File tree

1 file changed

+2
-5
lines changed
  • sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace

1 file changed

+2
-5
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_utils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,8 @@ def _get_DJB2_sample_score(trace_id_hex: str) -> float:
342342
hash_value = _SAMPLING_HASH
343343
for char in trace_id_hex:
344344
hash_value = ((hash_value << 5) + hash_value) + ord(char)
345-
# Manually handle 32-bit integer overflow
346-
if hash_value > _INT32_MAX:
347-
hash_value = ((hash_value - _INT32_MIN) % (_INT32_MAX - _INT32_MIN + 1)) + _INT32_MIN
348-
elif hash_value < _INT32_MIN:
349-
hash_value = _INT32_MAX - ((_INT32_MIN - hash_value - 1) % (_INT32_MAX - _INT32_MIN + 1))
345+
# Correctly emulate signed 32-bit integer overflow using two's complement
346+
hash_value = ((hash_value + 2**31) % 2**32) - 2**31
350347

351348
if hash_value == _INT32_MIN:
352349
hash_value = int(_INT32_MAX)

0 commit comments

Comments
 (0)