Skip to content

Commit

Permalink
Merge pull request microsoft#5991 from jenshnielsen/opencensus_deprecate
Browse files Browse the repository at this point in the history
Deprecate opencensus integration
  • Loading branch information
jenshnielsen authored Apr 22, 2024
2 parents 1f6b4fa + d4d8eee commit 0ee413d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
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 @@ 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"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 0ee413d

Please sign in to comment.