Azure function fails but the reason is not defined in the log

Daria Lisita 0 Reputation points
2023-07-04T19:31:57.37+00:00

Hello, I have a couple of issues with azure function (Python)

My function extracts data from SQL DB and put it to the excel file at the SharePoint.

During testing I use manual triggering in Postman. When function is triggered I see that function is funning from Logs Tab, but there is now mentioning about the function is triggered at the Monitor Tab and in Application insights doesn't mention that function was fired up. Only Logs (Traces table) shows that there is any activity. For example, Invocation ID - 8b47a9eb-022d-4239-b5c0-d6e9d144a99c didn´t return any output to monitoring tab, no error, no success.

During the function activity function reaches step to create excel file from DataFrame and to save it to the SharePoint. I use this Python code to complete this task:

for df_field, df_splited in sqldb_df.groupby('field'):
    file_name = '{0}_{1}_{2}_{3}.xlsx'.format(df_field, current_year, related_month, datetime_string)        
	target_folder = sharepoint_context.web.get_folder_by_server_relative_url(relative_url)      
	# Create a buffer object        
	buffer = BytesIO()                              
	# Write the dataframe to the buffer        
	df_splited.to_excel(buffer, engine='xlsxwriter', index=False)        
	buffer.seek(0)        
	file_content = buffer.read()                
    # Load content to the file on Sharepoint        
	target_folder.upload_file(file_name, file_content).execute_query()        
	logging.info(f"File {file_name} has been uploaded")     

At this step function like hangs up and looks like restarting. In logs I see next activity

7/5/2023, 12:07:43.596 PM Worker process started and initialized.
7/5/2023, 12:07:41.863 PM Executed 'Functions.XXXXXXXXXXXXXX' (Failed, Id=XXXXXXXXXXXXXXXXXXXXXXXXX, Duration=326417ms)
7/5/2023, 12:07:41.828 PM Call to StopAsync complete, registered listeners are now stopped
7/5/2023, 12:07:41.821 PM Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'XXXXXXXXXXXXXX'
7/5/2023, 12:07:41.813 PM Stopping the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'XXXXXXXXXXXXXX'
7/5/2023, 12:07:41.802 PM Calling StopAsync on the registered listeners
7/5/2023, 12:07:41.776 PM DrainMode mode enabled
7/5/2023, 12:07:36.554 PM Host lock lease acquired by instance ID 'XXXXXXXXXXXXXX'.
7/5/2023, 12:05:17.221 PM Host lock lease acquired by instance ID 'XXXXXXXXXXXXXX'.
7/5/2023, 12:05:11.856 PM Job host started
7/5/2023, 12:05:11.852 PM Host started (305ms)
7/5/2023, 12:05:11.545 PM Starting JobHost
7/5/2023, 12:05:11.626 PM Host initialized (77ms)
7/5/2023, 12:05:11.620 PM Initializing function HTTP routes No HTTP routes mapped
7/5/2023, 12:05:11.617 PM HttpOptions { "DynamicThrottlesEnabled": false, "EnableChunkedRequestBinding": false, "MaxConcurrentRequests": -1, "MaxOutstandingRequests": -1, "RoutePrefix": "api" }
7/5/2023, 12:05:11.607 PM Found the following functions: Host.Functions.XXXXXXXXXXXXXX
7/5/2023, 12:05:11.589 PM Generating 1 job function(s)
7/5/2023, 12:05:11.573 PM Worker process started and initialized.
7/5/2023, 12:05:11.556 PM 1 functions loaded
7/5/2023, 12:05:11.555 PM 1 functions found
7/5/2023, 12:05:11.553 PM Reading functions metadata
7/5/2023, 12:05:11.548 PM Loading functions metadata
7/5/2023, 12:05:11.546 PM Starting Host (HostId=functXXXXXXXXXXXXXXXXXXXXXXXXXXXXdev, Version=4.21.3.3, ProcessId=59, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=~4)
7/5/2023, 12:04:37.642 PM Job host started

Always after getting log ´DrainMode mode enabled´ function fails without any detailed log. Usually after that Azure skips to fire up this function for any period of time. Even if postman return response: ´202 Accepted´

Calling StopAsync on the registered listeners1trace
Stopping the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'Function_Name'1trace
Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'Function_Name'1trace
Call to StopAsync complete, registered listeners are now stopped

The same code works perfect from VS Code in Debugging of the function.

Another weird thing, I see function activity in Logs, but I didn´t trigger the function

How can I understand the reason and fix the error?

PLEASE! Pay attention that Application insights already enabled and I checked monitoring.

I use Consumption Plan

I did deploy with Azure DevOps pipeline

I use the v2 runtime

I didn´t set WEBSITE_TIME_ZONE because now in progress with testing

CRON expression set to "schedule": "0 0 5 8 * *", but during testing I trigger the app with postman.

Invocation Id=8b47a9eb-022d-4239-b5c0-d6e9d144a99c

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,131 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.