Azure / Azure-Functions

1.12k stars 199 forks source link

Streaming logs only work in Visual Studio 2017 after I enter Azure portal and click on the function app streaming log. #843

Open TonyHenrique opened 6 years ago

TonyHenrique commented 6 years ago

HI, I found a bug in Azure Functions v2 Runtime version: 2.0.11857.0 (beta) and Visual Studio 2017 15.8.0 Preview 2.0:

The Streaming logs only work in Visual Studio after I enter Azure portal and click on the function app streaming log.

image image

cgillum commented 6 years ago

@mathewc care to take a look?

mathewc commented 6 years ago

Log streaming is based on log files written by the runtime, and those log files are only written when in "debug mode" - meaning the portal, CLI or some other development client is connected. Now the portal and CLI hit runtime endpoints that keep it in debug mode, so the log files are written and streaming works. However, after a period of inactivity or disconnect, the files are no longer written and log streaming stops. This is by design. Since log files are expensive to write they are only written when needed, and after a short period of no portal/CLI activity they auto disable.

I suspect that the VS client isn't putting the host into debug mode the way the portal/CLI does.

TonyHenrique commented 6 years ago

I tought the same thing, it seems that Visual Studio is not starting the debug in the Azure host. Then I enter portal, click on logs, and the logs start streaming also on the Visual Studio .

gorillapower commented 6 years ago

Ive run into the same issue. We are trying leverage streaming of logs to our application using either Kudu logs or Application Insights. We've tried the recommended AppInsights approach and used the REST API to poll a query every few seconds, but the logs are up to 5mins delayed and there are throughput limits which we are worried we may hit at some point (it doesnt look like there is an api to leverage the live stream feature in the app insights portal).

After seeing the webapp streaming logs in the portal and seeing they are available in the Kudu API we tried to implement this approach (using filesystem and blob storage), with the former exhibiting the behaviour @mathewc describes above and the later not displaying the correct log messages as described in this issue https://github.com/Azure/azure-functions-host/issues/1181#issuecomment-293317058. EDIT: looks like its discussed here as well https://github.com/Azure/azure-functions-ux/issues/885

Is there way we can effectively 'live stream' a functions logs for our application? We are using durable functions and want to capture a particular functions log output in our application and display it to a user.