Skip to content

Commit

Permalink
Rename OTLPHandler -> LoggingHandler (#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Mar 15, 2022
1 parent f5520c7 commit 69c9e39
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/logs/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)
from opentelemetry.sdk._logs import (
LogEmitterProvider,
OTLPHandler,
LoggingHandler,
set_log_emitter_provider,
)
from opentelemetry.sdk._logs.export import BatchLogProcessor
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)
from opentelemetry.sdk._logs import (
LogEmitterProvider,
OTLPHandler,
LoggingHandler,
set_log_emitter_provider,
)
from opentelemetry.sdk._logs.export import BatchLogProcessor, LogExporter
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions opentelemetry-sdk/src/opentelemetry/sdk/_logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
22 changes: 11 additions & 11 deletions opentelemetry-sdk/tests/logs/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from opentelemetry.sdk._logs import (
LogData,
LogEmitterProvider,
LoggingHandler,
LogRecord,
OTLPHandler,
)
from opentelemetry.sdk._logs.export import (
BatchLogProcessor,
Expand Down Expand Up @@ -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()
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/tests/logs/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/tests/logs/test_multi_log_prcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from opentelemetry.sdk._logs import (
ConcurrentMultiLogProcessor,
LogEmitterProvider,
LoggingHandler,
LogProcessor,
LogRecord,
OTLPHandler,
SynchronousMultiLogProcessor,
)
from opentelemetry.sdk._logs.severity import SeverityNumber
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 69c9e39

Please sign in to comment.