1717from . import loader
1818from . import protos
1919
20+ from .logging import error_logger , logger
21+
2022
2123class DispatcherMeta (type ):
2224
@@ -62,8 +64,6 @@ def __init__(self, loop, host, port, worker_id, request_id,
6264 self ._grpc_thread = threading .Thread (
6365 name = 'grpc-thread' , target = self .__poll_grpc )
6466
65- self ._logger = logging .getLogger ('azure.functions_worker' )
66-
6767 @classmethod
6868 async def connect (cls , host , port , worker_id , request_id ,
6969 connect_timeout , max_msg_len = None ):
@@ -72,6 +72,7 @@ async def connect(cls, host, port, worker_id, request_id,
7272 connect_timeout , max_msg_len )
7373 disp ._grpc_thread .start ()
7474 await disp ._grpc_connected_fut
75+ logger .info ('Successfully opened gRPC channel to %s:%s' , host , port )
7576 return disp
7677
7778 async def dispatch_forever (self ):
@@ -186,14 +187,16 @@ async def _dispatch_grpc_request(self, request):
186187 # Don't crash on unknown messages. Some of them can be ignored;
187188 # and if something goes really wrong the host can always just
188189 # kill the worker's process.
189- self . _logger .error (
190+ logger .error (
190191 f'unknown StreamingMessage content type { content_type } ' )
191192 return
192193
193194 resp = await request_handler (request )
194195 self ._grpc_resp_queue .put_nowait (resp )
195196
196197 async def _handle__worker_init_request (self , req ):
198+ logger .info ('Received WorkerInitRequest, request ID %s' ,
199+ self .request_id )
197200 return protos .StreamingMessage (
198201 request_id = self .request_id ,
199202 worker_init_response = protos .WorkerInitResponse (
@@ -204,6 +207,9 @@ async def _handle__function_load_request(self, req):
204207 func_request = req .function_load_request
205208 function_id = func_request .function_id
206209
210+ logger .info ('Received FunctionLoadRequest, request ID: %s, '
211+ 'function ID: %s' , self .request_id , function_id )
212+
207213 try :
208214 func = loader .load_function (
209215 func_request .metadata .name ,
@@ -214,6 +220,10 @@ async def _handle__function_load_request(self, req):
214220 self ._functions .add_function (
215221 function_id , func , func_request .metadata )
216222
223+ logger .info ('Successfully processed FunctionLoadRequest, '
224+ 'request ID: %s, function ID: %s' ,
225+ self .request_id , function_id )
226+
217227 return protos .StreamingMessage (
218228 request_id = self .request_id ,
219229 function_load_response = protos .FunctionLoadResponse (
@@ -242,6 +252,10 @@ async def _handle__invocation_request(self, req):
242252 assert isinstance (current_task , ContextEnabledTask )
243253 current_task .set_azure_invocation_id (invocation_id )
244254
255+ logger .info ('Received FunctionInvocationRequest, request ID: %s, '
256+ 'function ID: %s, invocation ID: %s' ,
257+ self .request_id , function_id , invocation_id )
258+
245259 try :
246260 fi : functions .FunctionInfo = self ._functions .get_function (
247261 function_id )
@@ -303,6 +317,10 @@ async def _handle__invocation_request(self, req):
303317 fi .return_type .binding_name , call_result ,
304318 pytype = fi .return_type .pytype )
305319
320+ logger .info ('Successfully processed FunctionInvocationRequest, '
321+ 'request ID: %s, function ID: %s, invocation ID: %s' ,
322+ self .request_id , function_id , invocation_id )
323+
306324 return protos .StreamingMessage (
307325 request_id = self .request_id ,
308326 invocation_response = protos .InvocationResponse (
@@ -371,14 +389,17 @@ def gen(resp_queue):
371389 if ex is grpc_req_stream :
372390 # Yes, this is how grpc_req_stream iterator exits.
373391 return
392+ error_logger .exception ('unhandled error in gRPC thread' )
374393 raise
375394
376395
377396class AsyncLoggingHandler (logging .Handler ):
378397
379398 def emit (self , record ):
380- msg = self .format (record )
381- Dispatcher .current ._on_logging (record , msg )
399+ if not record .name .startswith ('azure.functions_worker' ):
400+ # Skip worker system logs
401+ msg = self .format (record )
402+ Dispatcher .current ._on_logging (record , msg )
382403
383404
384405class ContextEnabledTask (asyncio .Task ):
0 commit comments