Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate opencensus integration #5991

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changes/newsfragments/5991.breaking
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,7 +56,6 @@ dependencies = [
"tornado>=6.3.3",
"ipython>=8.10.0",
"pillow>=9.0.0",
"rsa>=4.7",
]

dynamic = ["version"]
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -249,6 +247,7 @@ packaging==24.0
# dask
# h5netcdf
# ipykernel
# lazy-loader
# matplotlib
# msal-extensions
# nbconvert
Expand Down Expand Up @@ -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
Expand Down
30 changes: 18 additions & 12 deletions src/qcodes/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -201,11 +198,17 @@
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]

Check warning on line 209 in src/qcodes/logger/logger.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/logger/logger.py#L209

Added line #L209 was not covered by tests
AzureLogHandler,
)
global telemetry_handler

# The default_custom_dimensions will appear in the "customDimensions"
Expand Down Expand Up @@ -251,6 +254,7 @@
connection_string=f"InstrumentationKey="
f"{qc.config.telemetry.instrumentation_key}"
)
assert telemetry_handler is not None

Check warning on line 257 in src/qcodes/logger/logger.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/logger/logger.py#L257

Added line #L257 was not covered by tests
telemetry_handler.add_telemetry_processor(callback_function)
telemetry_handler.setLevel(logging.INFO)
telemetry_handler.addFilter(CustomDimensionsFilter(default_custom_dimensions))
Expand Down Expand Up @@ -312,7 +316,9 @@
logging.captureWarnings(capture=True)

if qc.config.telemetry.enabled:
root_logger.addHandler(_create_telemetry_handler())
root_logger.addHandler(

Check warning on line 319 in src/qcodes/logger/logger.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/logger/logger.py#L319

Added line #L319 was not covered by tests
_create_telemetry_handler() # pyright: ignore[reportDeprecated]
)

log.info("QCoDes logger setup completed")

Expand Down
Loading