Open Closed

Integration with Elastic APM #4856


User avatar
0
Denis created

I am not able to get Exceptions to be recorded by Elastic APM. It seems like Exception are handled by some other middleware and not released to Elastic middleware. I placed Use Elastic APM on the top of OnApplicationInitialization. That did not help. So far it seems only exceptions on EF core are caught by Elastic APM. I tested with general Exception thrown by me - even that Exception is not caught

  • ABP Framework version: v7.X.X
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): tiered
  • Exception message and stack trace: -
  • Steps to reproduce the issue:" I used this instruction https://www.elastic.co/guide/en/apm/agent/dotnet/current/configuration-on-asp-net-core.html

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

    Hi,

    Could you share the full steps to reproduce? thanks.

  • User Avatar
    0
    Denis created
    1. Create new ABP Application
    2. Integrate Elastic following instruction https://www.elastic.co/guide/en/apm/agent/dotnet/current/configuration-on-asp-net-core.html
    3. Create and endpoint which throws some exception
    4. Call this endpoint and check Elastic APM
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I can't reproduce the problem with the steps you provided:

    public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        var app = context.GetApplicationBuilder();
        var env = context.GetEnvironment();
    
        app.UseElasticApm(app.ApplicationServices.GetRequiredService<IConfiguration>());
        
        .......
    }
    
    "ElasticApm":
      {
        "ServerUrl":  "http://localhost:8200",
        "SecretToken":  "",
        "ServiceName": "MyProjectName"
      }
    
    public class IndexModel : MyProjectNamePageModel
    {
      public void OnGet()
      {
        throw new UserFriendlyException("Test exception");
      }
    }
    

  • User Avatar
    0
    Denis created

    Please do these steps as well

    1. Create new Controller in HttpApi project
    2. Create some service in Application project, which throws an exception
    3. Make Controller call to call the service
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    it's not a problem.

    The elastic APM error page only shows unhandled exceptions

    ABP automatically handles all exceptions and sends a standard formatted error message to the client for an API/AJAX request: https://docs.abp.io/en/abp/latest/Exception-Handling

  • User Avatar
    0
    Denis created

    How I can make APM also to catch Exceptions then? I want APM to catch exception before ABP does that. I guess APM proxies exception further

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes, you can do that.

    You can define an exception subscriber: https://docs.abp.io/en/abp/latest/Exception-Handling#subscribing-to-the-exceptions

    public class ElasticApmExceptionSubscriber : ExceptionSubscriber
    {
        public  override Task HandleAsync(ExceptionNotificationContext context)
        {
            var transaction = Elastic.Apm.Agent.Tracer.CurrentTransaction;
            transaction.CaptureException(context.Exception);
            return Task.CompletedTask;
        }
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11