def _get_resource():
    instance = monitored_resource.get_instance()

    if instance is not None:
        return resource_pb2.Resource(type=instance.get_type(),
                                     labels=instance.get_labels())
    return resource_pb2.Resource(type='global')
def get_resource(metric_record: MetricRecord) -> resource_pb2.Resource:
    resource_attributes = metric_record.instrument.meter.resource.attributes
    return resource_pb2.Resource(
        type=infer_oc_resource_type(resource_attributes),
        labels={k: str(v)
                for k, v in resource_attributes.items()},
    )
    def test_export_with_no_resource_found(self, mock_get_instance):
        event = threading.Event()
        requests = []

        def _helper(request_iterator, context):
            for r in request_iterator:
                requests.append(r)
                event.set()
            yield

        self._add_and_start_service(GenericRpcHandler(_helper))

        mock_get_instance.return_value = None

        _create_rpc_handler(self._create_stub()).send(
            metrics_service_pb2.ExportMetricsServiceRequest())

        self.assertTrue(event.wait(timeout=1))
        self.assertEqual(requests[0].resource,
                         resource_pb2.Resource(type='global'))
def get_resource(export_record: ExportRecord) -> resource_pb2.Resource:
    resource_attributes = export_record.resource.attributes
    return resource_pb2.Resource(
        type=infer_oc_resource_type(resource_attributes),
        labels={k: str(v) for k, v in resource_attributes.items()},
    )