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 3 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
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",
jenshnielsen marked this conversation as resolved.
Show resolved Hide resolved
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
Loading