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

Commit 8026400

Browse files
committed
Merge branch 'master' of https://github.com/census-instrumentation/opencensus-python into django-db-instrumentation
2 parents 7a7e6b8 + 4ef5df4 commit 8026400

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

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.

opencensus/stats/exporters/stackdriver_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def set_attribute_label(series, resource_labels, attribute_key,
389389

390390
def get_user_agent_slug():
391391
"""Get the UA fragment to identify this library version."""
392-
return "opencensus-{}".format(__version__)
392+
return "opencensus-python/{}".format(__version__)
393393

394394

395395
def new_stats_exporter(options):

0 commit comments

Comments
 (0)