美文网首页
APP日志收集sentry集成记录(一步一步填坑)

APP日志收集sentry集成记录(一步一步填坑)

作者: wg刚 | 来源:发表于2018-10-23 18:24 被阅读0次

    集成到sentry官网平台上的步骤:

    1、注册,登录

    网址:https://sentry.io/
    注册一个账号

    2、创建一个项目(project)
    3、iOS客户端pod进sentry

    在项目Podfile文件中:

    pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '4.1.0'
    

    执行,引入sentry第三方

    pod install
    
    4、配置

    在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中实现如下代码

    OC
    NSError *error = nil;
    SentryClient *client = [[SentryClient alloc] initWithDsn:@"https://905b6c2bd0784285ae87895fe526d4f2@sentry.io/1306735" didFailWithError:&error];
    SentryClient.sharedClient = client;
    [SentryClient.sharedClient startCrashHandlerWithError:&error];
    if (nil != error) {
        NSLog(@"%@", error);
    
    Swift
    do {
            Client.shared = try Client(dsn: "https://905b6c2bd0784285ae87895fe526d4f2@sentry.io/1306735")
            try Client.shared?.startCrashHandler()
        } catch let error {
            print("\(error)")
        }
    

    重点来了:

    配置的时候需要填一个dsn,这个在哪里找呢?

    复制,粘贴到代码里即可。

    5、上传dsym文件
    这是个大坑😂
    这里我使用官网推荐的fastlane上传
    如果你项目里没有使用fastlane,可以看这篇文章,很详细,一步一步跟着做就好了点这里
    • 分两种:with Bitcode, without Bitcode

    怎么看呢?

    我这里设为NO,即:without Bitcode

    • 对于without Bitcode

    修改fastlane文件夹下的

    添加如下代码
    desc "上传dysm文件"
      lane :uploadsydm do
         #increment_build_number
      #2.1编译 选择scheme和功能
        gym
        sentry_upload_dsym(
          auth_token: '自己的token',
          org_slug: '创建项目时的组织名称',
          project_slug: '项目名称',
        ) 
      end
    

    重点又来了!

    这三个参数从哪里找?
    点击设置

    看到了两个参数:

    那token呢?

    这时候就拿到了这三个参数了
    • 对于with Bitcode

    参数获取方式一致

    lane :upload_symbols do
      download_dsyms
      upload_symbols_to_sentry(
        auth_token: '...',
        org_slug: '...',
        project_slug: '...',
      )
    end
    
    6、该上传了
    • cd到项目根目录
    • 先执行:
    fastlane add_plugin sentry
    

    这是因为upload_symbols_to_sentry被废弃了,使用新的函数sentry_upload_dsym代替

    再执行:

    fastlane (函数名)
    //例如我的
    fastlane uploadsydm
    
    • 这时候会报如下错误

    这是因为需要安装sentry-cli

    解决:

    执行 brew install getsentry/tools/sentry-cli
    或者
    curl -sL https://sentry.io/get-cli/ | bash

    7、上传成功,在这里可以看到
    8、使用

    自己写一个崩溃

    运行一次崩溃,在运行一次就会上传崩溃日志

    即可查看

    参考:
    https://docs.fastlane.tools/actions/upload_symbols_to_sentry/
    https://docs.sentry.io/clients/cocoa/dsym/#dsym-without-bitcode
    https://www.jianshu.com/p/b4334dec2f37

    相关文章

      网友评论

          本文标题:APP日志收集sentry集成记录(一步一步填坑)

          本文链接:https://www.haomeiwen.com/subject/epjazftx.html