Skip to content

Commit

Permalink
Merge pull request #5278 from jenshnielsen/silence_open_telemetry
Browse files Browse the repository at this point in the history
Silence log messages related to opentelemetry upload to azure
  • Loading branch information
jenshnielsen committed Jul 19, 2023
1 parent 373b80e commit 2e78182
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
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 @@ -66,15 +66,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

0 comments on commit 2e78182

Please sign in to comment.