<commit_before>//
//  EventTracker.swift
//  Stage1st
//
//  Created by <NAME> on 2018/10/3.
//  Copyright © 2018 Renaissance. All rights reserved.
//

import Crashlytics
import Sentry

protocol EventTracker {
    func recordAssertionFailure(_ error: Error)
    func recordError(_ error: Error)
    func recordError(_ error: Error, withAdditionalUserInfo userInfo: [String: Any]?)

    func logEvent(_ name: String)
    func logEvent(_ name: String, attributes: [String: String]?)
    func logEvent(_ name: String, uploadImmediately: Bool)
    func logEvent(_ name: String, attributes: [String: String]?, uploadImmediately: Bool)

    func setObjectValue(_ value: String, forKey key: String)
}

class S1EventTracker: EventTracker {

    private(set) var extraInfo: [String: String] = [:]

    func recordAssertionFailure(_ error: Error) {
        recordError(error, withAdditionalUserInfo: nil, level: .error)
    }

    func recordError(_ error: Error) {
        recordError(error, withAdditionalUserInfo: nil, level: .warning)
    }

    func recordError(_ error: Error, withAdditionalUserInfo userInfo: [String: Any]?) {
        recordError(error, withAdditionalUserInfo: userInfo, level: .warning)
    }

    func recordError(_ error: Error, withAdditionalUserInfo userInfo: [String: Any]?, level: SentryLevel) {
        Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo: userInfo)

        let extraInfoSnapshot = self.extraInfo

        let event = Event(level: .warning)
        let nsError = error as NSError
        event.message = "\(nsError.domain):\(nsError.code)"
        event.extra = nsError.userInfo
            .merging(userInfo ?? [:], uniquingKeysWith: { $1 })
            .merging(extraInfoSnapshot, uniquingKeysWith: { $1 })
        event.fingerprint = [event.message]
        event.type = "error"
        SentrySDK.capture(event: event)<commit_msg>Attach stacktrace for non fatal event<commit_after>//
//  EventTracker.swift
//  Stage1st
//
//  Created by <NAME> on 2018/10/3.
//  Copyright © 2018 Renaissance. All rights reserved.
//

import Crashlytics
import Sentry

protocol EventTracker {
    func recordAssertionFailure(_ error: Error)
    func recordError(_ error: Error)
    func recordError(_ error: Error, withAdditionalUserInfo userInfo: [String: Any]?)

    func logEvent(_ name: String)
    func logEvent(_ name: String, attributes: [String: String]?)
    func logEvent(_ name: String, uploadImmediately: Bool)
    func logEvent(_ name: String, attributes: [String: String]?, uploadImmediately: Bool)

    func setObjectValue(_ value: String, forKey key: String)
}

class S1EventTracker: EventTracker {

    private(set) var extraInfo: [String: String] = [:]

    func recordAssertionFailure(_ error: Error) {
        recordError(error, withAdditionalUserInfo: nil, level: .error)
    }

    func recordError(_ error: Error) {
        recordError(error, withAdditionalUserInfo: nil, level: .warning)
    }

    func recordError(_ error: Error, withAdditionalUserInfo userInfo: [String: Any]?) {
        recordError(error, withAdditionalUserInfo: userInfo, level: .warning)
    }

    func recordError(_ error: Error, withAdditionalUserInfo userInfo: [String: Any]?, level: SentryLevel) {
        Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo: userInfo)

        let extraInfoSnapshot = self.extraInfo

        let event = Event(level: .warning)
        let nsError = error as NSError
        event.message = "\(nsError.domain):\(nsError.code)"
        event.extra = nsError.userInfo
            .merging(userInfo ?? [:], uniquingKeysWith: { $1 })
            .merging(extraInfoSnapshot, uniquingKeysWith: { $1 })
        event.fingerprint = [event.message]
        event.type = "error"
        SentrySDK.currentHub().getClient()?.attachStacktrace(event)
        SentrySDK.capture(event: event)
{'fraction_non_alphanumeric': 0.109963861641714, 'fraction_numerical': 0.007743933918430563, 'mean_word_length': 3.516317016317016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5267697', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1097, 'n_words': 305}