• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    Swift
  • License
    BSD 3-Clause "New...
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Library for interacting with MetricKit

Build Status License Platforms Documentation

Meter

Meter is a companion library to MetricKit. It aims to provide the following capabilities:

  • API for MXCallStackTree
  • Types for MXDiagnostic emulation and coding
  • MXMetricManager-like interface for unsupported platforms
  • On-device symbolication
  • Account for MetricKit inconsistencies across platforms and types
  • Support for custom exception reporting

If you're also looking for a way to transmit MetricKit data to your server, have a look at MeterReporter. It uses Meter under the hood, and takes care of the details.

Integration

dependencies: [
    .package(url: "https://github.com/ChimeHQ/Meter")
]

Expanded API

The MetricKit API for crash reporting is unwieldy. In particular, MXCallStackTree lacks any kind of interface for interacting with its structure. Meter includes some classes that make it easier to work with. In addition to providing an API for MXCallStackTree, Meter includes types to emulate and parse MetricKit diagnostics.

let data = mxTree.jsonRepresentation()
let tree = try CallStackTree.from(data: data)

for frame in tree.callStacks[0].frames {
    print("\(frame.address) \(frame.binaryName) \(frame.binaryUUID)")
}

Custom Exceptions

MetricKit diagnostics does not capture or include uncaught NSExceptions. This can make it very difficult to debug certain kinds of crashes, particularly on macOS. Meter includes an ExceptionInfo type to help address this. These can be created from an NSException object, which will capture all the needed runtime information to emulate a standard CallStack.

How you actually get access to the NSException is not defined by Meter. But, if you have one, the CrashDiagnostic type also includes an exceptionInfo property that can accept one of these for easy encoding.

MXMetricManager and Diagnostics Polyfill

MetricKit's crash reporting facilities require iOS 14/macOS 12.0, and isn't supported at all for tvOS or watchOS. You may want to start moving towards using it as a standard interface between your app and whatever system consumes the data. Meter offers an API that's very similar to MetricKit's MXMetricManager to help do just that.

// adding a subscriber
MeterPayloadManager.shared.add(obj)

extension MyObject: MeterPayloadSubscriber {
    func didReceive(_ payloads: [DiagnosticPayloadProtocol]) {
        // this will be called for both simulated payloads *and* MeterKit payloads on OSes it supports
        print("received payloads \(payloads)")
    }
}

// posting diagnostics
MeterPayloadManager.shared.deliver(payloads)

This makes it easier to support the full capabilities of MetricKit when available, and gracefully degrade when they aren't. It can be nice to have a uniform interface to whatever backend system you are using to consume the reports. And, as you move towards a supported minimum, and as (hopefully) Apple starts supporting MetricKit on all platforms, it will be easier to pull out Meter altogether.

Backwards compatibility is still up to you, though. One solution is ImpactMeterAdapter, which uses Impact to collect crash data for OSes that don't support MXCrashDiagnostic.

On-Device Symbolication

The stack traces provided by MetricKit, like other types of crash logs, are not symbolicated. There are a bunch of different ways to tackle this problem, but one very convenient option is just to do it as a post-processing step on the device where the crash occurred. This does come, however, with one major drawback. It only works when you still have access to the same binaries. OS updates will almost certainly change all the OS binaries. The same is true for an app update, though in that case, an off-line symbolication step using a dSYM is still doable.

Meter provides an API for performing symbolication, via the Symbolicator protocol. The core of this protocol should be usable to symbolicate any address, and is not tied to MetricKit. But, the protocol also does include a number of convenience methods that can operate on the various MetricKit classes. The result uses the Meter's wrapper classes to return Frame instances which include a symbolInfo property. This property can be accessed directly or just re-encoded for transport.

let symbolicator = DlfcnSymbolicator()
let symPayload = symbolicator.symbolicate(payload: diagnosticPayload)

DlfcnSymbolicator

This class implements the Symbolicator protocol, and uses the functions with dlfcn.h to determine symbol/offset. This works, but does have some limitations. First, it relies on looking up symbols in the currently executing process, so it will only work if the needed binary is currently loaded.

Second, these functions return <redacted> for some binary's symbols on iOS. I know the symbol information is still accessible from the binary, so it's unclear why this is done.

This is a relatively inexpensive symbolication pass, and is a first effort. Further work here is definitely necessary.

Suggestions or Feedback

We'd love to hear from you! Get in touch via an issue or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

More Repositories

1

Impact

Crash capturing library for Apple platforms
C
431
star
2

Neon

A Swift library for efficient, flexible content-based text styling
Swift
320
star
3

Chime

An editor for macOS
Swift
303
star
4

SwiftTreeSitter

Swift API for the tree-sitter incremental parsing system
Swift
264
star
5

ConcurrencyPlus

Utilities for working with Swift Concurrency
Swift
253
star
6

OperationPlus

NSOperation's missing pieces
Swift
128
star
7

SwiftLSPClient

A Swift library for interacting with Language Server Protocol implementations
Swift
103
star
8

LanguageClient

Language Server Protocol (LSP) client for Swift
Swift
96
star
9

TextStory

