@@ -100,7 +100,7 @@ def _get_spanner_optimizer_statistics_package():
100100log = logging .getLogger (__name__ )
101101
102102
103- def _get_spanner_enable_builtin_metrics ():
103+ def _get_spanner_enable_builtin_metrics_env ():
104104 return os .getenv (SPANNER_DISABLE_BUILTIN_METRICS_ENV_VAR ) != "true"
105105
106106
@@ -180,6 +180,10 @@ class Client(ClientWithProject):
180180 This is intended only for experimental host spanner endpoints.
181181 If set, this will override the `api_endpoint` in `client_options`.
182182
183+ :type disable_builtin_metrics: bool
184+ :param disable_builtin_metrics: (Optional) Default False. Set to True to disable
185+ the Spanner built-in metrics collection and exporting.
186+
183187 :raises: :class:`ValueError <exceptions.ValueError>` if both ``read_only``
184188 and ``admin`` are :data:`True`
185189 """
@@ -205,6 +209,7 @@ def __init__(
205209 observability_options = None ,
206210 default_transaction_options : Optional [DefaultTransactionOptions ] = None ,
207211 experimental_host = None ,
212+ disable_builtin_metrics = False ,
208213 ):
209214 self ._emulator_host = _get_spanner_emulator_host ()
210215 self ._experimental_host = experimental_host
@@ -248,7 +253,8 @@ def __init__(
248253 warnings .warn (_EMULATOR_HOST_HTTP_SCHEME )
249254 # Check flag to enable Spanner builtin metrics
250255 if (
251- _get_spanner_enable_builtin_metrics ()
256+ _get_spanner_enable_builtin_metrics_env ()
257+ and not disable_builtin_metrics
252258 and HAS_GOOGLE_CLOUD_MONITORING_INSTALLED
253259 ):
254260 meter_provider = metrics .NoOpMeterProvider ()
0 commit comments