Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Diagnostics not working in my Worker Role

I'm trying to get trace logs for my worker role in windows azure but it's not working and cannot see any error.

I've configured my application to use azure diagnostics as explained here: https://www.windowsazure.com/en-us/develop/net/common-tasks/diagnostics/

First, I have this in the app.config of my worker role:

<system.diagnostics>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="AzureDiagnostics">
                <filter type="" />
            </add>
        </listeners>
    </trace>
</system.diagnostics>

Then, in my ServiceConfiguration.Cloud.cscfg I have this connection string:

<ConfigurationSettings>
  <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=XXXXXXX;AccountKey=XXXXXXXXX" /> 
  ...

In my ServiceDefinition.csdef I have:

<Import moduleName="Diagnostics" />

and finally in the OnStart() method of the WorkerRole.cs I have:

var config = DiagnosticMonitor.GetDefaultInitialConfiguration();
        config.Logs.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1.0);
        config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Information;

        DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);

Then I do some Trace.WriteLine() in my Run() method.

This should be creating a WADLogsTable in storage, but it isn't.

When I connect via remote desktop to my instance, I don't see any errors in event viewer, the only strange thing I see is the WaHostBootstrapper log where I'm seeing the DiagnosticsAgent.exe process started twice, and then when getting status one process responds and the other doesn't, this is the part of the log:

[00002868:00002872, 2012/11/23, 21:26:30.367, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:30.383, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:30.414, 00040000] Executing Startup Task type=2 rolemodule=Diagnostics cmd="E:\plugins\Diagnostics\DiagnosticsAgent.exe" 
[00002868:00002872, 2012/11/23, 21:26:30.414, 00040000] Executing "E:\plugins\Diagnostics\DiagnosticsAgent.exe" .
[00002868:00002872, 2012/11/23, 21:26:30.414, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:30.446, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:30.477, 00040000] Executing Startup Task type=0 rolemodule=Diagnostics cmd="E:\plugins\Diagnostics\DiagnosticsAgent.exe" /blockStartup
[00002868:00002872, 2012/11/23, 21:26:30.477, 00040000] Executing "E:\plugins\Diagnostics\DiagnosticsAgent.exe" /blockStartup.
[00002868:00002984, 2012/11/23, 21:26:30.821, 00040000] Registering client with PID 2964.
[00002868:00002984, 2012/11/23, 21:26:30.821, 00040000] Client DiagnosticsAgent.exe (2964) registered.
[00002868:00002984, 2012/11/23, 21:26:30.821, 00040000] Registering client with PID 2940.
[00002868:00002984, 2012/11/23, 21:26:30.821, 00040000] Client DiagnosticsAgent.exe (2940) registered.
[00002868:00002872, 2012/11/23, 21:26:45.961, 00040000] Program "E:\plugins\Diagnostics\DiagnosticsAgent.exe" /blockStartup exited with 0. Working Directory = E:\plugins\Diagnostics
[00002868:00002872, 2012/11/23, 21:26:45.961, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:45.992, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:46.008, 00040000] Executing Startup Task type=2 rolemodule=RemoteAccess cmd="E:\plugins\RemoteAccess\RemoteAccessAgent.exe" 
[00002868:00002872, 2012/11/23, 21:26:46.008, 00040000] Executing "E:\plugins\RemoteAccess\RemoteAccessAgent.exe" .
[00002868:00002872, 2012/11/23, 21:26:46.008, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:46.055, 00100000] <- WapGetEnvironmentVariable=0x800700cb
[00002868:00002872, 2012/11/23, 21:26:46.071, 00040000] Executing Startup Task type=0 rolemodule=RemoteAccess cmd="E:\plugins\RemoteAccess\RemoteAccessAgent.exe" /blockStartup
[00002868:00002872, 2012/11/23, 21:26:46.117, 00040000] Executing "E:\plugins\RemoteAccess\RemoteAccessAgent.exe" /blockStartup.
[00002868:00002984, 2012/11/23, 21:26:46.399, 00040000] Registering client with PID 936.
[00002868:00002984, 2012/11/23, 21:26:46.399, 00040000] Client RemoteAccessAgent.exe (936) registered.
[00002868:00002936, 2012/11/23, 21:26:46.430, 00040000] Registering client with PID 2432.
[00002868:00002936, 2012/11/23, 21:26:46.430, 00040000] Client RemoteAccessAgent.exe (2432) registered.
[00002868:00002872, 2012/11/23, 21:26:47.586, 00040000] Program "E:\plugins\RemoteAccess\RemoteAccessAgent.exe" /blockStartup exited with 0. Working Directory = E:\plugins\RemoteAccess
[00002868:00002872, 2012/11/23, 21:26:47.586, 00100000] <- GetDebugger=0x1
[00002868:00002872, 2012/11/23, 21:26:47.602, 00100000] <- GetRoleHostDebugger=0x1
[00002868:00002872, 2012/11/23, 21:26:47.633, 00100000] <- WapXmlReadContainerId=0x1
[00002868:00002872, 2012/11/23, 21:26:47.649, 00100000] <- WapGetVirtualAccountName=0x1
[00002868:00002872, 2012/11/23, 21:26:47.664, 00040000] Executing base\x64\WaWorkerHost.exe .
[00002868:00002872, 2012/11/23, 21:26:47.664, 00040000] Role host process PID: 2560.
[00002868:00002936, 2012/11/23, 21:26:47.742, 00040000] Registering client with PID 2560.
[00002868:00002936, 2012/11/23, 21:26:47.742, 00040000] Client WaWorkerHost.exe (2560) registered.
[00002868:00002936, 2012/11/23, 21:26:47.742, 00040000] Client process 2560 is the role host.
[00002868:00002936, 2012/11/23, 21:26:47.742, 00040000] Role host process registered.
[00002868:00002892, 2012/11/23, 21:26:47.899, 00040000] Getting status from client DiagnosticsAgent.exe (2964).
[00002868:00002892, 2012/11/23, 21:26:47.899, 00100000] Failed to connect to client DiagnosticsAgent.exe (2964).
[00002868:00002892, 2012/11/23, 21:26:47.914, 00100000] <- CRuntimeClient::OnRoleStatusCallback(0x00000000007EE660) =0x800706ba
[00002868:00002892, 2012/11/23, 21:26:47.961, 00040000] Getting status from client DiagnosticsAgent.exe (2940).
[00002868:00002892, 2012/11/23, 21:26:47.961, 00040000] Client reported status 0.

Is there anything wrong? how can I get those diagnostics posted to my azure storage?

like image 342
Escobar5 Avatar asked Nov 23 '12 21:11

Escobar5


1 Answers

Edited as I initially misread that you were running a webrole - oops.

With a worker role, try deleting the blob which describes the logging setup, then redeploy. You'll find the blob from under the wad-control-container blob directory in the storage account you are using for diagnostics.

Below is my original reply, however it applies only if you're running a webrole. I'm leaving it here as it's a obvious gotcha so maybe it saves some time for someone:

This could be because your webrole.cs code is running in a separate AppDomain from the web application (if you're hosting in full IIS). Even if the Azure DiagnosticMonitorTraceListener is configured in web.config, it has no effect for the AppDomain which is running webrole.cs code. Consequently, the Azure diagnostics trace listener is not registered in the Run method and the traces go nowhere.

I'd try two things: - Add the Azure diagnostics trace listener explicitly in code in OnStart (Trace.Listeners.Add(new DiagnosticMonitorTraceListener()). - Write some logs from the web application. This will likely trigger the creation of the WADLogsTable.

like image 180
Sami Avatar answered Sep 19 '22 18:09

Sami