设置会话ID或在ApplicationInsights中创建自定

设置会话ID或在ApplicationInsights中创建自定

本文介绍了如何从FunctionApp设置会话ID或在ApplicationInsights中创建自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

功能应用如下:

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequestMessage request, ILogger log)
    {
     log.LogInformation("Information", infoOBject);
    }

local.json文件具有applicationInstrument密钥.

local.json file has applicationInstrument key.

如何在应用程序见解中添加其他字段并为请求"条目设置"Session_Id".

How to add additional field and set "Session_Id" for "Request" entry in application insights.

推荐答案

您需要使用一些来自Application Insights的自定义日志记录

You need to this using some custom logging from Application Insights

首先,安装Nuget软件包

First, install the Nuget package

Install-Package Microsoft.ApplicationInsights -Version 2.7.2

然后像下面那样更改上面的代码

Then change your above code like below

public static class Function1
    {
        private static TelemetryClient GetTelemetryClient()
        {
            var telemetryClient = new TelemetryClient();
            telemetryClient.InstrumentationKey = "<your actual insight instrumentkey>";
            telemetryClient.Context.Session.Id = "124556";
            //update 1-Custom properties- Start
            telemetry.Context.Properties["tags"] = "PROD";
            telemetry.Context.Properties["userCorelateId"]="1234";
            //update 1-Custom properties- Ends
            return telemetryClient;
            }


        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req, ILogger log)
        {
            var appInsights = GetTelemetryClient();
            appInsights.TrackRequest(req.RequestUri.ToString(), DateTime.Now, Stopwatch.StartNew().Elapsed, "200", true);
            return req.CreateResponse(HttpStatusCode.OK, "message");

        }


    }

最后在appinsights

Finally in the appinsights

您还可以在请求中添加自己的其他属性.

You can also add your own additional properties within the request.

E.g,
telemetry.Context.Properties["tags"] = "PROD";

这将在customDimension属性下添加属性

您还可以在此处引用

这篇关于如何从FunctionApp设置会话ID或在ApplicationInsights中创建自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 07:17