public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var act = new Activity("Complex process");

            act.Start();
            telemetry.SetUserContext("testId");
            telemetry.SetOperationContext(act.Id);
            telemetry.Event(new Event
            {
                Name       = "Get data: Inside FirstFunction",
                Context    = req.HttpContext,
                Additional = new Dictionary <string, string>
                {
                    ["ts"] = DateTime.Now.ToString()
                }
            });
            telemetry.StartOperation(act.Id, "Get data");

            HttpClient client = new HttpClient();

            headerService.SetCorellationId(client.DefaultRequestHeaders, act.Id);
            DateTime start    = DateTime.Now;
            var      response = await client.GetAsync("http://localhost:7071/api/SecondFunction");

            var stop = (DateTime.Now - start);

            var dependency = await telemetry.Dependency(new Dependency()
            {
                Duration = stop,
                Name     = "Calling SecondFunction",
                Request  = response.RequestMessage,
                Response = response,
                Data     = await response.Content.ReadAsStringAsync()
            });

            telemetry.StopOperation();
            var data = JsonConvert.DeserializeObject <Data>(dependency.Data);

            data.Content += " Added data from first function.";
            string output = JsonConvert.SerializeObject(data);

            return(new OkObjectResult(output));
        }
        public async Task OnActionExecutionAsync(ActionExecutingContext filterContext, ActionExecutionDelegate next)
        {
            if (_applicationConfigurationService.IsProductImprovementEnabled() && !string.IsNullOrEmpty(_appSettings.GoogleAnalyticsMeasurementId))
            {
                try
                {
                    if (_type == TelemetryType.Event)
                    {
                        await _telemetry.Event(_action);
                    }
                    else
                    {
                        await _telemetry.View(_action);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("Google Analytics Add Telemetry Filter failed", e);
                }
            }

            await next();
        }
 public static async Task Event(this ITelemetry telemetry, string action, string label = null)
 => await telemetry.Event("Admin App Web", action, label);
 public static async Task View(this ITelemetry telemetry, string item)
 => await telemetry.Event($"View {item}");