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

Remove opencensus telemetry #6439

Merged
merged 2 commits into from
Sep 13, 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/6439.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The deprecated support for enabling OpenCensus based telemetry has been removed.
QCoDeS will now warn if you try to enable OpenCensus based telemetry in the config.
Users are encouraged to roll out their own telemetry solution if they need it based
on OpenTelemetry. This also means that the `qcodes[opencensus]` install target has been removed.
The unused method `filter_out_telemetry_log_records` has been deprecated and will be removed in a future release.
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ docs = [
"qcodes_loop>=0.1.1", # legacy dataset import examples
"jinja2>=3.1.3", # transitive dependency pin due to cve in earlier version
]
opencensus = [
jenshnielsen marked this conversation as resolved.
Show resolved Hide resolved
"opencensus>=0.7.10",
"opencensus-ext-azure>=1.0.4, <2.0.0",
]
refactor = [
"libcst>=1.2.0"
]
Expand Down
76 changes: 5 additions & 71 deletions src/qcodes/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging
import logging.handlers
import os
import platform
import sys
from collections import OrderedDict
from contextlib import contextmanager
Expand Down Expand Up @@ -77,6 +76,10 @@
)


@deprecated(
"filter_out_telemetry_log_records is deprecated and will be removed",
category=QCoDeSDeprecationWarning,
)
def filter_out_telemetry_log_records(record: logging.LogRecord) -> bool:
"""
here we filter any message that is likely to be thrown from
Expand Down Expand Up @@ -212,72 +215,6 @@
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 ( # type: ignore[import-not-found]
AzureLogHandler,
)

global telemetry_handler

# The default_custom_dimensions will appear in the "customDimensions"
# field in Azure log analytics for every log message alongside any
# custom dimensions that message may have. All messages additionally come
# with custom dimensions fileName, level, lineNumber, module, and process
default_custom_dimensions = {"pythonExecutable": sys.executable}

class CustomDimensionsFilter(logging.Filter):
"""
Add application-wide properties to the customDimension field of
AzureLogHandler records
"""

def __init__(self, custom_dimensions: dict[str, str]):
super().__init__()
self.custom_dimensions = custom_dimensions

def filter(self, record: logging.LogRecord) -> bool:
"""
Add the default custom_dimensions into the current log record
"""
cdim = self.custom_dimensions.copy()
cdim.update(getattr(record, "custom_dimensions", {}))
record.custom_dimensions = cdim

return True

# Transport module of opencensus-ext-azure logs info 'transmission
# succeeded' which is also exported to azure if AzureLogHandler is
# in root_logger. The following lines stops that.
logging.getLogger("opencensus.ext.azure.common.transport").setLevel(logging.WARNING)

loc = qc.config.GUID_components.location
stat = qc.config.GUID_components.work_station

def callback_function(envelope: "Envelope") -> bool:
envelope.tags["ai.user.accountId"] = platform.node()
envelope.tags["ai.user.id"] = f"{loc:02x}-{stat:06x}"
return True

telemetry_handler = AzureLogHandler(
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))
telemetry_handler.setFormatter(get_formatter_for_telemetry())

return telemetry_handler


def start_logger() -> None:
"""
Start logging of messages passed through the python logging module.
Expand Down Expand Up @@ -312,7 +249,6 @@
console_handler = logging.StreamHandler()
console_handler.setLevel(qc.config.logger.console_level)
console_handler.setFormatter(get_formatter())
console_handler.addFilter(filter_out_telemetry_log_records)
root_logger.addHandler(console_handler)

# file
Expand All @@ -331,9 +267,7 @@
logging.captureWarnings(capture=True)

if qc.config.telemetry.enabled:
root_logger.addHandler(
_create_telemetry_handler() # pyright: ignore[reportDeprecated]
)
log.warning("Enabling telemetry in QCoDes config has no effect.")

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

View check run for this annotation

Codecov / codecov/patch

src/qcodes/logger/logger.py#L270

Added line #L270 was not covered by tests

log.info("QCoDes logger setup completed")

Expand Down
Loading