SentryKit 0.1.1

SentryKit 0.1.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年9月
SPM支持 SPM

David Chavez 维护。



SentryKit 0.1.1

  • 作者
  • David Chavez

SentryKit

一个使用 Swift 编写的 Sentry 错误报告 API 的客户端。

要求

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0+

使用

配置客户端

let client = Sentry.shared

do {
    // create a DSN object from your DSN string (found in Sentry panel).
    let dsn = try DSN(dsn: "https://public:[email protected]/1")

    // configure the shared client with the DSN
    client.dsn = dsn
} catch {
    // handle error
}

// other attributes you may set at start or when they become available
client.hostVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
client.environment = "production"

// the context allows you to store general information to include with requests
// i.e. tags, extra metadata, and user information (more info in Xcode)
client.context.tags = ["customer_tier": "pro"]
client.context.extra = ["advertising_group": "alucard"]

// you should set this attribute of context when a user authenticates
client.context.user = User(id:username:email:extra)

捕获消息

您可以使用客户端中的 captureMessage(message:level:tags:extra:) 方法捕获消息。

do {
    try client.captureMessage("This is a test message", level: .info)
} catch {
    // handle error gracefully
}

捕获错误

您可以使用客户端中的 captureError(message:culprit:exception:tags:extra) 方法捕获错误。

// the `Exception` struct is used to represent an error (i.e.)
// init signature: Exception(value:type:module)
let exception = Exception(value: "did fail to test", type: "NSTestDomain")

do {
    try client.captureError(message: "This is a test error", culprit: "didTest() in Test.swift:12", exception: exception)
} catch {
    // handle error gracefully
}

面包屑

Sentry 支持一个名为面包屑的概念,它是指在问题发生之前发生的事件序列。

// create a generic breadcrumb
let readBC = Breadcrumb(category: "user.action", level: .info, message: "User read README")
client.addBreadcrumb(readBC)

// sentry supports two types of specialized breadcrumbs a `navigation` and `http`
// there's two build methods that will allow you to create those correctly

// this describes a URL change in a web app, a UI transition in a mobile application, etc.
let navBC = Breadcrumb.makeNavigationBreadcrumb(from: "launch", to: "firstViewController")
client.addBreadcrumb(navBC)

// this represents an HTTP request transmitted from your application.
let requestBC = Breadcrumb.makeHttpBreadcrumb(url: "http://dcvz.io", method: "GET", statusCode: 200, reason: "OK")
client.addBreadcrumb(requestBC)

// you may also clear breadcrumbs
client.clearBreadcrumbs()

沟通

  • 如果您 发现了漏洞,请打开一个问题。
  • 如果您 有功能请求,请打开一个问题。
  • 如果您 想要贡献,提交一个 pull 请求。

您也可以在 Twitter 上找到我:@dchavezlive

许可证

SentryKit 在 MIT 许可证下发布。有关详情,请参阅 LICENSE。