Open Closed

Application insights telemetry data server side #6629


User avatar
0
carlosfm created
  • ABP Framework version: 7.4.4
  • UI Type: Blazor WASM
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

Hello,

I have a problem connecting Application Insights with the app server. I can successfully connect the application and am able to exploit the data and make queries from Application Insights. Currently, in the requests table, I obtain all these data except for the session_Id and user_Id. When debugging the application, I see that the httpcontext of the application's session is null and it cannot assign to telemetry either. This would be the initializer that correctly has the user but within the context, the session is null.

public class CustomTelemetryInitializer : ITelemetryInitializer
{

    private readonly IHttpContextAccessor _httpContextAccessor;
    private readonly ICurrentUser _currentUser;

    public CustomTelemetryInitializer(IHttpContextAccessor httpContextAccessor, ICurrentUser currentUser)
    {
        _currentUser = currentUser;
        _httpContextAccessor = httpContextAccessor;
    }

    public void Initialize(ITelemetry telemetry)
    {
        var httpContext = _httpContextAccessor.HttpContext;
        if (httpContext == null) return;

        if (_currentUser.IsAuthenticated)
        {
            telemetry.Context.User.AuthenticatedUserId = _currentUser.Email;
            telemetry.Context.GlobalProperties["TenantId"] = _currentUser.TenantId.ToString();
        }
    }
}

As information, on the client side, I have the session without problems.

Thanks,


1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You could consider inheriting WebTelemetryInitializerBase

    • https://github.com/microsoft/ApplicationInsights-dotnet/blob/main/WEB/Src/Web/Web/Implementation/WebTelemetryInitializerBase.cs
    • https://github.com/microsoft/ApplicationInsights-dotnet/blob/bde1239460fabb81733c91ce36e9c2b317f1b483/WEB/Src/Web/Web/UserTelemetryInitializer.cs#L13
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11