Skip to content

Commit

Permalink
Add more docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed May 30, 2021
1 parent f1ce8f9 commit d34c64d
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/logs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
class OTELLogRecord:
"""A OTELLogRecord instance represents an event being logged.
OTELLogRecord instances are created every time something is logged.
They contain all the information pertinent to the event being logged.
OTELLogRecord instances are created and emitted via `LogEmitter`
every time something is logged. They contain all the information
pertinent to the event being logged.
"""

def __init__(
Expand Down Expand Up @@ -119,9 +120,16 @@ def __init__(


class LogProcessor(abc.ABC):
"""Interface to hook the log record emitting action.
Log processors can be registered directly using
:func:`LogEmitterProvider.add_log_processor` and they are invoked
in the same order as they were registered.
"""

@abc.abstractmethod
def emit(self, log_data: LogData):
"""Emits the LogData"""
"""Emits the `LogData`"""

@abc.abstractmethod
def shutdown(self):
Expand All @@ -142,6 +150,12 @@ def force_flush(self, timeout_millis: int = 30000):


class SynchronousMultiLogProcessor(LogProcessor):
"""Implementation of class:`LogProcessor` that forwards all received
events to a list of log processors sequentially.
The underlying log processors are called in sequential order as they were
added.
"""
def __init__(self):
# use a tuple to avoid race conditions when adding a new log and
# iterating through it on "emit".
Expand Down Expand Up @@ -187,6 +201,17 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:


class ConcurrentMultiLogProcessor(LogProcessor):
"""Implementation of :class:`LogProcessor` that forwards all received
events to a list of log processors in parallel.
Calls to the underlying log processors are forwarded in parallel by
submitting them to a thread pool executor and waiting until each log
processor finished its work.
Args:
num_threads: The number of threads managed by the thread pool executor
and thus defining how many log processors can work in parallel.
"""
def __init__(self, max_workers: int = 2):
# use a tuple to avoid race conditions when adding a new log and
# iterating through it on "emit".
Expand Down Expand Up @@ -250,6 +275,10 @@ def force_flush(self, timeout_millis: int = 30000):


class LogEmitter(logging.Handler):
"""
A handler class which emits formatted logging records in
OpenTelemetry manner.
"""
def __init__(
self,
resource: Resource,
Expand Down

0 comments on commit d34c64d

Please sign in to comment.