JetBrains / profiler-self-api

The portable version of JetBrains profiler self API for .NET Framework / .NET Core / .NET / .NET Standard
Apache License 2.0
61 stars 8 forks source link

Doesn't Work In Azure App Service #7

Open BluePositive opened 2 years ago

BluePositive commented 2 years ago

I'm trying to get a dotMemory Snaphost from an application that runs on Azure App Service but I'm getting this error.

System.InvalidOperationException: dotMemory console profiler has failed. See details below.
*** Standard Error ***
Unable to attach to the process #23240: Make sure it exists and it is a .NET Framework 4.0+/.NET Core 3.0+/.NET 5+ process.

*** Standard Output ***
dotMemory Console Profiler 2022.1.2 build 221.0.20220601.192640. Copyright (C) 2017-2022 JetBrains s.r.o.

Performs memory profiling of .NET applications

Attach Helper v221.0.19138.24931 Copyright (C) 2010-2022 JetBrains s.r.o.
Attach Helper v221.0.19138.24935 Copyright (C) 2010-2022 JetBrains s.r.o.

   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.BuildException(String caption)
   at JetBrains.Profiler.SelfApi.Impl.ConsoleProfiler.AwaitFinished(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotMemory.Session.AwaitFinished(Int32 milliseconds)
   at JetBrains.Profiler.SelfApi.DotMemory.GetSnapshotOnce(Config config)

   **here I removed a few lines that are specific to our code**

   at lambda_method6544(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
BluePositive commented 2 years ago

This is my controller method to get a snapshot

[HttpGet]
[Route("takeSnapshot")]
public async Task<string> TakeSnapshot(CancellationToken cancellationToken)
{
    var snapshotLocation = Environment.GetEnvironmentVariable("SNAPSHOT_LOCATION");
    if (snapshotLocation is null)
        return "The environment variable SNAPSHOT_LOCATION is missing";

    await DotMemory.EnsurePrerequisiteAsync(cancellationToken);
    var config = new DotMemory.Config()
        .SaveToDir(snapshotLocation);

    var snapshotPath = DotMemory.GetSnapshotOnce(config);
    return $"New snapshot at : {snapshotPath}";
} 
gassanosh commented 1 year ago

Azure App Service is a strict environment were not all APIs are available (at least by default). We never tested it in the environment and it's not expected the self api will work here. Here is a corresponding issue in JetBrains tracker: https://youtrack.jetbrains.com/issue/DTRC-28984