Search code examples
google-cloud-logginggoogle-cloud-vertex-ai

How to properly import the MetricsServiceV2Client attribute from google.cloud.logging_v2 package?


I am trying to set up a locust based framework for ML load test and need to create custom metrics and logs for which the example that I am following is using 'MetricsServiceV2Client' in 'google.cloud.logging_v2' lib. In the Vertex Workbench on GCP inspite being on v3.0 of the google-cloud-logging lib I am getting an issue of import

from google.cloud import logging_v2
from google.cloud.logging_v2 import MetricsServiceV2Client
error: cannot import name 'MetricsServiceV2Client' from 'google.cloud.logging_v2' (/opt/conda/lib/python3.7/site-packages/google/cloud/logging_v2/__init__.py)

Interestingly when I test the import in Google's cloud console I am able to import without any issue. What could be the issue?


Solution

  • Change it to the following:

    from google.cloud.logging_v2.services.metrics_service_v2 import MetricsServiceV2Client

    This will work.