Azure Diagnostics not working in my Worker Role
Asked Answered
D

1

7

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?

Directorate answered 23/11, 2012 at 21:40 Comment(1)
It looks good to me. Have you tried running it against local devstore first?Plumb
E
11

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.

Expletive answered 24/11, 2012 at 9:45 Comment(5)
Deleting the blob did it. ThanksDirectorate
+1 For the original answer; I had a webrole.cs running as a "worker role", tracing didn't work. Adding the Trace Listener as you described fixed my issue.Conduit
+1 Thanks. In my case I believed myself to have the same problem. However, I was just not realizing that Azure Diagnostics uploads them to a table WADLogsTable, I was looking for blobs and finding nothingBelding
In my case, it was even worse. It was blocking the actual restart which drove me to the edge of insanity (because it was in a production environment). Deleting the blob did the trick. Thanks A MILLION!!!Tauten
What if there is a backlog of old blob files in there from old deployments? Do you have to delete them all?Weinert

© 2022 - 2024 — McMap. All rights reserved.