You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We send logs to a collection service using PyZMQ. Ideally we'd be able to use the async bindings for this library but we're running into an issue where ddtrace is producing debug logs in a thread that does not have an asyncio event loop. Those logs are getting picked up by the PyZMQ's async log handler where it complains because there's no event loop for it to submit tasks to.
File".../lib/python3.10/site-packages/ddtrace/internal/logger.py", line147, inhandlesuper(DDLogger, self).handle(record)
File".../lib/python3.10/logging/__init__.py", line1634, inhandleself.callHandlers(record)
File".../lib/python3.10/logging/__init__.py", line1696, incallHandlershdlr.handle(record)
File".../lib/python3.10/logging/__init__.py", line968, inhandleself.emit(record)
File".../lib/python3.10/site-packages/zmq/log/handlers.py", line186, inemitself.socket.send_multipart([btopic, bmsg])
File".../lib/python3.10/site-packages/zmq/_future.py", line321, insend_multipartreturnself._add_send_event('send_multipart', msg=msg_parts, kwargs=kwargs)
File".../lib/python3.10/site-packages/zmq/_future.py", line509, in_add_send_eventf=futureorself._Future()
File".../lib/python3.10/asyncio/events.py", line656, inget_event_loopraiseRuntimeError('There is no current event loop in thread %r.'RuntimeError: Thereisnocurrenteventloopinthread'ddtrace.internal.remoteconfig._subscribers:RemoteConfigSubscriber'.
Thankfully, I don't think it would be a great deal of effort to modify PeriodicThread to operate using async primitives instead of thread-based in a backwards compatible way. Here's how I think it could work:
classPeriodicThread(threading.Thread):
def__init__(self, *args, **kwargs):
# same init logic as exists now...self.quit=forksafe.ResetObject(asyncio.Event)
defrun(self):
asyncio.run(self._run_async())
def_run_async(self):
whilenot (awaitself.quit.wait(self.interval)):
self._target()
ifself._on_shutdownisnotNone:
self._on_shutdown()
One could argue this is a problem with pyzmq since it would be ideal if we could manually specify what loop it should be sending its async tasks to. With that said, doing so would require a fair bit of care to ensure the internals of pyzmq are thread-safe. That is, a bunch of calls inside pyzmq which interact with the event loop would suddenly need to use loop.call_soon_threadsafe. Adding and testing that behavior to pyzmq seems pretty burdensome so I've chosen to post this issue here.
Summary of problem
We send logs to a collection service using PyZMQ. Ideally we'd be able to use the async bindings for this library but we're running into an issue where ddtrace is producing debug logs in a thread that does not have an asyncio event loop. Those logs are getting picked up by the PyZMQ's async log handler where it complains because there's no event loop for it to submit tasks to.
Thankfully, I don't think it would be a great deal of effort to modify
PeriodicThread
to operate using async primitives instead of thread-based in a backwards compatible way. Here's how I think it could work:One could argue this is a problem with
pyzmq
since it would be ideal if we could manually specify what loop it should be sending its async tasks to. With that said, doing so would require a fair bit of care to ensure the internals ofpyzmq
are thread-safe. That is, a bunch of calls insidepyzmq
which interact with the event loop would suddenly need to useloop.call_soon_threadsafe
. Adding and testing that behavior topyzmq
seems pretty burdensome so I've chosen to post this issue here.Which version of dd-trace-py are you using?
2.5.0
Which version of pip are you using?
Using Poetry 1.8.0
Which libraries and their versions are you using?
The library related to this problem is
pyzmq
.How can we reproduce your problem?
DEBUG
logszmq.log.PUBHandler
logging handler instance that uses azmq.asyncio.Context
.ddtrac.tracer()
What is the result that you get?
See traceback above
What is the result that you expected?
No errors.
The text was updated successfully, but these errors were encountered: