{"id":20683176,"url":"https://github.com/chimehq/wells","last_synced_at":"2025-04-22T12:21:39.731Z","repository":{"id":63906883,"uuid":"300754807","full_name":"ChimeHQ/Wells","owner":"ChimeHQ","description":"A lightweight diagnostics report submission system","archived":false,"fork":false,"pushed_at":"2024-07-05T17:12:00.000Z","size":94,"stargazers_count":42,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-20T21:19:10.629Z","etag":null,"topics":["apple","crash-reporting","diagnostics","ios","macos","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChimeHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["mattmassicotte"]}},"created_at":"2020-10-02T23:07:03.000Z","updated_at":"2025-03-26T13:16:57.000Z","dependencies_parsed_at":"2023-08-16T18:45:28.176Z","dependency_job_id":"5fa749e0-6f6b-4619-8104-3f91da7d5112","html_url":"https://github.com/ChimeHQ/Wells","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"31adbe6ab61cccfe716595373719ab631567beed"},"previous_names":["stacksift/wells"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FWells","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FWells/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FWells/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FWells/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChimeHQ","download_url":"https://codeload.github.com/ChimeHQ/Wells/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237868,"owners_count":21397407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","crash-reporting","diagnostics","ios","macos","swift","tvos","watchos"],"created_at":"2024-11-16T22:15:39.538Z","updated_at":"2025-04-22T12:21:39.710Z","avatar_url":"https://github.com/ChimeHQ.png","language":"Swift","funding_links":["https://github.com/sponsors/mattmassicotte"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![Platforms][platforms badge]][platforms]\n[![Discord][discord badge]][discord]\n\n\u003c/div\u003e\n\n# Wells\nA lightweight diagnostics report submission system. \n\n## Integration\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/ChimeHQ/Wells\")\n]\n```\n\n## Getting Started\n\nWells is just a submission system, and tries not to make any assumptions about the source or contents of the reports it transmits. It contains two main components: `WellsReporter` and `WellsUploader`. By default, these work together. But, `WellsUploader` can be used separately if you need more control over the process.\n\nBecause of its flexibility, Wells requires you to do a little more work to wire it up to your source of diagnostic data. Here's what an simple setup could look like. Keep in mind that Wells uploads data using `NSURLSession` background uploads. This means that the start and end of an upload may not occur during the same application launch.\n\nIf you use `WellsReporter` to submit data, it will manage the cross-launch details itself. But, if you need more control, or want to manage the on-disk files yourself, you'll need to provide it with a `ReportLocationProvider` that can map identifiers back to file URLs.\n\n```swift\nimport Foundation\nimport Wells\n\nclass MyDiagnosticReporter {\n    private let reporter: WellsReporter\n\n    init() {\n        self.reporter = WellsReporter()\n        \n        reporter.existingLogHandler = { url, date in\n            // might want to examine date to see how old\n            // the date is (and handle errors more gracefully)\n            try? submit(url: url)\n        }\n    }\n\n    func start() throws {\n        // submit files, including an identifier unique to each file\n        let logURLs = getExistingLogs()\n\n        for url in logURLs {\n            try submit(url: url)\n        }\n\n        // or, just submit bytes\n        let dataList = getExistingData()\n\n        for data in dataList {\n            let request = makeURLRequest()\n            reporter.submit(data, uploadRequest: request)\n        }\n\n    }\n\n    func submit(url: URL) throws {\n        let logIdentifier = computeUniqueIdentifier(for: url)\n        let request = makeURLRequest()\n\n        try reporter.submit(fileURL: url, identifier: logIdentifier, uploadRequest: request)\n    }\n\n    func computeUniqueIdentifier(for url: URL) -\u003e String {\n        // this works, but a more robust solution would be based on the content of the data. Note that\n        // the url itself *may not* be consistent from launch to launch.\n        return UUID().uuidString\n    }\n\n    // Finding logs/data is up to you\n    func getExistingLogs() -\u003e [URL] {\n        return []\n    }\n\n    func getExistingData() -\u003e [Data] {\n        return []\n    }\n\n    func makeURLRequest() -\u003e URLRequest {\n        // You have control over the URLRequest that Wells uses. However,\n        // some additional metadata will be added to enablee cross-launch tracking.\n        let endpoint = URL(string: \"https://mydiagnosticservice.com\")!\n\n        var request = URLRequest(url: endpoint)\n\n        request.httpMethod = \"PUT\"\n        request.addValue(\"hiya\", forHTTPHeaderField: \"custom-header\")\n\n        return request\n    }\n}\n```\n\n## Retries\n\nBecause that Wells manages submissions *across* app launches, retry logic can be complex. Wells will do its best to retry unsuccesful submissions. It respects the `Retry-After` HTTP header and has backoff. But, it is possible that the hosting app is terminated while a backoff delay is pending. In this situation, `WellsReporter` relies on its `existingLogHandler` property to avoid needing persistent storage.\n\nBy default, if there are files found within the `baseURL` directory that are older than 2 days, Wells will give up and delete them.\n\nBottom line: Wells submissions are best effort. Robust retry support means you have to make use of `existingLogHandler`. There are pathological, if improbable situations that could prevent the submission and retry system from working in a predictable way.\n\n## Using With MetricKit\n\nWells works great for submitting data gathered from MetricKit. In fact, [MeterReporter](https://github.com/ChimeHQ/MeterReporter) uses it for a full MetricKit-based reporting system.\n\nBut, you can also do it yourself. Here's a simple example.\n\n```swift\nimport Foundation\nimport MetricKit\nimport Wells\n\nclass MetricKitOnlyReporter: NSObject {\n    private let reporter: WellsReporter\n    private let endpoint = URL(string: \"https://mydiagnosticservice.com\")!\n\n    override init() {\n        self.reporter = WellsReporter()\n\n        super.init()\n\n        MXMetricManager.shared.add(self)\n    }\n\n    private func submitData(_ data: Data) {\n        var request = URLRequest(url: endpoint)\n\n        request.httpMethod = \"PUT\"\n\n        // ok, yes, I have glossed over error handling\n        try? reporter.submit(data, uploadRequest: request)\n    }\n}\n\nextension MetricKitOnlyReporter: MXMetricManagerSubscriber {\n    func didReceive(_ payloads: [MXMetricPayload]) {\n    }\n\n    func didReceive(_ payloads: [MXDiagnosticPayload]) {\n        payloads.map({ $0.jsonRepresentation() }).forEach({ submitData($0) })\n    }\n}\n```\n\n## Namesake\n\nWells is all about reporting, so it seemed logical to name it after a [notable journalist](https://en.wikipedia.org/wiki/Ida_B._Wells).\n\n## Suggestions or Feedback\n\nI would love to hear from you! Issues or pull requests work great. A [Discord server][discord] is also available for live help, but I have a strong bias towards answering in the form of documentation.\n\nI prefer collaboration, and would love to find ways to work together if you have a similar project.\n\nI prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.\n\nBy participating in this project you agree to abide by the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).\n\n[platforms]: https://swiftpackageindex.com/ChimeHQ/Wells\n[platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FChimeHQ%2FWells%2Fbadge%3Ftype%3Dplatforms\n[discord]: https://discord.gg/esFpX6sErJ\n[discord badge]: https://img.shields.io/badge/Discord-purple?logo=Discord\u0026label=Chat\u0026color=%235A64EC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimehq%2Fwells","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchimehq%2Fwells","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimehq%2Fwells/lists"}