Sentry突然出现无法自动上传崩溃日志

近段时间在研究崩溃日志的获取方式,经过搜寻找到开源库PLCrashReporter和KSCrash。第三方则有Sentry、友盟、Bugly等。目前我们项目中使用了Sentry和PLCrashReporter。

PLCrashReporter

PLCrashReporter的集成
pod 'PLCrashReporter', '~> 1.8.1'
PLCrashReporter使用
#import <CrashReporter/CrashReporter.h>
PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType: PLCrashReporterSignalHandlerTypeMach
                                                                       symbolicationStrategy: PLCrashReporterSymbolicationStrategyNone];
    PLCrashReporter *crashReporter = [[PLCrashReporter alloc] initWithConfiguration: config];

    // Enable the Crash Reporter.
    NSError *error;
    if (![crashReporter enableCrashReporterAndReturnError: &error]) {
        NSLog(@"Warning: Could not enable crash reporter: %@", error);
    }
    if ([crashReporter hasPendingCrashReport]) {
        NSError *error;

        // Try loading the crash report.
        NSData *data = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
        if (data == nil) {
            NSLog(@"Failed to load crash report data: %@", error);
            return;
        }

        // Retrieving crash reporter data.
        PLCrashReport *report = [[PLCrashReport alloc] initWithData: data error: &error];
        if (report == nil) {
            NSLog(@"Failed to parse crash report: %@", error);
            return;
        }

        // We could send the report from here, but we'll just print out some debugging info instead.
        // 这是获取的日志信息,可以自己保存到沙盒中,然后上传自己的服务器。
        NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport: report withTextFormat: PLCrashReportTextFormatiOS];
        NSLog(@"%@", text);

        // Purge the report.
        [crashReporter purgePendingCrashReport];
    }

Sentry

Sentry的使用方式在之前的文章都已经提过。
iOS端实现sentry日志收集

Sentry和PLCrashReporter之间的冲突

如果先把PLCrashReporter的使用写在sentry代码之后,就会出现sentry不会自动上传崩溃日志。
正确做法是:
其他崩溃日志的获取在sentry之前写。
例如:

//pLCrashReporter的使用。
[self pLCrashReporter];
    [SentrySDK startWithConfigureOptions:^(SentryOptions * _Nonnull options) {
        options.dsn = @"http://304ca6bc430645aea25082b1c6426a79@192.168.43.152:9000/2";
        options.debug = YES;
    }];
-(void)pLCrashReporter{
	PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType: PLCrashReporterSignalHandlerTypeMach
                                                                       symbolicationStrategy: PLCrashReporterSymbolicationStrategyNone];
    PLCrashReporter *crashReporter = [[PLCrashReporter alloc] initWithConfiguration: config];

    // Enable the Crash Reporter.
    NSError *error;
    if (![crashReporter enableCrashReporterAndReturnError: &error]) {
        NSLog(@"Warning: Could not enable crash reporter: %@", error);
    }
    if ([crashReporter hasPendingCrashReport]) {
        NSError *error;

        // Try loading the crash report.
        NSData *data = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
        if (data == nil) {
            NSLog(@"Failed to load crash report data: %@", error);
            return;
        }

        // Retrieving crash reporter data.
        PLCrashReport *report = [[PLCrashReport alloc] initWithData: data error: &error];
        if (report == nil) {
            NSLog(@"Failed to parse crash report: %@", error);
            return;
        }

        // We could send the report from here, but we'll just print out some debugging info instead.
        // 这是获取的日志信息,可以自己保存到沙盒中,然后上传自己的服务器。
        NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport: report withTextFormat: PLCrashReportTextFormatiOS];
        NSLog(@"%@", text);

        // Purge the report.
        [crashReporter purgePendingCrashReport];
    }
}

问题解决。如有问题,请联系。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,关于sentrysourcemap的问题,我可以给你一些指导。首先,为了在Sentry中方便地进行错误跟踪和调试,你需要将你的JavaScript代码和对应的sourcemap一起上Sentry中。这样,当一个错误发生时,Sentry可以自动地将错误堆栈信息还原为源代码级别,从而方便你进行调试。 具体的上步骤如下: 1. 首先,你需要安装并配置Sentry CLI。你可以通过以下命令安装Sentry CLI: ``` npm install -g @sentry/cli ``` 2. 接下来,你需要为你的项目创建一个Sentry项目,并获取对应的DSN。DSN是Sentry用于识别你的项目的唯一标识符,你需要将它放在你的JavaScript代码中,以便Sentry可以正确地将错误信息发送到对应的Sentry项目中。 3. 在你的JavaScript代码中,你需要使用Sentry SDK提供的函数来初始化Sentry,并将DSN递给它。你可以在你的JavaScript代码的入口处添加以下代码: ```javascript import * as Sentry from '@sentry/browser'; Sentry.init({ dsn: 'YOUR_DSN_HERE' }); ``` 4. 接下来,你需要使用Sentry CLI来上你的JavaScript代码和sourcemap。你可以使用以下命令来上: ``` sentry-cli releases files YOUR_RELEASE_NAME upload-sourcemaps --url-prefix 'YOUR_URL_PREFIX' ./dist ``` 其中,YOUR_RELEASE_NAME是你的代码的版本号,YOUR_URL_PREFIX是你的代码的URL前缀,./dist是你的代码和sourcemap所在的目录。 5. 上完成后,你可以在Sentry中查看你的错误信息和对应的堆栈信息,以及使用Sentry提供的调试工具来进行调试。 希望这些信息对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值