Happier, more flexible NSTextStorage
Swift
92
star
10

Rearrange

Swift library for working with ranges types: NSRange, IndexSet, and String.Index
Swift
69
star
11

WindowTreatment

Tools for happier work with NSWindow
Swift
63
star
12

LanguageServerProtocol

Swift library for working with Language Server Protocol (LSP)
Swift
56
star
13

ChimeKit

Framework for building Chime extensions
Swift
49
star
14

TextViewPlus

Make life better with NSTextView+TextKit 1/2
Swift
46
star
15

OAuthenticator

OAuth 2.0 request authentication
Swift
46
star
16

TextFormation

Rules system for live typing completions
Swift
46
star
17

Extendable

A set of utilities for more pleasant work with ExtensionKit
Swift
43
star
18

Wells

A lightweight diagnostics report submission system
Swift
40
star
19

AsyncXPCConnection

Concurrency support for NSXPCConnection
Swift
40
star
20

ProcessService

Host an executable within an XPC service
Swift
39
star
21

UITestingPlus

Utilities for working with XCUI testing
Swift
38
star
22

KeyCodes

AppKit Carbon key codes to UIKey-compatible enums
Swift
35
star
23

MeterReporter

Lightweight MetricKit-based diagnostics reporting
Swift
33
star
24

NicerTouchBar

Utilities for a more pleasant NSTouchBar development experience
Swift
33
star
25

TextViewBenchmark

A suite of performance tests for macOS text views
Swift
32
star
26

Flexer

Lexing library for Swift
Swift
31
star
27

ContainedDocument

Nested NSDocuments
Swift
26
star
28

JSONRPC

Swift library for JSON-RPC
Swift
25
star
29

ProcessEnv

Capture the shell environment of a Foundation app
Swift
25
star
30

ThemePark

A Swift library for working with syntax highlighting/IDE themes
Swift
25
star
31

Glyph

Make life with TextKit better
Swift
24
star
32

Dusk

Micro-framework to aid in supporting Dark Mode on macOS
Swift
21
star
33

ScrollViewPlus

A more pleasant NSScrollView experience
Swift
16
star
34

Background

Background Tasks and Networking
Swift
16
star
35

Welp

Tooling for macOS help books
Swift
15
star
36

XPCConnectionSession

Backwards-compatible implementation of XPCSession
Swift
13
star
37

EditorConfig

A Swift library for working with .editorconfig files
Swift
13
star
38

GlobPattern

Swift package to parse and evaluate glob patterns
Swift
13
star
39

Outline

Lazy SwiftUI wrapper for NSOutlineView
Swift
12
star
40

LanguageServer

Language Server Protocol server infrastructure for Swift
Swift
11
star
41

ImpactMeterAdapter

Impact crash reports as a Meter diagnostic source
Swift
11
star
42

Gramophone

Swift library for working with Extended Backus–Naur Form (EBNF) notation and grammars.
Swift
11
star
43

CoreSymbolication

Headers and package for CoreSymbolication
Swift
11
star
44

Ligature

Text selection, grouping, indentation, and manipulation in Swift
Swift
10
star
45

ViewPlus

Make working with NSView more pleasant
Swift
10
star
46

UnifiedLoggingPlus

Micro-framework for making OSLog more pleasant
Swift
10
star
47

Textbook

Easier text views and SwiftUI
Swift
10
star
48

chime-swift

A Chime extension for Swift
Swift
9
star
49

SwiftCoreSymbolication

Swift wrappers for CoreSymbolication
Swift
9
star
50

DebugAdapterProtocol

Swift library for working with Debug Adapter Protocol (DAP)
Swift
8
star
51

SourceView

A TextKit 2 `NSTextView` subclass built specifically to work with source code
Swift
7
star
52

RelativeCollections

Swift collection types that support efficient storage of order-relative values.
Swift
7
star
53

IBeam

A Swift library for multi-cursor support
Swift
7
star
54

paddleapi

Go implementation of the Paddle API
Go
6
star
55

MetricKitViewer

A really simple app for viewing MetricKit payloads
Swift
5
star
56

Lowlight

A simple syntax processing system that prioritizes latency over correctness
Swift
5
star
57

chime-ruby

A Chime extension for Ruby
Swift
4
star
58

chime-rust

A Chime extension for Rust
Swift
4
star
59

STTextView-Plugin-TextFormation

Source Code Typing Completions
Swift
4
star
60

gogsym

Go library for reading GSYM files
Go
3
star
61

chime-markdown

A Chime extension for Markdown
3
star
62

LanguageServerScripts

A collection of standardized scripts for managing LSP language servers with a Swift API
Shell
3
star
63

chime-elixir

A Chime extension for Elixir
Swift
2
star
64

binarycursor

Go binary data reader
Go
2
star
65

chime-python

A Chime extension for Rust
Swift
2
star
66

chime-go

A Chime extension for Go
Swift
1
star
67

chime-clojure

A Chime extension for Clojure
Swift
1
star
68

marpa-xcframework

XCFramework wrapper for libmarpa
C
1
star
69

Borderline

System for working with text line numbers in Swift
Swift
1
star