Enable Diagnostics in Windows Azure without .NET - azure

I'm using Windows Azure to host my python project and I'm trying to enable the diagnostics without good results.
As I'm using python and not .NET, the only way I can actually configure it is through config files.
Below my config files:
ServiceDefinition.csdef
...
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
...
ServiceConfiguration.Cloud.cscfg
....
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=<my-account-name>;AccountKey=<my-account-key"/>
....
diagnostics.wadcfg:
<DiagnosticMonitorConfiguration xmlns="http://schemas.microsoft.com/ServiceHosting/2010/10/DiagnosticsConfiguration"
configurationChangePollInterval="PT10M"
overallQuotaInMB="1200">
<DiagnosticInfrastructureLogs bufferQuotaInMB="100"
scheduledTransferLogLevelFilter="Warning"
scheduledTransferPeriod="PT5M" />
<Logs bufferQuotaInMB="200"
scheduledTransferLogLevelFilter="Warning"
scheduledTransferPeriod="PT5M" />
<Directories bufferQuotaInMB="600"
scheduledTransferPeriod="PT5M">
<CrashDumps container="wad-crash-dumps" directoryQuotaInMB="200" />
<FailedRequestLogs container="wad-frq" directoryQuotaInMB="200" />
<IISLogs container="wad-iis" directoryQuotaInMB="200" />
</Directories>
<WindowsEventLog bufferQuotaInMB="200"
scheduledTransferLogLevelFilter="Warning"
scheduledTransferPeriod="PT5M">
<DataSource name="System!*" />
</WindowsEventLog>
</DiagnosticMonitorConfiguration>
In Diagnostics Manager, I can't actually see any data.
Thanks.

May i ask where your diagnostics.wadcfg located? For a regular worker role the diagnostics.wadcfg must be in the root folder and because you don't have worker role module in your project the location of the architecture of your role folder is very important. Be sure to have exact same folder structure in your Python application as a regular worker role and then drop the diagnostics.wadcfg in the role root folder. (add that info back to your question to verify)
Do you see a diagnostics configuration XML is created in your Windows Azure Blob storage which is configured in the *.Diagnostics.ConnectionString. This is a check which suggests that the diagnostics component in the Azure role was able to read the provided configuration and could create the configuration XML at destination blob stroage (same Azure Storage will be use to write log Azure Table storage). Please verify.
Finally your diagnostics.wadcfg need some more work. As this is a non .net worker role you have configured IIS logging (do you really have IIS running in worker role? ) and also have System event log scheduled to transfer "warning only" so if there are no warnings. Finally the log transfer time is set to 5 minutes which is long during test.
What i can suggest as below to test if diagnostics is working or not:
Remove the IIS log if you dont have IIS running the Azure VM
Replace event log DataSource from System!* to Application!* and set filter to Info level
Change the log transfer time to less then a minutes
Run the exact same code in Development Fabric with Diagnostics connection string connected to Actual Azure Storage.
Add custom event log in your machine and see if they are transferred within the time limit to Azure Table storage and specific tables are created
Above should help you to troubleshoot the problem.

Related

Application Insights: Logs not streaming when deployed to App Service But streams in local debug environment

