diff --git a/docs/changes/newsfragments/5991.breaking b/docs/changes/newsfragments/5991.breaking new file mode 100644 index 00000000000..391494e8f6c --- /dev/null +++ b/docs/changes/newsfragments/5991.breaking @@ -0,0 +1,5 @@ +QCoDeS no longer installs opencensus and opencensus-ext-azure are no longer installed by default and opencensus integration is deprecated. +This means that the option ``qcodes.config.telemetry.enabled`` to ``True`` is deprecated. For the time being opencensus and opencensus-ext-azure +can be installed by installing QCoDeS with the opencensus option e.g. ``pip install qcodes[opencensus]``. We however, recommend that any use +of this telemetry integration is replaced by the use of OpenTelemetry. QCoDeS will not include any telemetry integration but the codebase +has been instrumented using OpenTelemetry spans and python log messages enabling any user to collect telemetry if they should so wish. diff --git a/pyproject.toml b/pyproject.toml index 9cf5f3084e0..b28f25fad2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,8 +33,6 @@ dependencies = [ "jsonschema>=4.9.0", "matplotlib>=3.3.3", "numpy>=1.21.0", - "opencensus>=0.7.10", - "opencensus-ext-azure>=1.0.4, <2.0.0", "packaging>=20.0", "pandas>=1.2.0", "pyarrow>=11.0.0", # will become a requirement of pandas. Installing explicitly silences a warning @@ -58,7 +56,6 @@ dependencies = [ "tornado>=6.3.3", "ipython>=8.10.0", "pillow>=9.0.0", - "rsa>=4.7", ] dynamic = ["version"] @@ -118,6 +115,10 @@ docs = [ "qcodes_loop>=0.1.1", # legacy dataset import examples "jinja2>=3.1.3", # transitive dependency pin due to cve in earlier version ] +opencensus = [ + "opencensus>=0.7.10", + "opencensus-ext-azure>=1.0.4, <2.0.0", +] [project.scripts] qcodes-monitor = "qcodes.monitor.monitor:main" diff --git a/requirements.txt b/requirements.txt index 98b578eef87..2ed5a3eb597 100644 --- a/requirements.txt +++ b/requirements.txt @@ -117,9 +117,7 @@ idna==3.7 imagesize==1.4.1 # via sphinx importlib-metadata==6.11.0 - # via - # dask - # opentelemetry-api + # via opentelemetry-api incremental==22.10.0 # via towncrier iniconfig==2.0.0 @@ -249,6 +247,7 @@ packaging==24.0 # dask # h5netcdf # ipykernel + # lazy-loader # matplotlib # msal-extensions # nbconvert @@ -282,10 +281,13 @@ portalocker==2.8.2 # via msal-extensions prompt-toolkit==3.0.43 # via ipython +proto-plus==1.23.0 + # via google-api-core protobuf==4.25.3 # via # google-api-core # googleapis-common-protos + # proto-plus psutil==5.9.8 # via # ipykernel diff --git a/src/qcodes/logger/logger.py b/src/qcodes/logger/logger.py index 66d4c25a622..dc9463173b7 100644 --- a/src/qcodes/logger/logger.py +++ b/src/qcodes/logger/logger.py @@ -8,8 +8,6 @@ import io import json import logging - -# logging.handlers is not imported by logging. This extra import is necessary import logging.handlers import os import platform @@ -18,26 +16,25 @@ from contextlib import contextmanager from copy import copy from datetime import datetime -from typing import TYPE_CHECKING, Optional, Union +from typing import TYPE_CHECKING, Any, Optional, Union + +from typing_extensions import deprecated if TYPE_CHECKING: from collections.abc import Iterator, Sequence from types import TracebackType - from opencensus.ext.azure.common.protocol import ( # type: ignore[import-untyped] - Envelope, - ) - from opencensus.ext.azure.log_exporter import ( # type: ignore[import-untyped] - AzureLogHandler, - ) - import qcodes as qc from qcodes.utils import ( + QCoDeSDeprecationWarning, get_all_installed_package_versions, get_qcodes_user_path, is_qcodes_installed_editably, ) +AzureLogHandler = Any +Envelope = Any + log: logging.Logger = logging.getLogger(__name__) LevelType = Union[int, str] @@ -201,11 +198,17 @@ def flush_telemetry_traces() -> None: telemetry_handler.flush() +@deprecated( + "OpenCensus integration is deprecated. Please use your own telemetry integration as needed, we recommend OpenTelemetry", + category=QCoDeSDeprecationWarning, +) def _create_telemetry_handler() -> "AzureLogHandler": """ Configure, create, and return the telemetry handler """ - from opencensus.ext.azure.log_exporter import AzureLogHandler + from opencensus.ext.azure.log_exporter import ( # type: ignore[import-not-found] + AzureLogHandler, + ) global telemetry_handler # The default_custom_dimensions will appear in the "customDimensions" @@ -251,6 +254,7 @@ def callback_function(envelope: "Envelope") -> bool: connection_string=f"InstrumentationKey=" f"{qc.config.telemetry.instrumentation_key}" ) + assert telemetry_handler is not None telemetry_handler.add_telemetry_processor(callback_function) telemetry_handler.setLevel(logging.INFO) telemetry_handler.addFilter(CustomDimensionsFilter(default_custom_dimensions)) @@ -312,7 +316,9 @@ def start_logger() -> None: logging.captureWarnings(capture=True) if qc.config.telemetry.enabled: - root_logger.addHandler(_create_telemetry_handler()) + root_logger.addHandler( + _create_telemetry_handler() # pyright: ignore[reportDeprecated] + ) log.info("QCoDes logger setup completed")