def test_register_asynchronous_instrument(self, mock_sync_measurement_consumer): meter_provider = MeterProvider() meter_provider._measurement_consumer.register_asynchronous_instrument.assert_called_with( meter_provider.get_meter("name").create_observable_counter( "name", Mock())) meter_provider._measurement_consumer.register_asynchronous_instrument.assert_called_with( meter_provider.get_meter("name").create_observable_up_down_counter( "name", Mock())) meter_provider._measurement_consumer.register_asynchronous_instrument.assert_called_with( meter_provider.get_meter("name").create_observable_gauge( "name", Mock()))
def test_consume_measurement_counter(self, mock_sync_measurement_consumer): sync_consumer_instance = mock_sync_measurement_consumer() meter_provider = MeterProvider() counter = meter_provider.get_meter("name").create_counter("name") counter.add(1) sync_consumer_instance.consume_measurement.assert_called()
def test_get_meter_duplicate(self): """ Subsequent calls to `MeterProvider.get_meter` with the same arguments should return the same `Meter` instance. """ mp = MeterProvider() meter1 = mp.get_meter( "name", version="version", schema_url="schema_url", ) meter2 = mp.get_meter( "name", version="version", schema_url="schema_url", ) meter3 = mp.get_meter( "name2", version="version", schema_url="schema_url", ) self.assertIs(meter1, meter2) self.assertIsNot(meter1, meter3)
def test_meter_configuration(self): """ Any updated configuration is applied to all returned `Meter`s. """ meter_provider = MeterProvider() view_0 = View() meter_provider.register_view(view_0) meter_0 = meter_provider.get_meter("meter_0") meter_1 = meter_provider.get_meter("meter_1") self.assertEqual(meter_0._meter_provider._views, [view_0]) self.assertEqual(meter_1._meter_provider._views, [view_0]) view_1 = View() meter_provider.register_view(view_1) self.assertEqual(meter_0._meter_provider._views, [view_0, view_1]) self.assertEqual(meter_1._meter_provider._views, [view_0, view_1])