简体   繁体   中英

SignalR trigger System.InvalidOperationException in Microsoft.ApplicationInsights.dll

SignalR trigger System.InvalidOperationException in Microsoft.ApplicationInsights.dll every second.

How can I use SignalR with application insights?

It seems to do with the the SQL backpane: Microsoft.AspNet.SignalR.SqlServer

    public class UnwantedTelemetryFilter : ITelemetryProcessor
    {
        private ITelemetryProcessor Next { get; set; }

        public UnwantedTelemetryFilter(ITelemetryProcessor next)
        {
            this.Next = next;
        }

        public void Process(ITelemetry item)
        {
            var request = item as RequestTelemetry;

            if (request != null && request.Name != null)
                if (request.Name.Contains("signalr"))
                    return;

            var dependency = item as DependencyTelemetry;
            if(dependency != null)
            {
                switch(dependency.Type)
                {
                    case "SQL":
                        if(String.IsNullOrEmpty(dependency.Data))
                        {
                            return;
                        }

                        break;
                }
            }

            // Send everything else:
            this.Next.Process(item);
        }

        public static void Set()
        {
            var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
            builder.Use((next) => new UnwantedTelemetryFilter(next));
            builder.Build();
        }
}

Error info:

Stacktrace:
at Microsoft.ApplicationInsights.Extensibility.Implementation.Metrics.DependencyMetricsExtractor.ExtractMetrics(ITelemetry fromItem, Boolean& isItemProcessed)

Error:
    Message "Cannot execute ExtractMetrics because this metrics extractor has not been initialized (no metrics manager)."   string

This is how I start the Application Insights. It is executed in the Application_Start.

    public static void SetApplicationInsights()
    {
        #if(DEBUG)
            Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;
        #endif

        Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = true;
        string t = Settings.KeyVault.Global.GetKey("AppInsightsInstrumentationKey");
        if (!String.IsNullOrEmpty(t))
        {
            UnwantedTelemetryFilter.Set();
            Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = t;
            Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.DisableTelemetry = false;

        }
    }

Given the new message you added with error info, you seem to be running into this GitHub issue:

GitHub issue #549: DependencyMetricsExtractor.ExtractMetrics threw exceptions

where it looks like if you manually added telemetry processors via code, you need to call initialize on them?

it looks like this specific issue was fixed a couple months ago, you may need to update to a newer version of the SDK, or use the workarounds specified in that issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM