Sentry SDK with Asp.Net 4.6.1 Not working

Viewed 133

I have an Asp.Net app, using .net 4.6.1 version. When I installed Sentry nuget and used Sentry SDK, nothing working, no events are being sent to Sentry. Below is global.asax configs where I tried this Sentry.

<%@ Application Language="C#" %>
<%@ Import Namespace="Sentry" %>
<%@ Import Namespace="Sentry.AspNet" %>
<%@ Import Namespace="Sentry.Extensibility" %>
<script runat="server">
    private IDisposable _sentry;

    protected void Application_Start()
    {
       _sentry = SentrySdk.Init(o =>
        {
            o.Dsn = "dsn url";
            
        });

        // Initialize Sentry to capture AppDomain unhandled exceptions and more.
        
    }
    // Global error catcher
    protected void Application_Error()
    {
        var exception = Server.GetLastError();

        SentrySdk.CaptureException(exception);
    }


    protected void Application_End()
    {
        if (_sentry != null)
            _sentry.Dispose();
    }
</script>

Can anyone help me? Thanks

1 Answers

Refer to the sample in the documentation here. Specifically, you need to change your code as follows:

  • Add o.AddAspNet(); to the body of your SentrySdk.Init call
  • Use Server.CaptureLastError() in your Application_Error method

If you want to enable Sentry's performance monitoring features, you also need to:

  • Set a TracesSampleRate in your options

  • Add the following code:

    protected void Application_BeginRequest()
    {
        Context.StartSentryTransaction();
    }
    
    protected void Application_EndRequest()
    {
        Context.FinishSentryTransaction();
    }
    
Related