From 69c9e39bc98077ddafdad6946d22fe582aee9261 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Tue, 15 Mar 2022 12:18:56 -0700 Subject: [PATCH] Rename OTLPHandler -> LoggingHandler (#2528) --- CHANGELOG.md | 4 ++-- docs/examples/logs/example.py | 4 ++-- .../sdk/_configuration/__init__.py | 4 ++-- .../src/opentelemetry/sdk/_logs/__init__.py | 5 +++-- opentelemetry-sdk/tests/logs/test_export.py | 22 +++++++++---------- opentelemetry-sdk/tests/logs/test_handler.py | 6 ++--- .../tests/logs/test_multi_log_prcessor.py | 4 ++-- opentelemetry-sdk/tests/test_configurator.py | 4 ++-- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91f44823346..fbd4575bae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix incorrect installation of some exporter “convenience” packages into “site-packages/src” ([#2525](https://github.com/open-telemetry/opentelemetry-python/pull/2525)) +- Change OTLPHandler to LoggingHandler + ([#2528](https://github.com/open-telemetry/opentelemetry-python/pull/2528)) ## [1.10.0-0.29b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.10.0-0.29b0) - 2022-03-10 - - - Docs rework: [non-API docs are moving](https://github.com/open-telemetry/opentelemetry-python/issues/2172) to [opentelemetry.io](https://opentelemetry.io). For details, including a list of diff --git a/docs/examples/logs/example.py b/docs/examples/logs/example.py index 33879fb2181..28fca75e7c4 100644 --- a/docs/examples/logs/example.py +++ b/docs/examples/logs/example.py @@ -6,7 +6,7 @@ ) from opentelemetry.sdk._logs import ( LogEmitterProvider, - OTLPHandler, + LoggingHandler, set_log_emitter_provider, ) from opentelemetry.sdk._logs.export import BatchLogProcessor @@ -35,7 +35,7 @@ exporter = OTLPLogExporter(insecure=True) log_emitter_provider.add_log_processor(BatchLogProcessor(exporter)) log_emitter = log_emitter_provider.get_log_emitter(__name__, "0.1") -handler = OTLPHandler(level=logging.NOTSET, log_emitter=log_emitter) +handler = LoggingHandler(level=logging.NOTSET, log_emitter=log_emitter) # Attach OTLP handler to root logger logging.getLogger().addHandler(handler) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 124573c2543..efa6f31f894 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -32,7 +32,7 @@ ) from opentelemetry.sdk._logs import ( LogEmitterProvider, - OTLPHandler, + LoggingHandler, set_log_emitter_provider, ) from opentelemetry.sdk._logs.export import BatchLogProcessor, LogExporter @@ -114,7 +114,7 @@ def _init_logging( ) log_emitter = provider.get_log_emitter(__name__) - handler = OTLPHandler(level=logging.NOTSET, log_emitter=log_emitter) + handler = LoggingHandler(level=logging.NOTSET, log_emitter=log_emitter) logging.getLogger().addHandler(handler) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py index 1de44712e8d..d13c8c59ea3 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py @@ -303,9 +303,10 @@ def force_flush(self, timeout_millis: int = 30000) -> bool: ) -class OTLPHandler(logging.Handler): +class LoggingHandler(logging.Handler): """A handler class which writes logging records, in OTLP format, to - a network destination or file. + a network destination or file. Supports signals from the `logging` module. + https://docs.python.org/3/library/logging.html """ def __init__( diff --git a/opentelemetry-sdk/tests/logs/test_export.py b/opentelemetry-sdk/tests/logs/test_export.py index 95c132769f7..f398fe3fd98 100644 --- a/opentelemetry-sdk/tests/logs/test_export.py +++ b/opentelemetry-sdk/tests/logs/test_export.py @@ -26,8 +26,8 @@ from opentelemetry.sdk._logs import ( LogData, LogEmitterProvider, + LoggingHandler, LogRecord, - OTLPHandler, ) from opentelemetry.sdk._logs.export import ( BatchLogProcessor, @@ -56,7 +56,7 @@ def test_simple_log_processor_default_level(self): log_emitter_provider.add_log_processor(SimpleLogProcessor(exporter)) logger = logging.getLogger("default_level") - logger.addHandler(OTLPHandler(log_emitter=log_emitter)) + logger.addHandler(LoggingHandler(log_emitter=log_emitter)) logger.warning("Something is wrong") finished_logs = exporter.get_finished_logs() @@ -77,7 +77,7 @@ def test_simple_log_processor_custom_level(self): logger = logging.getLogger("custom_level") logger.setLevel(logging.ERROR) - logger.addHandler(OTLPHandler(log_emitter=log_emitter)) + logger.addHandler(LoggingHandler(log_emitter=log_emitter)) logger.warning("Warning message") logger.debug("Debug message") @@ -107,7 +107,7 @@ def test_simple_log_processor_trace_correlation(self): log_emitter_provider.add_log_processor(SimpleLogProcessor(exporter)) logger = logging.getLogger("trace_correlation") - logger.addHandler(OTLPHandler(log_emitter=log_emitter)) + logger.addHandler(LoggingHandler(log_emitter=log_emitter)) logger.warning("Warning message") finished_logs = exporter.get_finished_logs() @@ -145,7 +145,7 @@ def test_simple_log_processor_shutdown(self): log_emitter_provider.add_log_processor(SimpleLogProcessor(exporter)) logger = logging.getLogger("shutdown") - logger.addHandler(OTLPHandler(log_emitter=log_emitter)) + logger.addHandler(LoggingHandler(log_emitter=log_emitter)) logger.warning("Something is wrong") finished_logs = exporter.get_finished_logs() @@ -172,7 +172,7 @@ def test_emit_call_log_record(self): emitter = provider.get_log_emitter(__name__) logger = logging.getLogger("emit_call") - logger.addHandler(OTLPHandler(log_emitter=emitter)) + logger.addHandler(LoggingHandler(log_emitter=emitter)) logger.error("error") self.assertEqual(log_processor.emit.call_count, 1) @@ -186,7 +186,7 @@ def test_shutdown(self): emitter = provider.get_log_emitter(__name__) logger = logging.getLogger("shutdown") - logger.addHandler(OTLPHandler(log_emitter=emitter)) + logger.addHandler(LoggingHandler(log_emitter=emitter)) logger.warning("warning message: %s", "possible upcoming heatwave") logger.error("Very high rise in temperatures across the globe") @@ -219,7 +219,7 @@ def test_force_flush(self): emitter = provider.get_log_emitter(__name__) logger = logging.getLogger("force_flush") - logger.addHandler(OTLPHandler(log_emitter=emitter)) + logger.addHandler(LoggingHandler(log_emitter=emitter)) logger.critical("Earth is burning") log_processor.force_flush() @@ -238,7 +238,7 @@ def test_log_processor_too_many_logs(self): emitter = provider.get_log_emitter(__name__) logger = logging.getLogger("many_logs") - logger.addHandler(OTLPHandler(log_emitter=emitter)) + logger.addHandler(LoggingHandler(log_emitter=emitter)) for log_no in range(1000): logger.critical("Log no: %s", log_no) @@ -256,7 +256,7 @@ def test_with_multiple_threads(self): emitter = provider.get_log_emitter(__name__) logger = logging.getLogger("threads") - logger.addHandler(OTLPHandler(log_emitter=emitter)) + logger.addHandler(LoggingHandler(log_emitter=emitter)) def bulk_log_and_flush(num_logs): for _ in range(num_logs): @@ -291,7 +291,7 @@ def test_batch_log_processor_fork(self): emitter = provider.get_log_emitter(__name__) logger = logging.getLogger("test-fork") - logger.addHandler(OTLPHandler(log_emitter=emitter)) + logger.addHandler(LoggingHandler(log_emitter=emitter)) logger.critical("yolo") time.sleep(0.5) # give some time for the exporter to upload diff --git a/opentelemetry-sdk/tests/logs/test_handler.py b/opentelemetry-sdk/tests/logs/test_handler.py index d7942f912b8..d80356c4540 100644 --- a/opentelemetry-sdk/tests/logs/test_handler.py +++ b/opentelemetry-sdk/tests/logs/test_handler.py @@ -17,19 +17,19 @@ from unittest.mock import Mock from opentelemetry.sdk import trace -from opentelemetry.sdk._logs import LogEmitter, OTLPHandler +from opentelemetry.sdk._logs import LogEmitter, LoggingHandler from opentelemetry.sdk._logs.severity import SeverityNumber from opentelemetry.trace import INVALID_SPAN_CONTEXT def get_logger(level=logging.NOTSET, log_emitter=None): logger = logging.getLogger(__name__) - handler = OTLPHandler(level=level, log_emitter=log_emitter) + handler = LoggingHandler(level=level, log_emitter=log_emitter) logger.addHandler(handler) return logger -class TestOTLPHandler(unittest.TestCase): +class TestLoggingHandler(unittest.TestCase): def test_handler_default_log_level(self): emitter_mock = Mock(spec=LogEmitter) logger = get_logger(log_emitter=emitter_mock) diff --git a/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py b/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py index e55124edcc7..6a5838231b9 100644 --- a/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py +++ b/opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py @@ -24,9 +24,9 @@ from opentelemetry.sdk._logs import ( ConcurrentMultiLogProcessor, LogEmitterProvider, + LoggingHandler, LogProcessor, LogRecord, - OTLPHandler, SynchronousMultiLogProcessor, ) from opentelemetry.sdk._logs.severity import SeverityNumber @@ -58,7 +58,7 @@ class TestLogProcessor(unittest.TestCase): def test_log_processor(self): provider = LogEmitterProvider() log_emitter = provider.get_log_emitter(__name__) - handler = OTLPHandler(log_emitter=log_emitter) + handler = LoggingHandler(log_emitter=log_emitter) logs_list_1 = [] processor1 = AnotherLogProcessor(Mock(), logs_list_1) diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index e0dd1e7b4b3..42d3859f5e2 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -30,7 +30,7 @@ _init_logging, _init_tracing, ) -from opentelemetry.sdk._logs import OTLPHandler +from opentelemetry.sdk._logs import LoggingHandler from opentelemetry.sdk._logs.export import ConsoleLogExporter from opentelemetry.sdk._metrics.export import ConsoleMetricExporter from opentelemetry.sdk.resources import SERVICE_NAME, Resource @@ -242,7 +242,7 @@ def tearDown(self): root_logger.handlers = [ handler for handler in root_logger.handlers - if not isinstance(handler, OTLPHandler) + if not isinstance(handler, LoggingHandler) ] def test_logging_init_empty(self):