File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed
sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 99 HTTP_CLIENT_REQUEST_DURATION ,
1010 HTTP_SERVER_REQUEST_DURATION ,
1111)
12- # pylint:disable=no-name-in-module
13- from fixedint import Int32
1412from azure .core import CaseInsensitiveEnumMeta
1513
1614
Original file line number Diff line number Diff line change 2121from opentelemetry .semconv .trace import DbSystemValues , SpanAttributes
2222from opentelemetry .util .types import Attributes
2323
24- # pylint:disable=no-name-in-module
25- from fixedint import Int32
26-
2724from azure .monitor .opentelemetry .exporter ._constants import _SAMPLE_RATE_KEY
2825
2926from azure .monitor .opentelemetry .exporter ._constants import (
@@ -342,12 +339,17 @@ def _get_url_for_http_request(attributes: Attributes) -> Optional[str]:
342339
343340def _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
You can’t perform that action at this time.
0 commit comments