File tree Expand file tree Collapse file tree 3 files changed +10
-6
lines changed
sdk/monitor/azure-monitor-opentelemetry-exporter
azure/monitor/opentelemetry/exporter/export/trace Expand file tree Collapse file tree 3 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ def should_sample(
104
104
return parent_result
105
105
106
106
sampling_percentage = self ._sampling_percentage_generator .get ()
107
- sampling_score = _get_DJB2_sample_score (format_trace_id (trace_id ).lower ())
107
+ sampling_score = _get_DJB2_sample_score (format_trace_id (trace_id ).lower (), "rate_limited" )
108
108
109
109
if sampling_score < sampling_percentage :
110
110
decision = Decision .RECORD_AND_SAMPLE
Original file line number Diff line number Diff line change @@ -340,7 +340,7 @@ def _get_url_for_http_request(attributes: Attributes) -> Optional[str]:
340
340
)
341
341
return url
342
342
343
- def _get_DJB2_sample_score (trace_id_hex : str ) -> float :
343
+ def _get_DJB2_sample_score (trace_id_hex : str , sampler_type ) -> float :
344
344
# This algorithm uses 32bit integers
345
345
hash_value = Int32 (_SAMPLING_HASH )
346
346
for char in trace_id_hex :
@@ -351,8 +351,12 @@ def _get_DJB2_sample_score(trace_id_hex: str) -> float:
351
351
else :
352
352
hash_value = abs (hash_value )
353
353
354
- # divide by _INTEGER_MAX for value between 0 and 1, then multiply by 100 for percentage
355
- return 100.0 * (float (hash_value ) / _INTEGER_MAX )
354
+ if sampler_type == "rate_limited" :
355
+ # divide by _INTEGER_MAX for value between 0 and 1, then multiply by 100 for percentage
356
+ return 100.0 * (float (hash_value ) / _INTEGER_MAX )
357
+ else :
358
+ # divide by _INTEGER_MAX for value between 0 and 1 for sampling score
359
+ return float (hash_value ) / _INTEGER_MAX
356
360
357
361
def _round_down_to_nearest (sampling_percentage : float ) -> float :
358
362
if sampling_percentage == 0 :
Original file line number Diff line number Diff line change @@ -469,7 +469,7 @@ def test_djb2_hash_consistency(self):
469
469
470
470
trace_id = "test-trace-id-12345"
471
471
472
- scores = [_get_DJB2_sample_score (trace_id ) for _ in range (10 )]
472
+ scores = [_get_DJB2_sample_score (trace_id , "rate_limited" ) for _ in range (10 )]
473
473
474
474
self .assertTrue (all (score == scores [0 ] for score in scores ))
475
475
@@ -485,7 +485,7 @@ def test_djb2_hash_edge_cases(self):
485
485
486
486
for trace_id in edge_cases :
487
487
with self .subTest (trace_id = trace_id ):
488
- score = _get_DJB2_sample_score (trace_id )
488
+ score = _get_DJB2_sample_score (trace_id , "rate_limited" )
489
489
self .assertIsInstance (score , float )
490
490
self .assertGreaterEqual (score , 0 )
491
491
self .assertLess (score , 100 )
You can’t perform that action at this time.
0 commit comments