11/*
2- * Copyright 2024 Google LLC
2+ * Copyright 2026 Google LLC
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions are
4444import java .util .concurrent .CancellationException ;
4545import java .util .concurrent .TimeUnit ;
4646import java .util .concurrent .atomic .AtomicBoolean ;
47+ import java .util .logging .Logger ;
4748import javax .annotation .Nullable ;
4849
4950/**
5556@ BetaApi
5657@ InternalApi
5758public class MetricsTracer implements ApiTracer {
59+ private static final Logger LOGGER = Logger .getLogger (MetricsTracer .class .getName ());
60+ private static final AtomicBoolean WARNING_LOGGED = new AtomicBoolean ();
61+
5862 public static final String METHOD_ATTRIBUTE = "method" ;
5963 public static final String LANGUAGE_ATTRIBUTE = "language" ;
6064 public static final String STATUS_ATTRIBUTE = "status" ;
@@ -69,6 +73,14 @@ public class MetricsTracer implements ApiTracer {
6973 private final AtomicBoolean operationFinished ;
7074
7175 public MetricsTracer (MethodName methodName , MetricsRecorder metricsRecorder ) {
76+ if (!MetricsUtils .isMetricsEnabled ()) {
77+ if (WARNING_LOGGED .compareAndSet (false , true )) {
78+ LOGGER .info (
79+ "Metrics are currently disabled. To enable metrics, set the environment variable "
80+ + "GOOGLE_CLOUD_ENABLE_METRICS=true or the system property "
81+ + "GOOGLE_CLOUD_ENABLE_METRICS=true." );
82+ }
83+ }
7284 this .attributes .put (METHOD_ATTRIBUTE , methodName .toString ());
7385 this .attributes .put (LANGUAGE_ATTRIBUTE , DEFAULT_LANGUAGE );
7486 this .metricsRecorder = metricsRecorder ;
0 commit comments