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

Silence log messages related to opentelemetry upload to azure #5278

Merged
merged 3 commits into from
Jul 19, 2023
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
3 changes: 3 additions & 0 deletions docs/changes/newsfragments/5278.improved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Very noisy log messages from `azure.monitor.opentelemetry.exporter` are now
by default filtered and not shown in the console logger. This matches the
behavior of the OpenCensus exporter.
6 changes: 5 additions & 1 deletion qcodes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Set up the main qcodes namespace."""

# flake8: noqa (we don't need the "<...> imported but unused" error)
# ruff: noqa: F401, E402
# This module still contains a lot of short hand imports
# since these imports are discouraged and they are officially
# added elsewhere under their respective submodules we cannot add
# them to __all__ here so silence the warning.

# config
import warnings
Expand Down
12 changes: 9 additions & 3 deletions qcodes/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,21 @@

_opencensus_filter = logging.Filter(name="opencensus")
_urllib3_connection_filter = logging.Filter(name="urllib3.connection")
_azure_monitor_opentelemetry_exporter_filter = logging.Filter(
name="azure.monitor.opentelemetry.exporter"
)


def filter_out_telemetry_log_records(record: logging.LogRecord) -> bool:
"""
here we filter any message that is likely to be thrown from
opencensus so it is not shown in the user console
opencensus/opentelemetry so it is not shown in the user console
"""
return (not _opencensus_filter.filter(record)
and not _urllib3_connection_filter.filter(record))
return (
not _opencensus_filter.filter(record)
and not _urllib3_connection_filter.filter(record)
and not _azure_monitor_opentelemetry_exporter_filter
)


def get_formatter() -> logging.Formatter:
Expand Down