Skip to content

Commit 41bbcf6

Browse files
committed
rm from utils
1 parent 8880986 commit 41bbcf6

File tree

2 files changed

+7
-7
lines changed
  • sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter

2 files changed

+7
-7
lines changed

sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
HTTP_CLIENT_REQUEST_DURATION,
1010
HTTP_SERVER_REQUEST_DURATION,
1111
)
12-
# pylint:disable=no-name-in-module
13-
from fixedint import Int32
1412
from azure.core import CaseInsensitiveEnumMeta
1513

1614

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
from opentelemetry.semconv.trace import DbSystemValues, SpanAttributes
2222
from opentelemetry.util.types import Attributes
2323

24-
# pylint:disable=no-name-in-module
25-
from fixedint import Int32
26-
2724
from azure.monitor.opentelemetry.exporter._constants import _SAMPLE_RATE_KEY
2825

2926
from azure.monitor.opentelemetry.exporter._constants import (
@@ -342,12 +339,17 @@ def _get_url_for_http_request(attributes: Attributes) -> Optional[str]:
342339

343340
def _get_DJB2_sample_score(trace_id_hex: str) -> float:
344341
# This algorithm uses 32bit integers
345-
hash_value = Int32(_SAMPLING_HASH)
342+
hash_value = _SAMPLING_HASH
346343
for char in trace_id_hex:
347344
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))
348350

349351
if hash_value == _INT32_MIN:
350-
hash_value = int(_INT32_MAX)
352+
hash_value = _INT32_MAX
351353
else:
352354
hash_value = abs(hash_value)
353355

0 commit comments

Comments
 (0)