diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a94f95b81..fa94a04c4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,4 +2,4 @@ # This file controls who is tagged for review for any given pull request. # For anything not explicitly taken by someone else: -* @census-instrumentation/global-owners @aabmass @c24t @hectorhdzg @lzchen @reyang @songy23 @victoraugustolls +* @census-instrumentation/global-owners @aabmass @hectorhdzg @lzchen @songy23 @victoraugustolls diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..bf62bcf53 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,41 @@ +name: Build + +on: + push: + branches-ignore: + - 'release/*' + pull_request: + +jobs: + build: + # 18.04 needed for python3.4 + runs-on: ubuntu-18.04 + env: + # We use these variables to convert between tox and GHA version literals + py27: 2.7 + py34: 3.4 + py35: 3.5 + py36: 3.6 + py37: 3.7 + strategy: + # ensures the entire test matrix is run, even if one permutation fails + fail-fast: false + matrix: + python-version: [py27, py34, py35, py36, py37] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python ${{ env[matrix.python-version] }} + uses: actions/setup-python@v2 + with: + python-version: ${{ env[matrix.python-version] }} + - name: Install tox + run: pip install -U tox-factor + - name: Cache tox environment + uses: actions/cache@v2 + with: + path: .tox + # bump version prefix to fully reset caches + key: v1-tox-${{ matrix.python-version }}-${{ hashFiles('tox.ini') }} + - name: run tox + run: tox -f ${{ matrix.python-version }} diff --git a/.pylintrc b/.pylintrc index 417d372ee..e34531789 100644 --- a/.pylintrc +++ b/.pylintrc @@ -5,11 +5,11 @@ # run arbitrary code. extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the excludelist. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the excludelist. The # regex matches against base names, not paths. ignore-patterns= diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9a06769a1..000000000 --- a/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -dist: xenial - -language: python - -python: - - '2.7' - - '3.4' - - '3.5' - - '3.6' - - '3.7' - -install: - - pip install tox-travis - -script: - - tox - - touch docs/.nojekyll diff --git a/CHANGELOG.md b/CHANGELOG.md index 742ebd370..6cb5f4e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 0.7.12 +Released 2021-01-14 +- Change blacklist to excludelist +([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) + ## 0.7.11 Released 2020-10-13 diff --git a/README.rst b/README.rst index 3532ec6c1..4bc43845d 100644 --- a/README.rst +++ b/README.rst @@ -118,9 +118,9 @@ Customization There are several things you can customize in OpenCensus: -* **Blacklist**, which excludes certain hosts and paths from being tracked. +* **Excludelist**, which excludes certain hosts and paths from being tracked. By default, the health check path for the App Engine flexible environment is - not tracked, you can turn it on by excluding it from the blacklist setting. + not tracked, you can turn it on by excluding it from the excludelist setting. * **Exporter**, which sends the traces. By default, the traces are printed to stdout in JSON format. You can choose @@ -174,8 +174,8 @@ information, please read the 'OPENCENSUS': { 'TRACE': { - 'BLACKLIST_HOSTNAMES': ['localhost', '127.0.0.1'], - 'BLACKLIST_PATHS': ['_ah/health'], + 'EXCLUDELIST_HOSTNAMES': ['localhost', '127.0.0.1'], + 'EXCLUDELIST_PATHS': ['_ah/health'], 'SAMPLER': 'opencensus.trace.samplers.ProbabilitySampler(rate=1)', 'EXPORTER': '''opencensus.ext.ocagent.trace_exporter.TraceExporter( service_name='foobar', diff --git a/contrib/opencensus-ext-azure/CHANGELOG.md b/contrib/opencensus-ext-azure/CHANGELOG.md index 31103f11f..b8d2cddcb 100644 --- a/contrib/opencensus-ext-azure/CHANGELOG.md +++ b/contrib/opencensus-ext-azure/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +## 1.0.6 +Released 2021-01-14 + +- Disable heartbeat metrics in exporters + ([#984](https://github.com/census-instrumentation/opencensus-python/pull/984)) +- Loosen instrumentation key validation to GUID + ([#984](https://github.com/census-instrumentation/opencensus-python/pull/984)) + ## 1.0.5 Released 2020-10-13 diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py index afb0ee388..a4c0b9df2 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/exporter.py @@ -67,7 +67,7 @@ def __init__(self, src, dst): def run(self): # pragma: NO COVER # Indicate that this thread is an exporter thread. - # Used to suppress tracking of requests in this thread. + # Used to suppress tracking of requests in this thread execution_context.set_is_exporter(True) src = self.src dst = self.dst diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py index 4e7401b77..feca72979 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py @@ -76,7 +76,6 @@ def _transmit(self, envelopes): except Exception: pass if response.status_code == 200: - logger.info('Transmission succeeded: %s.', text) return 0 if response.status_code == 206: # Partial Content if data: diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py index 4907f74af..75c839ee1 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/utils.py @@ -58,12 +58,9 @@ def timestamp_to_iso_str(timestamp): return to_iso_str(datetime.datetime.utcfromtimestamp(timestamp)) -# Validate UUID format -# Specs taken from https://tools.ietf.org/html/rfc4122 +# Validate GUID format uuid_regex_pattern = re.compile('^[0-9a-f]{8}-' - '[0-9a-f]{4}-' - '[1-5][0-9a-f]{3}-' - '[89ab][0-9a-f]{3}-' + '([0-9a-f]{4}-){3}' '[0-9a-f]{12}$') diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/version.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/version.py index e3ba8af95..43f8a937a 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/common/version.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/common/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '1.0.5' +__version__ = '1.0.6' diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py index f74d0c24e..45b104adf 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/log_exporter/__init__.py @@ -149,7 +149,9 @@ def __init__(self, probability=1.0): self.probability = probability def filter(self, record): - return random.random() < self.probability + val = random.random() + print(val) + return val < self.probability class AzureLogHandler(TransportMixin, ProcessorMixin, BaseLogHandler): diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py index bd523809a..17ee88c50 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/__init__.py @@ -153,9 +153,4 @@ def new_metrics_exporter(**options): producers, exporter, interval=exporter.options.export_interval) - from opencensus.ext.azure.metrics_exporter import heartbeat_metrics - heartbeat_metrics.enable_heartbeat_metrics( - exporter.options.connection_string, - exporter.options.instrumentation_key - ) return exporter diff --git a/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py b/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py index 17e4f3d3b..fa82b09d1 100644 --- a/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-azure/opencensus/ext/azure/trace_exporter/__init__.py @@ -60,8 +60,6 @@ def __init__(self, **options): self._telemetry_processors = [] super(AzureExporter, self).__init__(**options) atexit.register(self._stop, self.options.grace_period) - heartbeat_metrics.enable_heartbeat_metrics( - self.options.connection_string, self.options.instrumentation_key) def span_data_to_envelope(self, sd): envelope = Envelope( diff --git a/contrib/opencensus-ext-azure/setup.py b/contrib/opencensus-ext-azure/setup.py index 11e770fca..d7c8eff50 100644 --- a/contrib/opencensus-ext-azure/setup.py +++ b/contrib/opencensus-ext-azure/setup.py @@ -39,7 +39,7 @@ include_package_data=True, long_description=open('README.rst').read(), install_requires=[ - 'opencensus >= 0.7.11, < 1.0.0', + 'opencensus >= 0.7.12, < 1.0.0', 'psutil >= 5.6.3', 'requests >= 2.19.0', ], diff --git a/contrib/opencensus-ext-azure/tests/test_azure_heartbeat_metrics.py b/contrib/opencensus-ext-azure/tests/test_azure_heartbeat_metrics.py index a8ad2d564..08e14f808 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_heartbeat_metrics.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_heartbeat_metrics.py @@ -89,7 +89,13 @@ def test_heartbeat_metric_init(self): self.assertFalse(metric.init) self.assertEqual(len(metric.properties), 0) - def test_heartbeat_metric_get_metric_init(self): + @mock.patch( + 'requests.get', + throw(requests.exceptions.ConnectionError) + ) + @mock.patch('os.environ.get') + def test_heartbeat_metric_get_metric_init(self, environ_mock): + environ_mock.return_value = None metric = heartbeat_metrics.HeartbeatMetric() self.assertFalse(metric.init) metrics = metric.get_metrics() diff --git a/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py b/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py index 497422c17..1a9685cc7 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_metrics_exporter.py @@ -234,6 +234,7 @@ def test_new_metrics_exporter_no_standard_metrics(self, exporter_mock): self.assertFalse(isinstance(exporter_mock.call_args[0][0][0], producer_class)) + @unittest.skip("Skip because disabling heartbeat metrics") @mock.patch('opencensus.ext.azure.metrics_exporter' '.transport.get_exporter_thread') def test_new_metrics_exporter_heartbeat(self, exporter_mock): diff --git a/contrib/opencensus-ext-azure/tests/test_azure_utils.py b/contrib/opencensus-ext-azure/tests/test_azure_utils.py index 47ef484d8..75aa0bb06 100644 --- a/contrib/opencensus-ext-azure/tests/test_azure_utils.py +++ b/contrib/opencensus-ext-azure/tests/test_azure_utils.py @@ -121,12 +121,14 @@ def test_invalid_key_section5_hex(self): self.assertRaises(ValueError, lambda: utils.validate_instrumentation_key(key)) - def test_invalid_key_version(self): - key = '1234abcd-5678-6efa-8abc-1234567890ab' - self.assertRaises(ValueError, - lambda: utils.validate_instrumentation_key(key)) + def test_valid_key_section2_hex(self): + key = '1234abcd-567a-4efa-8abc-1234567890ab' + self.assertIsNone(utils.validate_instrumentation_key(key)) - def test_invalid_key_variant(self): - key = '1234abcd-5678-4efa-2abc-1234567890ab' - self.assertRaises(ValueError, - lambda: utils.validate_instrumentation_key(key)) + def test_valid_key_section3_hex(self): + key = '1234abcd-5678-befa-8abc-1234567890ab' + self.assertIsNone(utils.validate_instrumentation_key(key)) + + def test_valid_key_section4_hex(self): + key = '1234abcd-5678-4efa-cabc-1234567890ab' + self.assertIsNone(utils.validate_instrumentation_key(key)) diff --git a/contrib/opencensus-ext-datadog/examples/datadog.py b/contrib/opencensus-ext-datadog/examples/datadog.py index d415323e6..a74e67c44 100644 --- a/contrib/opencensus-ext-datadog/examples/datadog.py +++ b/contrib/opencensus-ext-datadog/examples/datadog.py @@ -6,7 +6,7 @@ app = Flask(__name__) middleware = FlaskMiddleware(app, - blacklist_paths=['/healthz'], + excludelist_paths=['/healthz'], sampler=AlwaysOnSampler(), exporter=DatadogTraceExporter( Options(service='python-export-test', diff --git a/contrib/opencensus-ext-django/CHANGELOG.md b/contrib/opencensus-ext-django/CHANGELOG.md index 79d6d9a43..116a0e499 100644 --- a/contrib/opencensus-ext-django/CHANGELOG.md +++ b/contrib/opencensus-ext-django/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 0.7.3 +Released 2021-01-14 + +- Change blacklist to excludelist +([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) + ## 0.7.2 Released 2019-09-30 diff --git a/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py b/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py index 53c26131c..84685f008 100644 --- a/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py +++ b/contrib/opencensus-ext-django/opencensus/ext/django/middleware.py @@ -46,8 +46,8 @@ REQUEST_THREAD_LOCAL_KEY = 'django_request' SPAN_THREAD_LOCAL_KEY = 'django_span' -BLACKLIST_PATHS = 'BLACKLIST_PATHS' -BLACKLIST_HOSTNAMES = 'BLACKLIST_HOSTNAMES' +EXCLUDELIST_PATHS = 'EXCLUDELIST_PATHS' +EXCLUDELIST_HOSTNAMES = 'EXCLUDELIST_HOSTNAMES' log = logging.getLogger(__name__) @@ -160,9 +160,12 @@ def __init__(self, get_response=None): if isinstance(self.propagator, six.string_types): self.propagator = configuration.load(self.propagator) - self.blacklist_paths = settings.get(BLACKLIST_PATHS, None) + self.excludelist_paths = settings.get(EXCLUDELIST_PATHS, None) - self.blacklist_hostnames = settings.get(BLACKLIST_HOSTNAMES, None) + self.excludelist_hostnames = settings.get(EXCLUDELIST_HOSTNAMES, None) + + if django.VERSION >= (2,): # pragma: NO COVER + connection.execute_wrappers.append(_trace_db_call) if django.VERSION >= (2,): # pragma: NO COVER connection.execute_wrappers.append(_trace_db_call) @@ -173,8 +176,8 @@ def process_request(self, request): :type request: :class:`~django.http.request.HttpRequest` :param request: Django http request. """ - # Do not trace if the url is blacklisted - if utils.disable_tracing_url(request.path, self.blacklist_paths): + # Do not trace if the url is excludelisted + if utils.disable_tracing_url(request.path, self.excludelist_paths): return # Add the request to thread local @@ -183,8 +186,8 @@ def process_request(self, request): request) execution_context.set_opencensus_attr( - 'blacklist_hostnames', - self.blacklist_hostnames) + 'excludelist_hostnames', + self.excludelist_hostnames) try: # Start tracing this request @@ -234,8 +237,8 @@ def process_view(self, request, view_func, *args, **kwargs): function name add set it as the span name. """ - # Do not trace if the url is blacklisted - if utils.disable_tracing_url(request.path, self.blacklist_paths): + # Do not trace if the url is excludelisted + if utils.disable_tracing_url(request.path, self.excludelist_paths): return try: @@ -248,8 +251,8 @@ def process_view(self, request, view_func, *args, **kwargs): log.error('Failed to trace request', exc_info=True) def process_response(self, request, response): - # Do not trace if the url is blacklisted - if utils.disable_tracing_url(request.path, self.blacklist_paths): + # Do not trace if the url is excludelisted + if utils.disable_tracing_url(request.path, self.excludelist_paths): return response try: diff --git a/contrib/opencensus-ext-django/setup.py b/contrib/opencensus-ext-django/setup.py index f6d3b3ab0..741a22090 100644 --- a/contrib/opencensus-ext-django/setup.py +++ b/contrib/opencensus-ext-django/setup.py @@ -44,7 +44,7 @@ long_description=open('README.rst').read(), install_requires=[ 'Django >= 1.11', - 'opencensus >= 0.7.0, < 1.0.0', + 'opencensus >= 0.7.12, < 1.0.0', ], extras_require={}, license='Apache-2.0', diff --git a/contrib/opencensus-ext-django/tests/test_django_middleware.py b/contrib/opencensus-ext-django/tests/test_django_middleware.py index 714e01eeb..dacf1545f 100644 --- a/contrib/opencensus-ext-django/tests/test_django_middleware.py +++ b/contrib/opencensus-ext-django/tests/test_django_middleware.py @@ -127,17 +127,17 @@ def test_process_request(self): self.assertEqual(span.name, 'mock.mock.Mock') - def test_blacklist_path(self): + def test_excludelist_path(self): from opencensus.ext.django import middleware execution_context.clear() - blacklist_paths = ['test_blacklist_path'] + excludelist_paths = ['test_excludelist_path'] settings = type('Test', (object,), {}) settings.OPENCENSUS = { 'TRACE': { 'SAMPLER': 'opencensus.trace.samplers.AlwaysOnSampler()', # noqa - 'BLACKLIST_PATHS': blacklist_paths, + 'EXCLUDELIST_PATHS': excludelist_paths, 'EXPORTER': mock.Mock(), } } @@ -148,11 +148,11 @@ def test_blacklist_path(self): with patch_settings: middleware_obj = middleware.OpencensusMiddleware() - django_request = RequestFactory().get('/test_blacklist_path') + django_request = RequestFactory().get('/test_excludelist_path') disabled = utils.disable_tracing_url(django_request.path, - blacklist_paths) + excludelist_paths) self.assertTrue(disabled) - self.assertEqual(middleware_obj.blacklist_paths, blacklist_paths) + self.assertEqual(middleware_obj.excludelist_paths, excludelist_paths) # test process_request middleware_obj.process_request(django_request) diff --git a/contrib/opencensus-ext-django/version.py b/contrib/opencensus-ext-django/version.py index c652125f7..b7a1f8944 100644 --- a/contrib/opencensus-ext-django/version.py +++ b/contrib/opencensus-ext-django/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.2' +__version__ = '0.7.3' diff --git a/contrib/opencensus-ext-flask/CHANGELOG.md b/contrib/opencensus-ext-flask/CHANGELOG.md index befd70cef..537b142e0 100644 --- a/contrib/opencensus-ext-flask/CHANGELOG.md +++ b/contrib/opencensus-ext-flask/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 0.7.4 +Released 2021-01-14 + +- Change blacklist to excludelist +([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) + ## 0.7.3 Released 2019-10-01 diff --git a/contrib/opencensus-ext-flask/README.rst b/contrib/opencensus-ext-flask/README.rst index 797e2bbbc..1252f291a 100644 --- a/contrib/opencensus-ext-flask/README.rst +++ b/contrib/opencensus-ext-flask/README.rst @@ -22,7 +22,7 @@ Usage from opencensus.ext.flask.flask_middleware import FlaskMiddleware app = Flask(__name__) - middleware = FlaskMiddleware(app, blacklist_paths=['_ah/health']) + middleware = FlaskMiddleware(app, excludelist_paths=['_ah/health']) @app.route('/') def hello(): diff --git a/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py b/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py index 39b220e02..8e1d6dbfe 100644 --- a/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py +++ b/contrib/opencensus-ext-flask/opencensus/ext/flask/flask_middleware.py @@ -40,8 +40,8 @@ HTTP_URL = attributes_helper.COMMON_ATTRIBUTES['HTTP_URL'] HTTP_STATUS_CODE = attributes_helper.COMMON_ATTRIBUTES['HTTP_STATUS_CODE'] -BLACKLIST_PATHS = 'BLACKLIST_PATHS' -BLACKLIST_HOSTNAMES = 'BLACKLIST_HOSTNAMES' +EXCLUDELIST_PATHS = 'EXCLUDELIST_PATHS' +EXCLUDELIST_HOSTNAMES = 'EXCLUDELIST_HOSTNAMES' log = logging.getLogger(__name__) @@ -52,8 +52,8 @@ class FlaskMiddleware(object): :type app: :class: `~flask.Flask` :param app: A flask application. - :type blacklist_paths: list - :param blacklist_paths: Paths that do not trace. + :type excludelist_paths: list + :param excludelist_paths: Paths that do not trace. :type sampler: :class:`~opencensus.trace.samplers.base.Sampler` :param sampler: A sampler. It should extend from the base @@ -76,10 +76,10 @@ class FlaskMiddleware(object): :class:`.TextFormatPropagator`. """ - def __init__(self, app=None, blacklist_paths=None, sampler=None, + def __init__(self, app=None, excludelist_paths=None, sampler=None, exporter=None, propagator=None): self.app = app - self.blacklist_paths = blacklist_paths + self.excludelist_paths = excludelist_paths self.sampler = sampler self.exporter = exporter self.propagator = propagator @@ -112,10 +112,10 @@ def init_app(self, app): if isinstance(self.propagator, six.string_types): self.propagator = configuration.load(self.propagator) - self.blacklist_paths = settings.get(BLACKLIST_PATHS, - self.blacklist_paths) + self.excludelist_paths = settings.get(EXCLUDELIST_PATHS, + self.excludelist_paths) - self.blacklist_hostnames = settings.get(BLACKLIST_HOSTNAMES, None) + self.excludelist_hostnames = settings.get(EXCLUDELIST_HOSTNAMES, None) self.setup_trace() @@ -129,8 +129,10 @@ def _before_request(self): See: http://flask.pocoo.org/docs/0.12/api/#flask.Flask.before_request """ - # Do not trace if the url is blacklisted - if utils.disable_tracing_url(flask.request.url, self.blacklist_paths): + # Do not trace if the url is in the exclude list + if utils.disable_tracing_url( + flask.request.url, self.excludelist_paths + ): return try: @@ -161,8 +163,8 @@ def _before_request(self): HTTP_URL, str(flask.request.url) ) execution_context.set_opencensus_attr( - 'blacklist_hostnames', - self.blacklist_hostnames + 'excludelist_hostnames', + self.excludelist_hostnames ) except Exception: # pragma: NO COVER log.error('Failed to trace request', exc_info=True) @@ -172,8 +174,10 @@ def _after_request(self, response): See: http://flask.pocoo.org/docs/0.12/api/#flask.Flask.after_request """ - # Do not trace if the url is blacklisted - if utils.disable_tracing_url(flask.request.url, self.blacklist_paths): + # Do not trace if the url is in the exclude list + if utils.disable_tracing_url( + flask.request.url, self.excludelist_paths + ): return response try: @@ -193,8 +197,10 @@ def _after_request(self, response): return response def _teardown_request(self, exception): - # Do not trace if the url is blacklisted - if utils.disable_tracing_url(flask.request.url, self.blacklist_paths): + # Do not trace if the url is in the exclude list + if utils.disable_tracing_url( + flask.request.url, self.excludelist_paths + ): return try: diff --git a/contrib/opencensus-ext-flask/setup.py b/contrib/opencensus-ext-flask/setup.py index 52baa7d38..65594c6ae 100644 --- a/contrib/opencensus-ext-flask/setup.py +++ b/contrib/opencensus-ext-flask/setup.py @@ -40,7 +40,7 @@ long_description=open('README.rst').read(), install_requires=[ 'flask >= 0.12.3, < 2.0.0', - 'opencensus >= 0.7.1, < 1.0.0', + 'opencensus >= 0.7.12, < 1.0.0', ], extras_require={}, license='Apache-2.0', diff --git a/contrib/opencensus-ext-flask/tests/test_flask_middleware.py b/contrib/opencensus-ext-flask/tests/test_flask_middleware.py index 55b54c33d..4ef5a9982 100644 --- a/contrib/opencensus-ext-flask/tests/test_flask_middleware.py +++ b/contrib/opencensus-ext-flask/tests/test_flask_middleware.py @@ -165,14 +165,14 @@ def test__before_request(self): span_context = tracer.span_context self.assertEqual(span_context.trace_id, trace_id) - def test__before_request_blacklist(self): + def test__before_request_excludelist(self): flask_trace_header = 'traceparent' trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' span_id = '6e0c63257de34c92' flask_trace_id = '00-{}-{}-00'.format(trace_id, span_id) app = self.create_app() - # Use the AlwaysOnSampler here to prove that the blacklist takes + # Use the AlwaysOnSampler here to prove that the excludelist takes # precedence over the sampler flask_middleware.FlaskMiddleware(app=app, sampler=samplers.AlwaysOnSampler()) @@ -349,7 +349,7 @@ def test__after_request_invalid_url(self): self.assertEqual(span.attributes, expected_attributes) assert isinstance(span.parent_span, base.NullContextManager) - def test__after_request_blacklist(self): + def test__after_request_excludelist(self): flask_trace_header = 'traceparent' trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' span_id = '6e0c63257de34c92' diff --git a/contrib/opencensus-ext-flask/version.py b/contrib/opencensus-ext-flask/version.py index b7a1f8944..d5d5f1a28 100644 --- a/contrib/opencensus-ext-flask/version.py +++ b/contrib/opencensus-ext-flask/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.3' +__version__ = '0.7.4' diff --git a/contrib/opencensus-ext-grpc/CHANGELOG.md b/contrib/opencensus-ext-grpc/CHANGELOG.md index 6ff58e2d5..0562d9216 100644 --- a/contrib/opencensus-ext-grpc/CHANGELOG.md +++ b/contrib/opencensus-ext-grpc/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 0.7.2 +Released 2021-01-14 + +- Extract byte size from proto-plus messages + ([#976](https://github.com/census-instrumentation/opencensus-python/pull/976)) + ## 0.7.1 Released 2019-08-05 diff --git a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py index 0cc213bb3..7a36c3d84 100644 --- a/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py +++ b/contrib/opencensus-ext-grpc/opencensus/ext/grpc/utils.py @@ -6,6 +6,17 @@ from opencensus.trace import execution_context, time_event +def extract_byte_size(proto_message): + """Gets the byte size from a google.protobuf or proto-plus message""" + if hasattr(proto_message, "ByteSize"): + # google.protobuf message + return proto_message.ByteSize() + if hasattr(type(proto_message), "pb"): + # proto-plus message + return type(proto_message).pb(proto_message).ByteSize() + return None + + def add_message_event(proto_message, span, message_event_type, message_id=1): """Adds a MessageEvent to the span based off of the given protobuf message @@ -15,7 +26,7 @@ def add_message_event(proto_message, span, message_event_type, message_id=1): datetime.utcnow(), message_id, type=message_event_type, - uncompressed_size_bytes=proto_message.ByteSize() + uncompressed_size_bytes=extract_byte_size(proto_message), ) ) diff --git a/contrib/opencensus-ext-grpc/setup.py b/contrib/opencensus-ext-grpc/setup.py index c3dea1566..ec9401baf 100644 --- a/contrib/opencensus-ext-grpc/setup.py +++ b/contrib/opencensus-ext-grpc/setup.py @@ -40,7 +40,7 @@ long_description=open('README.rst').read(), install_requires=[ 'grpcio >= 1.0.0, < 2.0.0', - 'opencensus >= 0.7.1, < 1.0.0', + 'opencensus >= 0.7.12, < 1.0.0', ], extras_require={}, license='Apache-2.0', diff --git a/contrib/opencensus-ext-grpc/tests/test_server_interceptor.py b/contrib/opencensus-ext-grpc/tests/test_server_interceptor.py index 680de1002..850c036fa 100644 --- a/contrib/opencensus-ext-grpc/tests/test_server_interceptor.py +++ b/contrib/opencensus-ext-grpc/tests/test_server_interceptor.py @@ -167,6 +167,20 @@ def test__wrap_rpc_behavior_none(self): new_handler = server_interceptor._wrap_rpc_behavior(None, lambda: None) self.assertEqual(new_handler, None) + def test_extract_byte_size(self): + # should work with a google.protobuf message + google_protobuf_mock = mock.Mock() + google_protobuf_mock.ByteSize.return_value = 5 + self.assertEqual(grpc_utils.extract_byte_size(google_protobuf_mock), 5) + + # should work with a proto-plus style message + protoplus_protobuf_mock = mock.Mock(spec=[]) + type(protoplus_protobuf_mock).pb = mock.Mock() + type(protoplus_protobuf_mock).pb.return_value.ByteSize.return_value = 5 + self.assertEqual( + grpc_utils.extract_byte_size(protoplus_protobuf_mock), 5 + ) + class MockTracer(object): def __init__(self, *args, **kwargs): diff --git a/contrib/opencensus-ext-grpc/version.py b/contrib/opencensus-ext-grpc/version.py index 752777753..c652125f7 100644 --- a/contrib/opencensus-ext-grpc/version.py +++ b/contrib/opencensus-ext-grpc/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.1' +__version__ = '0.7.2' diff --git a/contrib/opencensus-ext-httplib/CHANGELOG.md b/contrib/opencensus-ext-httplib/CHANGELOG.md index 6c59e7ffe..bcdcde478 100644 --- a/contrib/opencensus-ext-httplib/CHANGELOG.md +++ b/contrib/opencensus-ext-httplib/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## 0.7.4 +Released 2021-01-14 + +- Change blacklist to excludelist +([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) + ## 0.7.3 Released 2020-02-03 diff --git a/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py b/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py index 9df2b6308..5ab3faa3e 100644 --- a/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py +++ b/contrib/opencensus-ext-httplib/opencensus/ext/httplib/trace.py @@ -65,10 +65,10 @@ def call(self, method, url, body, headers, *args, **kwargs): return request_func(self, method, url, body, headers, *args, **kwargs) _tracer = execution_context.get_opencensus_tracer() - blacklist_hostnames = execution_context.get_opencensus_attr( - 'blacklist_hostnames') + excludelist_hostnames = execution_context.get_opencensus_attr( + 'excludelist_hostnames') dest_url = '{}:{}'.format(self.host, self.port) - if utils.disable_tracing_hostname(dest_url, blacklist_hostnames): + if utils.disable_tracing_hostname(dest_url, excludelist_hostnames): return request_func(self, method, url, body, headers, *args, **kwargs) _span = _tracer.start_span() diff --git a/contrib/opencensus-ext-httplib/tests/test_httplib_trace.py b/contrib/opencensus-ext-httplib/tests/test_httplib_trace.py index eed7d8f42..cf0a30e94 100644 --- a/contrib/opencensus-ext-httplib/tests/test_httplib_trace.py +++ b/contrib/opencensus-ext-httplib/tests/test_httplib_trace.py @@ -103,7 +103,7 @@ def test_wrap_httplib_request(self): self.assertEqual(span_module.SpanKind.CLIENT, mock_tracer.span.span_kind) - def test_wrap_httplib_request_blacklist_ok(self): + def test_wrap_httplib_request_excludelist_ok(self): mock_span = mock.Mock() span_id = '1234' mock_span.span_id = span_id @@ -139,7 +139,7 @@ def test_wrap_httplib_request_blacklist_ok(self): 'traceparent': '00-123-456-01', }) - def test_wrap_httplib_request_blacklist_nok(self): + def test_wrap_httplib_request_excludelist_nok(self): mock_span = mock.Mock() span_id = '1234' mock_span.span_id = span_id diff --git a/contrib/opencensus-ext-httplib/version.py b/contrib/opencensus-ext-httplib/version.py index b7a1f8944..d5d5f1a28 100644 --- a/contrib/opencensus-ext-httplib/version.py +++ b/contrib/opencensus-ext-httplib/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.3' +__version__ = '0.7.4' diff --git a/contrib/opencensus-ext-pyramid/CHANGELOG.md b/contrib/opencensus-ext-pyramid/CHANGELOG.md index fd4831563..31fb762e6 100644 --- a/contrib/opencensus-ext-pyramid/CHANGELOG.md +++ b/contrib/opencensus-ext-pyramid/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 0.7.2 +Released 2021-01-14 +- Change blacklist to excludelist +([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) + ## 0.7.1 Released 2019-08-26 diff --git a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py index 2a119cfb2..575432a2b 100644 --- a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py +++ b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/config.py @@ -21,7 +21,7 @@ 'PROPAGATOR': trace_context_http_header_format.TraceContextPropagator(), # https://cloud.google.com/appengine/docs/flexible/python/ # how-instances-are-managed#health_checking - 'BLACKLIST_PATHS': ['_ah/health'], + 'EXCLUDELIST_PATHS': ['_ah/health'], } diff --git a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py index 3b853ddc5..76fcd59c7 100644 --- a/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py +++ b/contrib/opencensus-ext-pyramid/opencensus/ext/pyramid/pyramid_middleware.py @@ -27,7 +27,7 @@ HTTP_URL = attributes_helper.COMMON_ATTRIBUTES['HTTP_URL'] HTTP_STATUS_CODE = attributes_helper.COMMON_ATTRIBUTES['HTTP_STATUS_CODE'] -BLACKLIST_PATHS = 'BLACKLIST_PATHS' +EXCLUDELIST_PATHS = 'EXCLUDELIST_PATHS' log = logging.getLogger(__name__) @@ -62,7 +62,7 @@ def __init__(self, handler, registry): self.exporter = settings.EXPORTER self.propagator = settings.PROPAGATOR - self._blacklist_paths = settings.BLACKLIST_PATHS + self._excludelist_paths = settings.EXCLUDELIST_PATHS def __call__(self, request): self._before_request(request) @@ -74,7 +74,7 @@ def __call__(self, request): return response def _before_request(self, request): - if utils.disable_tracing_url(request.path, self._blacklist_paths): + if utils.disable_tracing_url(request.path, self._excludelist_paths): return try: @@ -113,7 +113,7 @@ def _before_request(self, request): log.error('Failed to trace request', exc_info=True) def _after_request(self, request, response): - if utils.disable_tracing_url(request.path, self._blacklist_paths): + if utils.disable_tracing_url(request.path, self._excludelist_paths): return try: diff --git a/contrib/opencensus-ext-pyramid/setup.py b/contrib/opencensus-ext-pyramid/setup.py index 43aba4777..bc6f16098 100644 --- a/contrib/opencensus-ext-pyramid/setup.py +++ b/contrib/opencensus-ext-pyramid/setup.py @@ -40,7 +40,7 @@ long_description=open('README.rst').read(), install_requires=[ 'pyramid >= 1.9.1, < 2.0.0', - 'opencensus >= 0.7.0, < 1.0.0', + 'opencensus >= 0.7.12, < 1.0.0', ], extras_require={}, license='Apache-2.0', diff --git a/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py b/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py index f31ad66e9..4ff7addb0 100644 --- a/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py +++ b/contrib/opencensus-ext-pyramid/tests/test_pyramid_config.py @@ -29,14 +29,14 @@ def test_trace_settings_default(self): assert trace_settings.SAMPLER == default_config['SAMPLER'] assert trace_settings.EXPORTER == default_config['EXPORTER'] assert trace_settings.PROPAGATOR == default_config['PROPAGATOR'] - assert trace_settings.BLACKLIST_PATHS == default_config[ - 'BLACKLIST_PATHS'] + assert trace_settings.EXCLUDELIST_PATHS == default_config[ + 'EXCLUDELIST_PATHS'] def test_trace_settings_override(self): mock_sampler = mock.Mock() mock_exporter = mock.Mock() mock_propagator = mock.Mock() - mock_blacklist_paths = ['foo/bar'] + mock_excludelist_paths = ['foo/bar'] registry = mock.Mock() registry.settings = { @@ -45,7 +45,7 @@ def test_trace_settings_override(self): 'SAMPLER': mock_sampler, 'EXPORTER': mock_exporter, 'PROPAGATOR': mock_propagator, - 'BLACKLIST_PATHS': mock_blacklist_paths, + 'EXCLUDELIST_PATHS': mock_excludelist_paths, }, }, } @@ -55,7 +55,7 @@ def test_trace_settings_override(self): assert trace_settings.SAMPLER == mock_sampler assert trace_settings.EXPORTER == mock_exporter assert trace_settings.PROPAGATOR == mock_propagator - assert trace_settings.BLACKLIST_PATHS == mock_blacklist_paths + assert trace_settings.EXCLUDELIST_PATHS == mock_excludelist_paths def test_trace_settings_invalid(self): registry = mock.Mock() diff --git a/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py b/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py index 6cfd9dd8b..63121b740 100644 --- a/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py +++ b/contrib/opencensus-ext-pyramid/tests/test_pyramid_middleware.py @@ -167,7 +167,7 @@ def dummy_handler(request): span_context = tracer.span_context self.assertEqual(span_context.trace_id, trace_id) - def test__before_request_blacklist(self): + def test__before_request_excludelist(self): pyramid_trace_header = 'traceparent' trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' span_id = '6e0c63257de34c92' @@ -248,7 +248,7 @@ def dummy_handler(request): self.assertEqual(span.attributes, expected_attributes) - def test__after_request_blacklist(self): + def test__after_request_excludelist(self): pyramid_trace_header = 'traceparent' trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05' span_id = '6e0c63257de34c92' diff --git a/contrib/opencensus-ext-pyramid/version.py b/contrib/opencensus-ext-pyramid/version.py index 752777753..c652125f7 100644 --- a/contrib/opencensus-ext-pyramid/version.py +++ b/contrib/opencensus-ext-pyramid/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.1' +__version__ = '0.7.2' diff --git a/contrib/opencensus-ext-requests/CHANGELOG.md b/contrib/opencensus-ext-requests/CHANGELOG.md index d0b090412..a42e24866 100644 --- a/contrib/opencensus-ext-requests/CHANGELOG.md +++ b/contrib/opencensus-ext-requests/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 0.7.4 +Released 2021-01-14 +- Change blacklist to excludelist +([#977](https://github.com/census-instrumentation/opencensus-python/pull/977)) + ## 0.7.3 Released 2020-02-03 diff --git a/contrib/opencensus-ext-requests/README.rst b/contrib/opencensus-ext-requests/README.rst index 54762d7c0..dd0257d20 100644 --- a/contrib/opencensus-ext-requests/README.rst +++ b/contrib/opencensus-ext-requests/README.rst @@ -13,7 +13,7 @@ You can enable requests integration by specifying ``'requests'`` to ``trace_inte It's possible to configure a list of URL you don't want traced. By default the request to exporter won't be traced. It's configurable by giving an array of hostname/port to the attribute -``blacklist_hostnames`` in OpenCensus context's attributes: +``excludelist_hostnames`` in OpenCensus context's attributes: Only the hostname must be specified if only the hostname is specified in the URL request. diff --git a/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py b/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py index c99862018..c2c42be13 100644 --- a/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py +++ b/contrib/opencensus-ext-requests/opencensus/ext/requests/trace.py @@ -74,14 +74,14 @@ def call(url, *args, **kwargs): # Check if request was sent from an exporter. If so, do not wrap. if execution_context.is_exporter(): return requests_func(url, *args, **kwargs) - blacklist_hostnames = execution_context.get_opencensus_attr( - 'blacklist_hostnames') + excludelist_hostnames = execution_context.get_opencensus_attr( + 'excludelist_hostnames') parsed_url = urlparse(url) if parsed_url.port is None: dest_url = parsed_url.hostname else: dest_url = '{}:{}'.format(parsed_url.hostname, parsed_url.port) - if utils.disable_tracing_hostname(dest_url, blacklist_hostnames): + if utils.disable_tracing_hostname(dest_url, excludelist_hostnames): return requests_func(url, *args, **kwargs) path = parsed_url.path if parsed_url.path else '/' @@ -145,14 +145,14 @@ def wrap_session_request(wrapped, instance, args, kwargs): method = kwargs.get('method') or args[0] url = kwargs.get('url') or args[1] - blacklist_hostnames = execution_context.get_opencensus_attr( - 'blacklist_hostnames') + excludelist_hostnames = execution_context.get_opencensus_attr( + 'excludelist_hostnames') parsed_url = urlparse(url) if parsed_url.port is None: dest_url = parsed_url.hostname else: dest_url = '{}:{}'.format(parsed_url.hostname, parsed_url.port) - if utils.disable_tracing_hostname(dest_url, blacklist_hostnames): + if utils.disable_tracing_hostname(dest_url, excludelist_hostnames): return wrapped(*args, **kwargs) path = parsed_url.path if parsed_url.path else '/' diff --git a/contrib/opencensus-ext-requests/setup.py b/contrib/opencensus-ext-requests/setup.py index b04a277fd..9833b3f8e 100644 --- a/contrib/opencensus-ext-requests/setup.py +++ b/contrib/opencensus-ext-requests/setup.py @@ -39,7 +39,7 @@ include_package_data=True, long_description=open('README.rst').read(), install_requires=[ - 'opencensus >= 0.7.3, < 1.0.0', + 'opencensus >= 0.7.12, < 1.0.0', 'wrapt >= 1.0.0, < 2.0.0', ], extras_require={}, diff --git a/contrib/opencensus-ext-requests/tests/test_requests_trace.py b/contrib/opencensus-ext-requests/tests/test_requests_trace.py index c3957ae71..6cd0a75f5 100644 --- a/contrib/opencensus-ext-requests/tests/test_requests_trace.py +++ b/contrib/opencensus-ext-requests/tests/test_requests_trace.py @@ -124,7 +124,7 @@ def test_wrap_requests(self): mock_tracer.current_span.status.__dict__ ) - def test_wrap_requests_blacklist_ok(self): + def test_wrap_requests_excludelist_ok(self): mock_return = mock.Mock() mock_return.status_code = 200 return_value = mock_return @@ -157,7 +157,7 @@ def test_wrap_requests_blacklist_ok(self): self.assertEqual(expected_name, mock_tracer.current_span.name) - def test_wrap_requests_blacklist_nok(self): + def test_wrap_requests_excludelist_nok(self): mock_return = mock.Mock() mock_return.status_code = 200 return_value = mock_return @@ -413,7 +413,7 @@ def test_wrap_session_request(self): mock_tracer.current_span.status.__dict__ ) - def test_wrap_session_request_blacklist_ok(self): + def test_wrap_session_request_excludelist_ok(self): def wrapped(*args, **kwargs): result = mock.Mock() result.status_code = 200 @@ -448,7 +448,7 @@ def wrapped(*args, **kwargs): expected_name = '/' self.assertEqual(expected_name, mock_tracer.current_span.name) - def test_wrap_session_request_blacklist_nok(self): + def test_wrap_session_request_excludelist_nok(self): def wrapped(*args, **kwargs): result = mock.Mock() result.status_code = 200 diff --git a/contrib/opencensus-ext-requests/version.py b/contrib/opencensus-ext-requests/version.py index b7a1f8944..d5d5f1a28 100644 --- a/contrib/opencensus-ext-requests/version.py +++ b/contrib/opencensus-ext-requests/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.3' +__version__ = '0.7.4' diff --git a/contrib/opencensus-ext-stackdriver/CHANGELOG.md b/contrib/opencensus-ext-stackdriver/CHANGELOG.md index 92869a205..a8071d279 100644 --- a/contrib/opencensus-ext-stackdriver/CHANGELOG.md +++ b/contrib/opencensus-ext-stackdriver/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## Unreleased + ## 0.7.4 Released 2020-10-13 @@ -25,25 +27,6 @@ Released 2019-08-05 - Support exporter changes in `opencensus>=0.7.0` -## 0.7.3 -Released 2020-06-29 - - - Add mean property for distribution values - ([#919](https://github.com/census-instrumentation/opencensus-python/pull/919)) - -## 0.7.2 -Released 2019-08-26 - - - Delete SD integ test metric descriptors - ([#770](https://github.com/census-instrumentation/opencensus-python/pull/770)) - - Updated `http.status_code` attribute to be an int. - ([#755](https://github.com/census-instrumentation/opencensus-python/pull/755)) - -## 0.7.1 -Released 2019-08-05 - - - Support exporter changes in `opencensus>=0.7.0` - ## 0.4.0 Released 2019-05-31 diff --git a/contrib/opencensus-ext-stackdriver/README.rst b/contrib/opencensus-ext-stackdriver/README.rst index d938ad12f..3dd36e177 100644 --- a/contrib/opencensus-ext-stackdriver/README.rst +++ b/contrib/opencensus-ext-stackdriver/README.rst @@ -32,8 +32,8 @@ This example shows how to report the traces to Stackdriver Trace: :: - pip install google-cloud-trace - pipenv install google-cloud-trace + pip install google-cloud-trace<1.0.0 + pipenv install google-cloud-trace<1.0.0 By default, traces are exported asynchronously, to reduce latency during your code's execution. If you would like to export data on the main thread diff --git a/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py index cf7fe0d79..b09e69647 100644 --- a/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py +++ b/contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/trace_exporter/__init__.py @@ -175,8 +175,8 @@ class StackdriverExporter(base_exporter.Exporter): :param transport: Class for creating new transport objects. It should extend from the base_exporter :class:`.Transport` type and implement :meth:`.Transport.export`. Defaults to - :class:`.SyncTransport`. The other option is - :class:`.AsyncTransport`. + :class:`.AsyncTransport`. The other option is + :class:`.SyncTransport`. """ def __init__(self, client=None, project_id=None, diff --git a/docs/trace/usage.rst b/docs/trace/usage.rst index f0ed9a452..3c858c84c 100644 --- a/docs/trace/usage.rst +++ b/docs/trace/usage.rst @@ -148,13 +148,13 @@ This example shows how to use the ``GoogleCloudFormatPropagator``: # Serialize header = propagator.to_header(span_context) -Blacklist Paths -~~~~~~~~~~~~~~~ +Excludelist Paths +~~~~~~~~~~~~~~~~~ You can specify which paths you do not want to trace by configuring the -blacklist paths. +excludelist paths. -This example shows how to configure the blacklist to ignore the `_ah/health` endpoint +This example shows how to configure the excludelist to ignore the `_ah/health` endpoint for a Flask application: .. code:: python @@ -163,21 +163,21 @@ for a Flask application: app = flask.Flask(__name__) - blacklist_paths = ['_ah/health'] - middleware = FlaskMiddleware(app, blacklist_paths=blacklist_paths) + excludelist_paths = ['_ah/health'] + middleware = FlaskMiddleware(app, excludelist_paths=excludelist_paths) -For Django, you can configure the blacklist in the ``OPENCENSUS_TRACE_PARAMS`` in ``settings.py``: +For Django, you can configure the excludelist in the ``OPENCENSUS_TRACE_PARAMS`` in ``settings.py``: .. code:: python OPENCENSUS_TRACE_PARAMS: { ... - 'BLACKLIST_PATHS': ['_ah/health',], + 'EXCLUDELIST_PATHS': ['_ah/health',], } .. note:: By default the health check path for the App Engine flexible environment is not traced, - but you can turn it on by excluding it from the blacklist setting. + but you can turn it on by excluding it from the excludelist setting. Framework Integration --------------------- @@ -235,7 +235,7 @@ setting in ``settings.py``: .. code:: python OPENCENSUS_TRACE_PARAMS = { - 'BLACKLIST_PATHS': ['/_ah/health'], + 'EXCLUDELIST_PATHS': ['/_ah/health'], 'GCP_EXPORTER_PROJECT': None, 'SAMPLING_RATE': 0.5, 'SERVICE_NAME': 'my_service', diff --git a/opencensus/common/transports/async_.py b/opencensus/common/transports/async_.py index cc63ba139..56e726119 100644 --- a/opencensus/common/transports/async_.py +++ b/opencensus/common/transports/async_.py @@ -93,7 +93,7 @@ def _thread_main(self): batches to the specified tracing backend using the exporter. """ # Indicate that this thread is an exporter thread. - # Used to suppress tracking of requests in this thread. + # Used to suppress tracking of requests in this thread execution_context.set_is_exporter(True) quit_ = False diff --git a/opencensus/common/version/__init__.py b/opencensus/common/version/__init__.py index 366bd7b59..e6da719b6 100644 --- a/opencensus/common/version/__init__.py +++ b/opencensus/common/version/__init__.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.7.11' +__version__ = '0.7.12' diff --git a/opencensus/metrics/transport.py b/opencensus/metrics/transport.py index e85be1eee..d27b06f32 100644 --- a/opencensus/metrics/transport.py +++ b/opencensus/metrics/transport.py @@ -80,7 +80,7 @@ def func(*aa, **kw): def run(self): # Indicate that this thread is an exporter thread. - # Used to suppress tracking of requests in this thread. + # Used to suppress tracking of requests in this thread execution_context.set_is_exporter(True) super(PeriodicMetricTask, self).run() diff --git a/opencensus/trace/utils.py b/opencensus/trace/utils.py index 7aabf73ab..5b9be3473 100644 --- a/opencensus/trace/utils.py +++ b/opencensus/trace/utils.py @@ -19,10 +19,10 @@ from opencensus.trace import execution_context from opencensus.trace.status import Status -# By default the blacklist urls are not tracing, currently just include the +# By default the excludelist urls are not tracing, currently just include the # health check url. The paths are literal string matched instead of regular # expressions. Do not include the '/' at the beginning of the path. -DEFAULT_BLACKLIST_PATHS = [ +DEFAULT_EXCLUDELIST_PATHS = [ '_ah/health', ] @@ -42,20 +42,20 @@ def get_func_name(func): return func_name -def disable_tracing_url(url, blacklist_paths=None): - """Disable tracing on the provided blacklist paths, by default not tracing +def disable_tracing_url(url, excludelist_paths=None): + """Disable tracing on the provided excludelist paths, by default not tracing the health check request. - If the url path starts with the blacklisted path, return True. + If the url path starts with the excludelisted path, return True. - :type blacklist_paths: list - :param blacklist_paths: Paths that not tracing. + :type excludelist_paths: list + :param excludelist_paths: Paths that not tracing. :rtype: bool :returns: True if not tracing, False if tracing. """ - if blacklist_paths is None: - blacklist_paths = DEFAULT_BLACKLIST_PATHS + if excludelist_paths is None: + excludelist_paths = DEFAULT_EXCLUDELIST_PATHS # Remove the 'https?|ftp://' if exists url = re.sub(URL_PATTERN, '', url) @@ -63,39 +63,39 @@ def disable_tracing_url(url, blacklist_paths=None): # Split the url by the first '/' and get the path part url_path = url.split('/', 1)[1] - for path in blacklist_paths: + for path in excludelist_paths: if url_path.startswith(path): return True return False -def disable_tracing_hostname(url, blacklist_hostnames=None): - """Disable tracing for the provided blacklist URLs, by default not tracing +def disable_tracing_hostname(url, excludelist_hostnames=None): + """Disable tracing for the provided excludelist URLs, by default not tracing the exporter url. - If the url path starts with the blacklisted path, return True. + If the url path starts with the excludelisted path, return True. - :type blacklist_hostnames: list - :param blacklist_hostnames: URL that not tracing. + :type excludelist_hostnames: list + :param excludelist_hostnames: URL that not tracing. :rtype: bool :returns: True if not tracing, False if tracing. """ - if blacklist_hostnames is None: + if excludelist_hostnames is None: # Exporter host_name are not traced by default _tracer = execution_context.get_opencensus_tracer() try: - blacklist_hostnames = [ + excludelist_hostnames = [ '{}:{}'.format( _tracer.exporter.host_name, _tracer.exporter.port ) ] except(AttributeError): - blacklist_hostnames = [] + excludelist_hostnames = [] - return url in blacklist_hostnames + return url in excludelist_hostnames def status_from_http_code(http_code): diff --git a/tests/system/trace/django/app/settings.py b/tests/system/trace/django/app/settings.py index 3bba77f31..c60837af9 100644 --- a/tests/system/trace/django/app/settings.py +++ b/tests/system/trace/django/app/settings.py @@ -71,7 +71,7 @@ 'PROPAGATOR': 'opencensus.trace.propagation.google_cloud_format.' 'GoogleCloudFormatPropagator()', - 'BLACKLIST_PATHS': [ + 'EXCLUDELIST_PATHS': [ '_ah/health', ], } diff --git a/tests/unit/trace/test_ext_utils.py b/tests/unit/trace/test_ext_utils.py index 0816b2d7e..e322158a7 100644 --- a/tests/unit/trace/test_ext_utils.py +++ b/tests/unit/trace/test_ext_utils.py @@ -53,9 +53,9 @@ def test_disable_tracing_url_default(self): def test_disable_tracing_url_explicit(self): url = 'http://127.0.0.1:8080/test_no_tracing' - blacklist_paths = ['test_no_tracing'] + excludelist_paths = ['test_no_tracing'] - disable_tracing = utils.disable_tracing_url(url, blacklist_paths) + disable_tracing = utils.disable_tracing_url(url, excludelist_paths) self.assertTrue(disable_tracing) def test_disable_tracing_hostname_default(self): @@ -65,14 +65,16 @@ def test_disable_tracing_hostname_default(self): self.assertFalse(disable_tracing) def test_disable_tracing_hostname_explicit(self): - blacklist_paths = ['127.0.0.1', '192.168.0.1:80'] + excludelist_paths = ['127.0.0.1', '192.168.0.1:80'] url = '127.0.0.1:8080' - disable_tracing = utils.disable_tracing_hostname(url, blacklist_paths) + disable_tracing = utils.disable_tracing_hostname( + url, excludelist_paths) self.assertFalse(disable_tracing) url = '127.0.0.1:80' - disable_tracing = utils.disable_tracing_hostname(url, blacklist_paths) + disable_tracing = utils.disable_tracing_hostname( + url, excludelist_paths) self.assertFalse(disable_tracing) def test_grpc_code_from_http_code(self):