# Crash 설정

## 1. **Custom Crash 발생** <a href="#custom-crash" id="custom-crash"></a>

IMQA Crash Agent 에서는 다음과 같은 사용자 정의 에러를 수집할 수 있습니다. Exception 객체와 함께 특정 태그, 에러의 등급을 지정할 수 있습니다.

```java
 try {
  ...
} catch (SomeException e) {
  IMQACrashAgent.SendException(e, "ERROR TAG", ErrorRank.Major);
}
```

에러 랭크의 경우 별도로 정해져있지는 않으며 앱의 구성에 따라 변경하여 사용가능합니다.

<table><thead><tr><th width="218.2087241113939">Rank</th><th width="413.3333333333333">Description</th></tr></thead><tbody><tr><td>ErrorRank.Unhandle</td><td>기본이 되는 에러 등급으로 처리하지 못한 크래시에 사용</td></tr><tr><td>ErrorRank.Critical</td><td>앱에 상당한 영향을 주는 크래시 일 경우</td></tr><tr><td>ErrorRank.Major</td><td>앱에 영향이 있는 크래시 일 경우</td></tr><tr><td>ErrorRank.Minor</td><td>앱에 큰 영향이 없는 크래시 일 경우</td></tr></tbody></table>

## 2. Custom Web Crash 발생

IMQA Webview Agent 에서는 웹뷰에서 발생하는 에러나 비즈니스 로직에서 발생하는 다양한 문제를 사용자 정의 에러로 수집할 수 있습니다.

