【问题标题】:How to setup Sentry in .NET Azure functions如何在 .NET Azure 函数中设置 Sentry
【发布时间】:2021-07-20 01:20:34
【问题描述】:

【问题讨论】:

    标签: .net azure-functions sentry


    【解决方案1】:
    1. 安装包 Install-Package Sentry.AspNetCore
    2. Azure 函数中的设置处理
    
            [FunctionName("Function1")]
            public static async Task RunAsync([TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
            {
                using (SentrySdk.Init())
                {
                    try
                    {
                       //Code
                    }
                    catch (Exception ex)
                    {
                        SentrySdk.CaptureException(ex);
                        throw;  //if you want to pass it into Azure
                    }
                }
            }
    
    1. local.settings.json中配置DSN
      "Values": {
        "SENTRY_DSN": "https://your-dsn-url.ingest.sentry.io/xxx"
      }
    

    【讨论】:

    • 如果你只是使用普通的 .NET SDK(Sentry nuget 包),你甚至不需要安装 Sentry.AspNetCore。只是哨兵。我还建议在调用 capture 之后(在 throw 之前)使用 await SentrySdk.FlushAsync(TimeSpan.FromSecond(2)); 以确保 Sentry 获取事件,以防 lambda 进程被冻结/关闭。虽然离开using 应该已经处理并刷新了(虽然阻塞线程,因为 Dispose 在那里同步)
    猜你喜欢
    • 1970-01-01
    • 2018-10-24
    • 2020-01-01
    • 2020-09-23
    • 2021-01-13
    • 2023-02-16
    • 2020-05-21
    • 1970-01-01
    • 2021-07-19
    相关资源
    最近更新 更多