4
votes

I'm encapsulating TelemetryClient functionality to a framework component for both client and server to use. In the process, trimming dependencies and replacing default behavior with my own.

My problem, however, is although telemetry shows up in debug output, it's not shown in the Application Insights Search window.

AISearch

Note, the telemetry is picked up in Azure Portal.

How can I get data from debug session telemetry, without the full blown Web App to Add Application Insights Telemetry... workflow?

Steps to reproduce:

  • Create Azure resource, replace InstrumentationKey = "###YourKey###" in snippet below
  • Create .NET Framework ConsoleApp
  • Add Microsoft.ApplicationInsights nuget package

Program.cs

using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Track.AddEvent("Debugging");
            System.Console.WriteLine("Search Insights");
            System.Console.ReadLine();
        }
    }

    public static class Track
    {
        private static readonly TelemetryClient TelemetryClient;

        static Track()
        {
            TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();
            config.InstrumentationKey = "###YourKey###";
            TelemetryClient = new TelemetryClient(config);
        }

        public static void AddEvent(string eventName)
        {
            TelemetryClient.TrackEvent(eventName);
        }
    }
}

Taking data from Azure Resource.

AzRes

2
I see you have a ReadLine() in there, but does calling Flush() on the telemetry client before the program exits make a difference?Brendan Green
@Brendan I did a flush before the Console calls, but no luck.Funk

2 Answers

2
votes

Don't know what caused it, but you can get around by manually adding ApplicationInsights.config.

Workflow:

  • Right click project: Add new item...
  • Choose: Application Configuration File
  • Name: ApplicationInsights.config

Running the solution again made the event count appear next to the light bulb.

  • Go to Application Insights Search window
  • Check All
  • Update

Data from Debug session telemetry shown accordingly.

Funny thing, if you now remove the config file, the events will still show up in the Application Insights Search window, although the count next to the light bulb disappears again.

1
votes

I just copy your code and install the latest version of Microsoft.ApplicationInsights(2.9.1), works fine at my side: I can see the telemetry data is shown in the "Application insights search".

  1. So can you confirm the version of the visual studio? Seams that there is issue in some previously visual studio version . I'm using 15.8.5, and works fine.

enter image description here

  1. Can you confirm the time range you select is correct?

  2. Please check if you can see the count of telemetry data in your visual studio as per screenshot below:

enter image description here

  1. Also, if there is an update button, please click it to get latest data.

enter image description here