Crash Analysis

更新时间:
复制 MD 格式

This document describes how to validate the Crash Analysis feature of the Alibaba Cloud App Monitor SDK for iOS.

1. Report a crash

  1. Write test code to simulate or trigger an app crash. For example:

    Important

    Do not run the app in the Xcode debugger. The SDK does not catch crashes in the Xcode debugger.

    NSMutableArray *array = @[];
    [array addObject:nil]; // crash
    let someNilString: String? = nil
    let forcedValue: String = someNilString!
    print("Value: \(forcedValue)")
  2. After the crash is triggered, wait about 2 minutes and view the data on the Crash page in the console.

    Note
    • Crash data appears in the console about 2 to 3 minutes after it is collected.

    • In some scenarios, crash data is uploaded after the application restarts.

    image

2. Set custom dimensions

  1. Write test code to call the SDK and set custom dimensions. For example:

    #import "AlicloudApmCore/AlicloudApmCore.h"
    
    [[EAPMApm defaultApm] setCustomValue:@"value" forKey:@"key"];
    
    [[EAPMApm defaultApm] setCustomKeysAndValues:@{
        @"key1":@"value1",
        @"key2":@"value2",
    }];
    #import "AlicloudApmCore/AlicloudApmCore.h"
    
    let apm = EAPMApm.defaultApm()
    apm.setCustomValue("value", forKey: "key")
    apm.setCustomKeysAndValues([
        "key1": "value1",
        "key2": "value2"
    ])
  2. About 2 minutes after you trigger a crash, you can view the report on the Crash page in the console, as shown in the red box in the following image.

3. Report a custom exception

  1. Write test code to call the SDK and report a custom exception. For example:

    #import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
    
    NSError *error = [NSError errorWithDomain:@"customError" code:10001 userInfo:@{@"errorInfoKey":@"errorInfoValue"}];
    
    [[EAPMCrashAnalysis crashAnalysis] recordError:error userInfo:@{
        @"key1":@"value1",
        @"key2":@"value2",
    }];
    #import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
    
    let crashAnalysis = CrashAnalysis.crashAnalysis()
    let error = NSError(
        domain: "customError",
        code: 10001,
        userInfo: [
            "errorInfoKey": "errorInfoValue",
        ]
    )
    crashAnalysis.record(error: error, userInfo: [
        "key1": "value1",
        "key2": "value2"
    ])
  2. After the application restarts, you can view the data on the Custom Exception page in the console.image