Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions - Application Insights - Custom Telemetry - EventSource instance already exists

I am trying to follow the instructions in Insights Preview where I can create custom telemetry. I followed the instructions exactly. But maybe I've got it configured wrong.

I have the APPINSIGHTS_INSTRUMENTATIONKEY set in the local.settings.json file and it seems to work fine. But when I add a new TelemetryClient I start getting those duplicate errors (below). It happens when the function gets invoked.

I really would like the telemetry data from AF to go to the same AI instrumentation key so I can see it together.

I also pulled the Microsoft.Extensions.Logging out as I wanted to use AI only, if that makes any difference.

Anyone have any suggestions?

See below...

TIA

ERROR: Exception in Command Processing for EventSource Microsoft-ApplicationInsights-Core: An instance of EventSource with Guid 74af9f20-af6a-5582-9382-f21f674fb271 already exists.
ERROR: Exception in Command Processing for EventSource Microsoft-ApplicationInsights-Core: An instance of EventSource with Guid 74af9f20-af6a-5582-9382-f21f674fb271 already exists.
Microsoft.WindowsAzure.ServiceRuntime Critical: 102 : Unexpcted Exception During Runtime Startup:
System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> <CrtImplementationDetails>.ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.
 ---> System.Runtime.InteropServices.COMException: Invalid operation. (Exception from HRESULT: 0x80131022)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at <CrtImplementationDetails>.GetDefaultDomain()
   at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie)
   at <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* )
   at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* )
   at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
   --- End of inner exception stack trace ---
   at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
   at .cctor()
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor()
ERROR: Exception in Command Processing for EventSource Microsoft-ApplicationInsights-Data: An instance of EventSource with Guid a62adddb-6b4b-519d-7ba1-f983d81623e0 already exists.
like image 999
Bill Noel Avatar asked Oct 29 '22 04:10

Bill Noel


1 Answers

I started over with a fresh AF project (and a glass of wine) to keep it simple.

The following code works:

private static TelemetryConfiguration config = new TelemetryConfiguration { InstrumentationKey = System.Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process)};
private static TelemetryClient telemetryClient = new TelemetryClient(config);

This code (directly from the Preview post) does not:

private static TelemetryClient telemetryClient = new TelemetryClient();
private static string key = TelemetryConfiguration.Active.InstrumentationKey = System.Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process);

An unfortunate side effect is that the telemetry doesn't show up in te VS2017 Application Insights window automatically. You have to use the settings gear to select the AI repository you want and then you can see it. Minutes later, but better than nothing.

like image 99
Bill Noel Avatar answered Nov 09 '22 04:11

Bill Noel