Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 4ef5df4

Browse files
authored
Fix stats example project ID (#424)
1 parent 6f53356 commit 4ef5df4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/stats/exporter/stackdriver.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import time
1615
import random
16+
import time
17+
18+
import google.auth
19+
1720
from opencensus.stats import aggregation as aggregation_module
18-
from opencensus.stats.exporters import stackdriver_exporter as stackdriver
1921
from opencensus.stats import measure as measure_module
2022
from opencensus.stats import stats as stats_module
2123
from opencensus.stats import view as view_module
24+
from opencensus.stats.exporters import stackdriver_exporter as stackdriver
2225
from opencensus.tags import tag_key as tag_key_module
2326
from opencensus.tags import tag_map as tag_map_module
2427
from opencensus.tags import tag_value as tag_value_module
@@ -38,8 +41,14 @@
3841
view_manager = stats.view_manager
3942
stats_recorder = stats.stats_recorder
4043

44+
try:
45+
_, project_id = google.auth.default()
46+
except google.auth.exceptions.DefaultCredentialsError:
47+
raise ValueError("Couldn't find Google Cloud credentials, set the "
48+
"project ID with 'gcloud set project'")
49+
4150
exporter = stackdriver.new_stats_exporter(
42-
stackdriver.Options(project_id="opencenus-node"))
51+
stackdriver.Options(project_id=project_id))
4352
view_manager.register_exporter(exporter)
4453

4554
# Register view.

0 commit comments

Comments
 (0)