def test_enable_heartbeat_metrics_exists(self, transport_mock):
     # pylint: disable=protected-access
     producer = heartbeat_metrics.AzureHeartbeatMetricsProducer()
     heartbeat_metrics._HEARTBEAT_METRICS = producer
     heartbeat_metrics.enable_heartbeat_metrics(None, None)
     self.assertEqual(heartbeat_metrics._HEARTBEAT_METRICS, producer)
     transport_mock.assert_not_called()
 def test_enable_heartbeat_metrics(self, transport_mock):
     ikey = '12345678-1234-5678-abcd-12345678abcd'
     # pylint: disable=protected-access
     self.assertIsNone(heartbeat_metrics._HEARTBEAT_METRICS)
     heartbeat_metrics.enable_heartbeat_metrics(None, ikey)
     self.assertTrue(
         isinstance(heartbeat_metrics._HEARTBEAT_METRICS,
                    heartbeat_metrics.AzureHeartbeatMetricsProducer))
     transport_mock.assert_called()
 def __init__(self, **options):
     self.options = Options(**options)
     utils.validate_instrumentation_key(self.options.instrumentation_key)
     self.storage = LocalFileStorage(
         path=self.options.storage_path,
         max_size=self.options.storage_max_size,
         maintenance_period=self.options.storage_maintenance_period,
         retention_period=self.options.storage_retention_period,
         source=self.__class__.__name__,
     )
     self._telemetry_processors = []
     super(AzureExporter, self).__init__(**options)
     heartbeat_metrics.enable_heartbeat_metrics(
         self.options.connection_string, self.options.instrumentation_key)
示例#4
0
def new_metrics_exporter(**options):
    exporter = MetricsExporter(**options)
    producers = [stats_module.stats]
    if exporter.options.enable_standard_metrics:
        producers.append(standard_metrics.producer)
    transport.get_exporter_thread(producers,
                                  exporter,
                                  interval=exporter.options.export_interval)
    from opencensus.ext.azure.metrics_exporter import heartbeat_metrics
    heartbeat_metrics.enable_heartbeat_metrics(
        exporter.options.connection_string,
        exporter.options.instrumentation_key
    )
    return exporter
示例#5
0
 def __init__(self, **options):
     super(BaseLogHandler, self).__init__()
     self.options = Options(**options)
     utils.validate_instrumentation_key(self.options.instrumentation_key)
     if not 0 <= self.options.logging_sampling_rate <= 1:
         raise ValueError('Sampling must be in the range: [0,1]')
     self.export_interval = self.options.export_interval
     self.max_batch_size = self.options.max_batch_size
     self.storage = LocalFileStorage(
         path=self.options.storage_path,
         max_size=self.options.storage_max_size,
         maintenance_period=self.options.storage_maintenance_period,
         retention_period=self.options.storage_retention_period,
         source=self.__class__.__name__,
     )
     self._telemetry_processors = []
     self.addFilter(SamplingFilter(self.options.logging_sampling_rate))
     self._queue = Queue(capacity=self.options.queue_capacity)
     self._worker = Worker(self._queue, self)
     self._worker.start()
     heartbeat_metrics.enable_heartbeat_metrics(
         self.options.connection_string, self.options.instrumentation_key)