{% hint style="warning" %}
Webview Crash 수집을 위해서는 WebviewInterface 와 WebViewBridge 를 추가해 주어야 WebView에서 발생한 에러 정보를 수집할 수 있습니다. \
‘[Android > MPM 설정 > MPM Webview Guide > Android Agent 설정](https://docs.imqa.io/imqa-guide/installation/android/mpm-sdk-setting#android-agent)'을 참고하세요.
{% endhint %}

{% code title="사용자 정의 에러 수집할 js 파일" %}

```javascript
throw new IMQACustomError("사용자가 지정한 에러 메시지");

try {
	...
} catch (e) {
	throw new IMQACustomError(e)
}
```

{% endcode %}

커스텀 웹 에러 발생시, 아래와 같이 IMQA Crash, WCrash 에러 검색에서 에러 유형 ‘WCustom’으로 구분하여 검색하실 수 있습니다.

<figure><img src="/files/jjwXvQRumK8WrYNjC16p" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
현재 WCustom 유형 에러 목록 확인은 ‘에러 검색’ 페이지를 통해서만 가능합니다.
{% endhint %}

## 3. 특정 웹 크래시 수집 제한 옵션 <a href="#filtererror" id="filtererror"></a>

IMQA Webview Agent 에서는 웹뷰에서 발생하는 에러 중 수집하고 싶지 않은 에러를 설정할 수 있습니다.

{% hint style="warning" %}
Webview Crash 수집을 위해서는 WebviewInterface 와 WebViewBridge 를 추가해 주어야 WebView에서 발생한 에러 정보를 수집할 수 있습니다. \
‘[Android > MPM 설정 > MPM Webview Guide > Android Agent 설정](https://docs.imqa.io/imqa-guide/installation/android/mpm-sdk-setting#android-agent)'을 참고하세요.
{% endhint %}

<table><thead><tr><th width="137" align="center">Option Name</th><th width="125" align="center">Type</th><th width="132" align="center">Default Value</th><th>Description</th></tr></thead><tbody><tr><td align="center">filterError</td><td align="center">string[] | null</td><td align="center">null</td><td>예) [”$”, “type”]<br>- Agent가 수집한 에러(Web Crash)중 배열속 문자열이 포함된 에러라면 수집하지 않습니다.<br>- 대소문자는 구분하지 않습니다. <br>- [”type”]으로 옵션값을 설정하시면 “TypeError …”과 같은 에러도 수집되지 않습니다.</td></tr></tbody></table>

필수 설정과 특정 웹 크래시 수집 제한 옵션을 적용한 스크립트는 아래와 같습니다.

{% code title="webview-agent.js 연결 할 html <head>" overflow="wrap" %}

```html
// IMQA webview-agent.js 연결
<script src="https://cdn.imqa.io/agent/webview-agent.js"></script>

// IMQA webview-agent 스크립트 필수 값
<script>
    ((w, c, _wv, _w, _wk, _mh, _b) => {
        w[c] = w[c] || {};
    function imqaConf(key, value){w[c][key]=value};

    // 특정 웹 크래시 수집 제한 옵션
    imqaConf("filterError", ["$", "type"]); // "$" 또는 "type"이 에러명에 포함된 에러는 수집하지 않음         
                                                    
       w[_wv](w); // 웹뷰 에이전트 실행함수
    })(window, 'imqaClientConfig', 'IMQAWebviewMain', 'IMQAWebMain', 'webkit', 'messageHandlers', 'ImqaBridge')
</script>


```

{% endcode %}

위와 같이 Agent 웹 크래시 수집 제한 설정시, IMQA Crash, WCrash에서 **에러명**에 "$" 또는 "type"이 포함된 웹 크래시는 수집되지 않습니다.

<figure><img src="/files/RlxsfEzlsV4AAcCGRMRZ" alt=""><figcaption><p>"type"이 포함된 에러명 예시</p></figcaption></figure>

## 4. EventPath 등 <a href="#eventpath" id="eventpath"></a>

EventPath는 사용자의 기기에서 앱이 어떤 경로로 동작하는지 파악하는 기능입니다. 이를 사용하기 위해서는 클래스에 EventPath 추적 코드를 넣어주어야 합니다. 추적코드에 ‘STEP’ 과 ‘LABEL’에 해당되는 내용을 넣어줍니다.

| STEP                                                       | LABEL                                                          |
| ---------------------------------------------------------- | -------------------------------------------------------------- |
| 수집할 콜스택의 단계, 해당 스텝의 클래스명, 함수이름, 호출 위치를 가지고 옵니&#xB2E4;**.** | 수집된 EventPath 의 별칭, 크래시 정보 창에서 EventPath의 각 발생 위치를 별칭으로 보여줍니다. |

```java
public void onClickSomething() {
      EventPathManager.CreateEventPath(STEP, LABEL);
  }
```

## 5. Custom User ID 등록 <a href="#custom-user-id" id="custom-user-id"></a>

크래시 데이터 수집 시 특정 사용자를 식별하기 위한 ID 정보를 설정할 수 있습니다. 사용자 ID 정보를 설정한 후, Crash 에러 목록 에서 사용자 ID 정보로 에러를 조회할 수 있습니다.

{% hint style="warning" %}
**Custom User ID 등록시,** 사용자 식별을 위해 사용자 로그인 후의 화면, 홈 화면 또는 스플래시 화면에 추가해 주세요.
{% endhint %}

{% hint style="info" %}
SDK 옵션 상, MethodName은 사용자ID, 사용자 이름, 사용자 이메일로 작성되었으나 사용 예시이며, 실제 개인을 특정할 수 있는 직접 식별 정보 (특정 이름, 주민등록번호, 이메일 주소, 기타 유사 데이터) 보다는 **2차 가공한 임의의 식별 정보**를 사용하시기를 권고 드립니다.\
\
예를 들어, 2차 가공한 식별자 (예: 2013133, A39233 등), 등급 정보 (예: VIP, Gold, Member), 유입 경로 (예: Google, N, K) 등으로 사용자의 유형 분류에 따른 분석이 가능합니다.
{% endhint %}

<table><thead><tr><th width="185.56548708822163">Class Name</th><th width="282.4795378120725">Method Name</th><th>Description</th></tr></thead><tbody><tr><td>IdentifierCollector</td><td>setCustomUserId(STRING)</td><td>사용자 ID-1 (Primary)</td></tr><tr><td>IdentifierCollector</td><td>setCustomUserName(STRING)</td><td>사용자 ID-2</td></tr><tr><td>IdentifierCollector</td><td>setCustomUserMail(STRING)</td><td>사용자 ID-3</td></tr></tbody></table>

```javascript
IdentifierCollector.setCustomUserId("A100032"); // 사용자 ID-1 (Primary)
IdentifierCollector.setCustomUserName("VIP"); // 사용자 ID-2
IdentifierCollector.setCustomUserMail("G****"); // 사용자 ID-3
```

SDK에서 사전 정의한 사용자의 ID 정보가 수집되었을 경우, MPM 행동분석 및 Crash 사용자별 에러 목록에서 사용자 ID 정보로 데이터 조회가 가능합니다.

<figure><img src="/files/WrjI7MmoCUagS8Gzj0Xi" alt=""><figcaption></figcaption></figure>

## 6. Custom User Log/Key 등록 <a href="#custom-user-log-key" id="custom-user-log-key"></a>

크래시가 발생하기 전에 원하는 로그를 개발자가 직접 추가로 남길 수 있습니다. (최대 100개)

| Class Name         | Method Name     | Description       |
| ------------------ | --------------- | ----------------- |
| CustomLogCollector | log(STRING)     | 로그를 일반 문자열로 남깁니다. |
| CustomLogCollector | log(KEY, VALUE) | 로그를 키:값 형태로 남깁니다. |

```javascript
CustomLogCollector.log("test log"); // 로그를 일반 문자열로 남깁니다.
CustomKeyCollector.log("My Key", "My Log"); // 로그를 키:값 형태로 남깁니다.
```

## 7. 초기화 Option 추가 <a href="#option" id="option"></a>

IMQAController 초기화 시 옵션을 지정할 수 있습니다. IMQA Crash 모드를 파라미터나 Option을 이용해 변경할 수 있습니다.

<table><thead><tr><th width="160.7827459212473">Class Name</th><th>Method Name</th><th></th></tr></thead><tbody><tr><td>IMQAOption</td><td>setDirectUploadFlag(BOOL)</td><td>업로드 모드를 설정합니다. false 로 설정할 경우 debug mode 에서도 동작합니다.</td></tr><tr><td>IMQAOption</td><td>setPrintLog(BOOL)</td><td>Log 출력 여부를 설정합니다. true 로 설정할 경우 IMQA 의 Log가 출력됩니다.</td></tr><tr><td>IMQAOption</td><td>setAnrOn(BOOL)</td><td>ANR 을 모니터링 여부를 설정합니다. false 로 설정할 경우 ANR은 크래시 수집에서 제외됩니다.</td></tr><tr><td>IMQAOption</td><td>setAnrTimeoutIntercal(int)</td><td>ANR 타임아웃이 발생하는 시간을 설정합니다. (milliseconds 단위)</td></tr></tbody></table>

{% code title="MyApplication.java" %}

```java
@Override
public void onCreate() {
    super.onCreate();
      
    io.imqa.core.IMQAOption imqaOption = new io.imqa.core.IMQAOption();

    /*  
     * 기본값 : true
     * ANR 정보 수집 여부를 설정합니다. 
     * true : ANR 발생 여부를 모니터링 합니다.
     * false : ANR 발생 모니터링을 중지합니다.
    */
    imqaOption.setAnrOn(false);


    /*
     * 기본값 : 5000
     * anrTimeoutInveral : ANR 타임아웃이 발생하는 시간을 설정합니다(milliseconds 단위)
     */
    imqaOption.setAnrTimeoutInterval(5000);


   /*
     * 기본값 : false
     * Log 출력 여부를 설정합니다. 
     * true : IMQA Crash 의 Log가 출력됩니다.
    */
    imqaOption.setPrintCrashLog(true);

    /*
     * 기본값 : true
     * 수집된 크래시 정보를 크래시 발생 순간에 업로드합니다.
     * true : 크래시 발생 순간에 업로드합니다.
     * false : 보관 후 재실행시 업로드 합니다.
    */
    imqaOption.setCrashDirectUploadFlag(false);

    /*
     * 기본값 : false
     * 압축 알고리즘을 설정합니다.
     * true : zstandard 압축 알고리즘 사용.
     * false : gzip 압축 알고리즘 사용.
    */
    imqaOption.setCompressZstd(true);

    /*
     * 기본값 : 'https://main.collector.imqa.io'
     * 크래시 서버 URL을 설정합니다.
     * String : 서버 정보
     */
    imqaOption.setCrashServerUrl('https://main.collector.imqa.io');

    io.imqa.crash.IMQACrashAgent.InitializeAndStartSession(
        this, // Application Context
        BuildConfig.FLAVOR, // Project Flavor Setting
        "PROJECT_KEY",  // 발급 받은 프로젝트 키
        imqaOption // 옵션을 설정할 경우 객체 추가
    );
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.imqa.io/imqa-guide/installation/android/crash-sdk-setting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