What I am trying to achieve
Hello, I have dotnetcore web Api which is running in Azure App Service server farm. For logging I have used both ILogger and Log4net. I am trying to send the logs of service to application-insights but the logs are not streaming when deployed to Azure but when tested locally it works fine and I can see logs from both the library ILogger/Log4net getting streamed to Application Insights.
What I have tried so far
Below configuration I have added in my service for application insights.
Runtime version: netcoreapp3.1 version-2.31.0.1
Hosting environment: Azure App Service
app-service.csproj
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
<PackageReference Include="Microsoft.ApplicationInsights.Log4NetAppender" Version="2.20.0" />
...
<ItemGroup>
log4net.config
<appender name="aiAppender" type="Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender, Microsoft.ApplicationInsights.Log4NetAppender">
<InstrumentationKey name="AppInsightsKey" value="abcdefgh-abcd-abcd-abcd-abcdefghijkl" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline"/>
</layout>
</appender>
startup.cs
public Startup(IConfiguration configuration)
{
Configuration = configuration;
Logger.ConfigureLog4Net("./logs/app.log", Configuration)
...
}
public void ConfigureServices(IServiceCollection services)
{
// The following line enables Application Insights telemetry collection.
services.AddApplicationInsightsTelemetry(
new Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions
{
EnableActiveTelemetryConfigurationSetup = true,
InstrumentationKey = Configuration["ApplicationInsights:InstrumentationKey"]
}) ;
services.AddMvc();
...
}
appsettings.json
"ApplicationInsights": {
"InstrumentationKey": "xxxxx"
}
I have also added ApplicationInsights.config file as suggested in elsewhere for Log4net to work as below
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<InstrumentationKey>xxxxx</InstrumentationKey>
</ApplicationInsights>
I have also added the key ApplicationInsights:InstrumentationKey in App Service Configuration App Settings. As well tried with default app settings key APPINSIGHTS_INSTRUMENTATIONKEY.
I have made sure all the required App settings keys are present in App service configuration too.
Followed this MS document on common issues Troubleshooting Application Insights Agent (formerly named Status Monitor v2) and as it quotes below
If any of these DLLs are present in the bin directory, monitoring
might fail:
Microsoft.ApplicationInsights.dll
Microsoft.AspNet.TelemetryCorrelation.dll
System.Diagnostics.DiagnosticSource.dll
But it's really confusing cause the required Nugets like "Microsoft.ApplicationInsights.AspNetCore" has "Microsoft.ApplicationInsights.dll" as dependency which in-turn has "System.Diagnostics.DiagnosticSource.dll" as dependency; and without the required AspNetCore nuget Application Insight won't work.
Essentially, this is a strange issue am facing where-in all logs and exceptions getting streamed perfectly fine in local run but once deployed to Azure App service no logs are streaming at all. Can someone shed some light here? Am I missing something obvious??
There are 5 Nuget packages that depend onSystem.Diagnostics.DiagnosticSource.dll , which belongs to logging of data.
This particular dll produces more conflicts while logging ApplicationInsights data.
Delete the System.Diagnostics.DiagnosticSource.dll from the bin folder ,build and deploy the application once and check the logs in Portal.
As it is a Default template added with the
Microsoft.ApplicationInsights.AspNetCore , I didn't found any build issues after deleting it from bin.
Here is the workaround which cleared the same issue.

Deployed app using Zipdeploy UI on Azure throws an error

