microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
565 stars 287 forks source link

TrackPageView method is not sending data to BrowserTiming table in Log Analytics #1185

Closed v-gamaar closed 5 years ago

v-gamaar commented 5 years ago

Hello Team

I have configured AI SDK to monitor my web application .NET 4.7 through VS 2019, the web application is sending telemetry correctly to the Application Insights resource, the problem is when I want to send custom page view telemetry using TrackPageView method.

When I use this method I can the custom telemetry in the PageView table in Log Analytics, at the beginning Y wasn't able to see this custom telemetry in the Performance blade browser section of AI due to the client_type field was by default having the value "PC" instead of "Browser" needed to display this telemetry.

After researching I could solve this issue using the property Context.Device.Type = "Browser" in my code for TrackPageView method and the custom telemetry is showed in Performance blade now.

The current problem is that this function is not filling the table BrowserTiming in Log Analytics that is used to showed more details about Page View client side performance, I have searched for information and also I tried to use the class PageViewPerformanceTelemetry to send this data with TrackPageView method but is not working. I am not sure if my code is incorrect, could you please help me to know how to field this table with TrackPageView method, here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;

namespace NetMVC.Controllers
{
    public class HomeController : Controller
    {
        public TelemetryClient telemetry = new TelemetryClient();
        public PageViewTelemetry pageView = new PageViewTelemetry();
        public TelemetryConfiguration telemetryConfiguration = new TelemetryConfiguration();
        public PageViewPerformanceTelemetry performanceTelemetry = new PageViewPerformanceTelemetry();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            TimeSpan timeSpan = new TimeSpan(0,0,0,0,21);
            pageView.Name = "Hola2";
            pageView.Duration = timeSpan;
            pageView.Properties["initime"] = "25";
            pageView.Properties["endTime"] = "26";
            pageView.Context.Device.Type = "Browser";
            performanceTelemetry.Duration = timeSpan;
            performanceTelemetry.DeepClone();
            telemetry.TrackPageView(pageView);

            DateTimeOffset dateTimeOffset = new DateTimeOffset(DateTime.Now);
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

Version Info

SDK Version : .NET .NET Version : .NET 4.7
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : Visual Studio AI SDK 2.10 OS : Windows Hosting Info (IIS/Azure WebApps/ etc) : Azure App Service Windows

cijothomas commented 5 years ago

I don't see instrumentation key specified in the TelemetryConfiguration or TelemetryClient without which no telemetry will be sent using this telemetryClient instance. If this is a Asp.Net Web Application where you have other telemetry flowing, then simply do new TelemetryClient(). It'll pick up the current Active TelemetryConfiguration.

and create pageview telemetry for every request. i.e do the following inside ABout()

var performanceTelemetry = new PageViewPerformanceTelemetry();