Не удается отправить идентификаторы контекста пользователя в Azure Application Insights - PullRequest
0 голосов
/ 17 октября 2019

Когда я пытаюсь зарегистрировать сеанс пользователя, используя шаги из этого поста: Отправка идентификаторов контекста пользователя для включения возможностей использования в Azure Application Insights в веб-формах, информация недоступна в Azure Application Insights

Репро шаги 1. Добавьте инициализатор телеметрии

public class TelemetryInitializer : ITelemetryInitializer
{
    public void Initialize(ITelemetry telemetry)
    {
        var ctx = HttpContext.Current;

        // If telemetry initializer is called as part of request execution and not from some async thread
        if (ctx != null)
        {
            var requestTelemetry = ctx.GetRequestTelemetry();

            // Set the user and session ids from requestTelemetry.Context.User.Id, which is populated in Application_PostAcquireRequestState in Global.asax.cs.
            if (requestTelemetry != null && !string.IsNullOrEmpty(requestTelemetry.Context.User.Id) &&
                (string.IsNullOrEmpty(telemetry.Context.User.Id) || string.IsNullOrEmpty(telemetry.Context.Session.Id)))
            {
                // Set the user id on the Application Insights telemetry item.
                telemetry.Context.User.Id = requestTelemetry.Context.User.Id;

                // Set the session id on the Application Insights telemetry item.
                telemetry.Context.Session.Id = requestTelemetry.Context.User.Id;
            }
        }
    }
}
Зарегистрируйте инициализатор на Global.asax
TelemetryConfiguration.Active.TelemetryInitializers.Add(new ManageTelemetryInitializer());
Заполните данные в Application_PostAcquireRequestState
protected void Application_PostAcquireRequestState()
{
    var requestTelemetry = Context.GetRequestTelemetry();
    if (HttpContext.Current.Session != null && requestTelemetry != null && string.IsNullOrEmpty(requestTelemetry.Context.User.Id))
    {
        UserSession userSession = // GetMySession

        string userId = string.Empty;

        if (userSession != null)
        {
            userId = userSession.UserGuid.ToString("N");
        }

        requestTelemetry.Context.User.Id = userId;
        requestTelemetry.Context.Session.Id = Session.SessionID;
    }
}

Фактические данные сеанса поведения недоступны в Azure Application Insights

enter image description here

Ожидаемое поведение Правильный сеанс пользователя в Azure Application Insights

ОБНОВЛЕНИЕ:

Вот данные, которые я вижу в окне вывода при отладке. Все выглядит хорошо. Я пропустил некоторые поля из-за конфиденциальности.

{
    "name": "Microsoft.ApplicationInsights.Dev.fc9e8309cdd74395bf57f81d63d915d9.Message",
    "time": "2019-10-18T10:13:21.0548760Z",
    "sampleRate": 33.3333333333333,
    "iKey": "INSTRUMENTATION_KEY",
    "tags": {
        "ai.internal.sdkVersion": "sd:2.4.1-442",
        "ai.session.id": "oaluibbilrmunjxc3i1zovld",
        "ai.operation.id": "OPERATION_ID",
        "ai.location.ip": "::1",
        "ai.cloud.roleInstance": "MACHINE_NAME",
        "ai.user.id": "cef5121344374f25a325a1079473c51a",
        "ai.operation.name": "OEPRATION",
        "ai.operation.parentId": "PARENT_ID"
    },
    "data": {
        "baseType": "MessageData",
        "baseData": {
            "ver": 2,
            "message": "MESSAGE",
            "severityLevel": "Verbose",
            "properties": {
                "DeveloperMode": "true"
            }
        }
    }
} 

1 Ответ

0 голосов
/ 18 октября 2019

Тайна была раскрыта. Комбинация фильтров в Azure Application Insights была упущена за лидерство команды из NOC. Из-за этого они не видели данных.

...