i can deploy an app using Azure service extension in visual studio code which also creates web.config file and the app works fine, but when i try to upload the ZIP file using ZIPdeployUI and manually add the web.config the app throws an error "You do not have permission to view this directory or page". The difference is using Visual studio code the files are uploaded straight into /wwwroot folder and with ZipdeployUI it creates another folder that was zipped on local system.
You do not have permission to view this directory or page.
That is basically a hint that Azure encounter an error while running your web app. Since it's in production, it does not show any useful error messages. For testing/debugging purposes you can turn on the Azure detailed messaging, and turn it back off when it's ready for production. To do so, you have to follow these two steps,
Log in to Azure > App Services (left side menu) > Your Web App > App Service logs (search box is at the top if you can't find it), then turn on Detailed Error Messages or turn on all of the logging options, up to you.
Now add the following in your Web Config file,
In your Web Config file add <customErrors mode="Off" /> BEFORE system.web closing tag, </system.web>. Similarly, add <httpErrors errorMode="Detailed"></httpErrors> BEFORE </system.webServer>. Finally, upload the Web Config to Azure and cross your fingers.
If you follow the steps correctly, that will show the error messages in detail which takes you to figure out the issue.
Few Error Cases-Resolutions were:
You do not... this directory... this error comes when you have restricted IP on IIS Config. Check your web.config file and add your IP address in security section like:
<security>
<ipSecurity allowUnlisted="false">
<clear />
<add ipAddress="192.168.250.70" allowed="true" />
</ipSecurity >
</security>
Remove it if you do not want to restrict any IP address.
Check the zip is unpacked in the path Site>wwwroot>, else try restarting your function or web app.
You might need to tweak this depending on how your application structure looks like after the build like site\wwwroot\dist\, but if you have the app name in the folder structure, you might need to: site\wwwroot\dist\<app-name>\
Sometimes azure active directory authentication was created by Function App / Authentication automatically like (MS Graph - User.Read, Azure Service Management -user_impersonation). If yes, removing those will work to access the directory.

Azure worker role hangs on publish with error in Diagnostics

After updating to Azure SDK 2.6 (from 2.5.1) I have not been able to publish my Azure Worker Role instance. It had been working previously with the 2.5.1 SDK. The worker process fails to start in Azure and hangs with the status of:
Busy (Waiting for role to start... Application startup tasks are running. [2015- 06-02T23:27:56Z] Last role error: exit code - 0, exit time - [2015/06/02, 23:27:20.218])
The worker process does make use of Azure Diagnostics - configured in my service definition file like:
<Imports>
<Import moduleName="RemoteAccess" />
<Import moduleName="RemoteForwarder" />
<Import moduleName="Diagnostics"/>
</Imports>
and I do see an error in the Event Log of the worker VM:
System.UnauthorizedAccessException: Access to the path 'DiagnosticPlugin-ShutdownEvent' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Threading.EventWaitHandle..ctor(Boolean initialState, EventResetMode mode, String name)
at Microsoft.WindowsAzure.Plugins.Launcher.Program.MainImpl(String[] args)
at Microsoft.WindowsAzure.Plugins.Launcher.Program.Main(String[] args)
I'm just not sure how to correct the issue. Any ideas?
Azure Diagnostics Module should no longer be present in either SDK 2.5 or 2.6 of Azure deployments. Azure Diagnostics in SDK2.5+ world is now configured as an extension. (Diagnostics v1.3 version)
Here is more information: https://azure.microsoft.com/en-us/documentation/articles/cloud-services-dotnet-diagnostics/

Get publication path when publishing Azure

I followed this thread to create a virtual directory in Azure Cloud Services: Windows Azure creating virtual directory to local storage.
It works fine but I'm not able to get "localResourcePath" with the path Azure located the files.
Where do I have to set "MyResource"?
Thanks in advance.
"MyResource" is a LocalStorage resource you define in your CSDEF file - http://msdn.microsoft.com/en-us/library/azure/ee758711.aspx.
You would add the following to your CSDEF (changing sizeInMB as appropriate):
<LocalResources>
<LocalStorage name="MyResource" cleanOnRoleRecycle="false" sizeInMB="1000" />
</LocalResources>

Caching for session state not working in Azure Emulator

I have an Azure cloud service comprising one Web Role and a Cache Worker Role. The web role runs fine except when I try to add a session state provider that uses the cache worker:
<sessionState mode="Custom" customProvider="AFCacheSessionStateProvider">
<providers>
<add name="AFCacheSessionStateProvider" type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache" cacheName="default" dataCacheClientName="default" applicationName="AFCacheSessionState"/>
</providers>
</sessionState>
<dataCacheClients>
<dataCacheClient name="default">
<autoDiscover isEnabled="true" identifier="MyCacheWorkerRole" />
<!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
</dataCacheClient>
When I try to debug, the Azure compute emulator fires up, the browser opens, but the page never loads - just a loading spinner for a couple of minutes, then a single line: "The page cannot be displayed because an internal server error has occurred."
If I uncomment the "localCache" line above (I'm not sure what it's meant to do), I get a "not running a hosted service or the Development Fabric" message. The cloud service is set up as the startup project
----- EDIT ----
I get the same behaviour when I try to point to a Windows Azure Cache Service instead of a cache worker role.

Resources