Skip to content

Commit

Permalink
Specify name for worker threads for logging and metrics (#2724)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen authored Jun 2, 2022
1 parent 1dd1855 commit a31dcc3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2714](https://github.com/open-telemetry/opentelemetry-python/pull/2714))
- narrow protobuf dependencies to exclude protobuf >= 4
([#2720](https://github.com/open-telemetry/opentelemetry-python/pull/2720))
- Specify worker thread names
([#2724](https://github.com/open-telemetry/opentelemetry-python/pull/2724))
- Loosen dependency on `backoff` for newer Python versions
([#2726](https://github.com/open-telemetry/opentelemetry-python/pull/2726))
- fix: frozenset object has no attribute items
Expand Down
12 changes: 10 additions & 2 deletions opentelemetry-sdk/src/opentelemetry/sdk/_logs/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def __init__(
self._max_export_batch_size = max_export_batch_size
self._export_timeout_millis = export_timeout_millis
self._queue = collections.deque() # type: Deque[LogData]
self._worker_thread = threading.Thread(target=self.worker, daemon=True)
self._worker_thread = threading.Thread(
name="OtelBatchLogProcessor",
target=self.worker,
daemon=True,
)
self._condition = threading.Condition(threading.Lock())
self._shutdown = False
self._flush_request = None # type: Optional[_FlushRequest]
Expand All @@ -164,7 +168,11 @@ def __init__(
def _at_fork_reinit(self):
self._condition = threading.Condition(threading.Lock())
self._queue.clear()
self._worker_thread = threading.Thread(target=self.worker, daemon=True)
self._worker_thread = threading.Thread(
name="OtelBatchLogProcessor",
target=self.worker,
daemon=True,
)
self._worker_thread.start()

def worker(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,23 @@ def __init__(
self._shutdown = False
self._shutdown_event = Event()
self._shutdown_once = Once()
self._daemon_thread = Thread(target=self._ticker, daemon=True)
self._daemon_thread = Thread(
name="OtelPeriodicExportingMetricReader",
target=self._ticker,
daemon=True,
)
self._daemon_thread.start()
if hasattr(os, "register_at_fork"):
os.register_at_fork(
after_in_child=self._at_fork_reinit
) # pylint: disable=protected-access

def _at_fork_reinit(self):
self._daemon_thread = Thread(target=self._ticker, daemon=True)
self._daemon_thread = Thread(
name="OtelPeriodicExportingMetricReader",
target=self._ticker,
daemon=True,
)
self._daemon_thread.start()

def _ticker(self) -> None:
Expand Down

0 comments on commit a31dcc3

Please sign in to comment.