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

Commit 1d30e38

Browse files
authored
v0.4.1 and stackdriver v0.2.1 release (#615)
1 parent 11d1527 commit 1d30e38

File tree

13 files changed

+133
-29
lines changed

13 files changed

+133
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased
44

5+
## 0.4.0
6+
Released 2019-04-11
7+
8+
- Allow for metrics with empty label keys and values
9+
([#611](https://github.com/census-instrumentation/opencensus-python/pull/611))
10+
([#614](https://github.com/census-instrumentation/opencensus-python/pull/614))
11+
512
## 0.4.0
613
Released 2019-04-08
714

contrib/opencensus-ext-stackdriver/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
## 0.2.0
6+
Released 2019-04-11
7+
- Don't require exporter options, fall back to default GCP auth
8+
([#610](https://github.com/census-instrumentation/opencensus-python/pull/610))
9+
510
## 0.2.0
611
Released 2019-04-08
712

contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from google.api_core.gapic_v1 import client_info
2424
from google.cloud import monitoring_v3
25+
import google.auth
2526

2627
from opencensus.common import utils
2728
from opencensus.common.monitored_resource import monitored_resource
@@ -365,12 +366,16 @@ def get_user_agent_slug():
365366
return "opencensus-python/{}".format(__version__)
366367

367368

368-
def new_stats_exporter(options, interval=None):
369+
def new_stats_exporter(options=None, interval=None):
369370
"""Get a stats exporter and running transport thread.
370371
371372
Create a new `StackdriverStatsExporter` with the given options and start
372373
periodically exporting stats to stackdriver in the background.
373374
375+
Fall back to default auth if `options` is null. This will raise
376+
`google.auth.exceptions.DefaultCredentialsError` if default credentials
377+
aren't configured.
378+
374379
See `opencensus.metrics.transport.get_exporter_thread` for details on the
375380
transport thread.
376381
@@ -380,9 +385,12 @@ def new_stats_exporter(options, interval=None):
380385
:type interval: int or float
381386
:param interval: Seconds between export calls.
382387
383-
:rtype: :class:`StackdriverStatsExporter` and :class:`PeriodicTask`
384-
:return: A tuple of the exporter and transport thread.
388+
:rtype: :class:`StackdriverStatsExporter`
389+
:return: The newly-created exporter.
385390
"""
391+
if options is None:
392+
_, project_id = google.auth.default()
393+
options = Options(project_id=project_id)
386394
if str(options.project_id).strip() == "":
387395
raise ValueError(ERROR_BLANK_PROJECT_ID)
388396

contrib/opencensus-ext-stackdriver/tests/test_stackdriver_stats.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import unittest
1818

1919
from google.cloud import monitoring_v3
20+
import google.auth
2021

2122
from opencensus.common import utils
2223
from opencensus.common.version import __version__
@@ -115,6 +116,32 @@ def test_constructor_param(self):
115116
default_monitoring_labels=default_labels))
116117
self.assertEqual(exporter.options.project_id, project_id)
117118

119+
def test_null_options(self):
120+
# Check that we don't suppress auth errors
121+
auth_error = google.auth.exceptions.DefaultCredentialsError
122+
mock_auth_error = mock.Mock()
123+
mock_auth_error.side_effect = auth_error
124+
with mock.patch('opencensus.ext.stackdriver.stats_exporter'
125+
'.google.auth.default', mock_auth_error):
126+
with self.assertRaises(auth_error):
127+
stackdriver.new_stats_exporter()
128+
129+
# Check that we get the default credentials' project ID
130+
mock_auth_ok = mock.Mock()
131+
mock_auth_ok.return_value = (None, 123)
132+
with mock.patch('opencensus.ext.stackdriver.stats_exporter'
133+
'.google.auth.default', mock_auth_ok):
134+
sdse = stackdriver.new_stats_exporter()
135+
self.assertEqual(sdse.options.project_id, 123)
136+
137+
# Check that we raise if auth works but the project is empty
138+
mock_auth_no_project = mock.Mock()
139+
mock_auth_no_project.return_value = (None, '')
140+
with mock.patch('opencensus.ext.stackdriver.stats_exporter'
141+
'.google.auth.default', mock_auth_no_project):
142+
with self.assertRaises(ValueError):
143+
stackdriver.new_stats_exporter()
144+
118145
def test_blank_project(self):
119146
self.assertRaises(ValueError, stackdriver.new_stats_exporter,
120147
stackdriver.Options(project_id=""))

contrib/opencensus-ext-stackdriver/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = '0.2.0'
15+
__version__ = '0.2.1'

opencensus/common/version/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = '0.4.0'
15+
__version__ = '0.4.1'

opencensus/metrics/export/metric_descriptor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def __init__(self, name, description, unit, type_, label_keys):
130130
if type_ not in MetricDescriptorType:
131131
raise ValueError("Invalid type")
132132

133-
if not label_keys:
134-
raise ValueError("label_keys must not be empty or null")
133+
if label_keys is None:
134+
raise ValueError("label_keys must not be None")
135135

136136
if any(key is None for key in label_keys):
137137
raise ValueError("label_keys must not contain null keys")

opencensus/metrics/export/time_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class TimeSeries(object):
3838
""" # noqa
3939

4040
def __init__(self, label_values, points, start_timestamp):
41-
if not label_values:
42-
raise ValueError("label_values must not be null or empty")
41+
if label_values is None:
42+
raise ValueError("label_values must not be None")
4343
if not points:
4444
raise ValueError("points must not be null or empty")
4545
self._label_values = label_values

opencensus/trace/propagation/b3_format.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def from_headers(self, headers):
6262
sampled = headers.get(_SAMPLED_KEY)
6363

6464
if sampled is not None:
65-
if len(sampled) != 1:
66-
return SpanContext(from_header=False)
67-
68-
sampled = sampled in ('1', 'd')
65+
# The specification encodes an enabled tracing decision as "1".
66+
# In the wild pre-standard implementations might still send "true".
67+
# "d" is set in the single header case when debugging is enabled.
68+
sampled = sampled.lower() in ('1', 'd', 'true')
6969
else:
7070
# If there's no incoming sampling decision, it was deferred to us.
7171
# Even though we set it to False here, we might still sample

tests/unit/metrics/export/test_metric_descriptor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def test_null_label_keys(self):
5353
NAME, DESCRIPTION, UNIT,
5454
metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE, None)
5555

56+
def test_empty_label_keys(self):
57+
metric_descriptor.MetricDescriptor(
58+
NAME, DESCRIPTION, UNIT,
59+
metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE, [])
60+
5661
def test_null_label_key_values(self):
5762
with self.assertRaises(ValueError):
5863
metric_descriptor.MetricDescriptor(

0 commit comments

Comments
 (0)