Skip to content

Commit 0ee413d

Browse files
authored
Merge pull request #5991 from jenshnielsen/opencensus_deprecate
Deprecate opencensus integration
2 parents 1f6b4fa + d4d8eee commit 0ee413d

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
QCoDeS no longer installs opencensus and opencensus-ext-azure are no longer installed by default and opencensus integration is deprecated.
2+
This means that the option ``qcodes.config.telemetry.enabled`` to ``True`` is deprecated. For the time being opencensus and opencensus-ext-azure
3+
can be installed by installing QCoDeS with the opencensus option e.g. ``pip install qcodes[opencensus]``. We however, recommend that any use
4+
of this telemetry integration is replaced by the use of OpenTelemetry. QCoDeS will not include any telemetry integration but the codebase
5+
has been instrumented using OpenTelemetry spans and python log messages enabling any user to collect telemetry if they should so wish.

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ dependencies = [
3333
"jsonschema>=4.9.0",
3434
"matplotlib>=3.3.3",
3535
"numpy>=1.21.0",
36-
"opencensus>=0.7.10",
37-
"opencensus-ext-azure>=1.0.4, <2.0.0",
3836
"packaging>=20.0",
3937
"pandas>=1.2.0",
4038
"pyarrow>=11.0.0", # will become a requirement of pandas. Installing explicitly silences a warning
@@ -58,7 +56,6 @@ dependencies = [
5856
"tornado>=6.3.3",
5957
"ipython>=8.10.0",
6058
"pillow>=9.0.0",
61-
"rsa>=4.7",
6259
]
6360

6461
dynamic = ["version"]
@@ -118,6 +115,10 @@ docs = [
118115
"qcodes_loop>=0.1.1", # legacy dataset import examples
119116
"jinja2>=3.1.3", # transitive dependency pin due to cve in earlier version
120117
]
118+
opencensus = [
119+
"opencensus>=0.7.10",
120+
"opencensus-ext-azure>=1.0.4, <2.0.0",
121+
]
121122

122123
[project.scripts]
123124
qcodes-monitor = "qcodes.monitor.monitor:main"

requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ idna==3.7
117117
imagesize==1.4.1
118118
# via sphinx
119119
importlib-metadata==6.11.0
120-
# via
121-
# dask
122-
# opentelemetry-api
120+
# via opentelemetry-api
123121
incremental==22.10.0
124122
# via towncrier
125123
iniconfig==2.0.0
@@ -249,6 +247,7 @@ packaging==24.0
249247
# dask
250248
# h5netcdf
251249
# ipykernel
250+
# lazy-loader
252251
# matplotlib
253252
# msal-extensions
254253
# nbconvert
@@ -282,10 +281,13 @@ portalocker==2.8.2
282281
# via msal-extensions
283282
prompt-toolkit==3.0.43
284283
# via ipython
284+
proto-plus==1.23.0
285+
# via google-api-core
285286
protobuf==4.25.3
286287
# via
287288
# google-api-core
288289
# googleapis-common-protos
290+
# proto-plus
289291
psutil==5.9.8
290292
# via
291293
# ipykernel

src/qcodes/logger/logger.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import io
99
import json
1010
import logging
11-
12-
# logging.handlers is not imported by logging. This extra import is necessary
1311
import logging.handlers
1412
import os
1513
import platform
@@ -18,26 +16,25 @@
1816
from contextlib import contextmanager
1917
from copy import copy
2018
from datetime import datetime
21-
from typing import TYPE_CHECKING, Optional, Union
19+
from typing import TYPE_CHECKING, Any, Optional, Union
20+
21+
from typing_extensions import deprecated
2222

2323
if TYPE_CHECKING:
2424
from collections.abc import Iterator, Sequence
2525
from types import TracebackType
2626

27-
from opencensus.ext.azure.common.protocol import ( # type: ignore[import-untyped]
28-
Envelope,
29-
)
30-
from opencensus.ext.azure.log_exporter import ( # type: ignore[import-untyped]
31-
AzureLogHandler,
32-
)
33-
3427
import qcodes as qc
3528
from qcodes.utils import (
29+
QCoDeSDeprecationWarning,
3630
get_all_installed_package_versions,
3731
get_qcodes_user_path,
3832
is_qcodes_installed_editably,
3933
)
4034

35+
AzureLogHandler = Any
36+
Envelope = Any
37+
4138
log: logging.Logger = logging.getLogger(__name__)
4239

4340
LevelType = Union[int, str]
@@ -201,11 +198,17 @@ def flush_telemetry_traces() -> None:
201198
telemetry_handler.flush()
202199

203200

201+
@deprecated(
202+
"OpenCensus integration is deprecated. Please use your own telemetry integration as needed, we recommend OpenTelemetry",
203+
category=QCoDeSDeprecationWarning,
204+
)
204205
def _create_telemetry_handler() -> "AzureLogHandler":
205206
"""
206207
Configure, create, and return the telemetry handler
207208
"""
208-
from opencensus.ext.azure.log_exporter import AzureLogHandler
209+
from opencensus.ext.azure.log_exporter import ( # type: ignore[import-not-found]
210+
AzureLogHandler,
211+
)
209212
global telemetry_handler
210213

211214
# The default_custom_dimensions will appear in the "customDimensions"
@@ -251,6 +254,7 @@ def callback_function(envelope: "Envelope") -> bool:
251254
connection_string=f"InstrumentationKey="
252255
f"{qc.config.telemetry.instrumentation_key}"
253256
)
257+
assert telemetry_handler is not None
254258
telemetry_handler.add_telemetry_processor(callback_function)
255259
telemetry_handler.setLevel(logging.INFO)
256260
telemetry_handler.addFilter(CustomDimensionsFilter(default_custom_dimensions))
@@ -312,7 +316,9 @@ def start_logger() -> None:
312316
logging.captureWarnings(capture=True)
313317

314318
if qc.config.telemetry.enabled:
315-
root_logger.addHandler(_create_telemetry_handler())
319+
root_logger.addHandler(
320+
_create_telemetry_handler() # pyright: ignore[reportDeprecated]
321+
)
316322

317323
log.info("QCoDes logger setup completed")
318324

0 commit comments

Comments
 (0)