Add Fixed-rate sampling logic for Azure Log Exporter#848
Add Fixed-rate sampling logic for Azure Log Exporter#848lzchen merged 5 commits intocensus-instrumentation:masterfrom
Conversation
| def __init__(self, **options): | ||
| self.options = Options(**options) | ||
| utils.validate_instrumentation_key(self.options.instrumentation_key) | ||
| if self.options.logging_sampling_rate < 0 or \ |
There was a problem hiding this comment.
nit:You can move this at the beginning of the method to avoid doing anything else if sampling rate is incorrect
There was a problem hiding this comment.
Validating the instrumentation key is also a validation and fast fail in itself.
| return time.time() - start_time # time taken to stop | ||
|
|
||
|
|
||
| class SamplingFilter(logging.Filter): |
There was a problem hiding this comment.
Is there any desire to support adaptive sampling for Application Insights as well? If so, it may be worth it to name this FixedRateSamplingFilter to be more specific.
There was a problem hiding this comment.
Currently in the roadmap there is no plan to add adaptive sampling. If this is ever added, it will be simple to iterate on this since the class is not exposed to customers.
c24t
left a comment
There was a problem hiding this comment.
Superficial comments only, LGTM!
contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py
Outdated
Show resolved
Hide resolved
| self.assertFalse('not_a_dict' in post_body) | ||
| self.assertFalse('key_1' in post_body) | ||
|
|
||
| @mock.patch('requests.post', return_value=mock.Mock()) |
There was a problem hiding this comment.
Surprising to see post patched here, but the only easy alternative I see is TransportMixin._transmit, which isn't obviously a better target.
Implements a
SamplingFilterclass forAzureLogHandler.SamplingFilterextends from the PythonFilterlogging class. Upon construction of the AzureLogHandler, a filter is added to the handler which filters out log records based off of a random number generated. The fixed rate is passed in to theAzureLogHandlerby thelogging_sampling_rateparameter which should be in the range [0,1.0]. The default rate if none passed is 1.0.AzureLogHandler(logging_sampling_rate=0.5)