{"id":19922282,"url":"https://github.com/isopropylcyanide/async-metrics-codahale","last_synced_at":"2026-06-10T00:31:25.715Z","repository":{"id":57720280,"uuid":"211720450","full_name":"isopropylcyanide/async-metrics-codahale","owner":"isopropylcyanide","description":"Leverage Codahale metrics (or any Metric Registry for that matter) to provide metrics on methods that complete asynchronously.","archived":false,"fork":false,"pushed_at":"2020-10-13T16:22:59.000Z","size":41,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T00:11:25.568Z","etag":null,"topics":["aop","aspectj","async","codahale-metrics","completable-future","dropwizard-metrics","guice","guice-aop","java-8"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isopropylcyanide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-29T20:14:27.000Z","updated_at":"2023-04-19T18:38:55.000Z","dependencies_parsed_at":"2022-08-25T15:50:42.117Z","dependency_job_id":null,"html_url":"https://github.com/isopropylcyanide/async-metrics-codahale","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isopropylcyanide%2Fasync-metrics-codahale","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isopropylcyanide%2Fasync-metrics-codahale/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isopropylcyanide%2Fasync-metrics-codahale/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isopropylcyanide%2Fasync-metrics-codahale/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isopropylcyanide","download_url":"https://codeload.github.com/isopropylcyanide/async-metrics-codahale/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241348356,"owners_count":19948164,"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":["aop","aspectj","async","codahale-metrics","completable-future","dropwizard-metrics","guice","guice-aop","java-8"],"created_at":"2024-11-12T22:10:27.501Z","updated_at":"2026-06-10T00:31:25.708Z","avatar_url":"https://github.com/isopropylcyanide.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Async Metrics Using Guice AOP\n![Travis (.org)](https://img.shields.io/travis/isopropylcyanide/async-metrics-codahale)\n![Codecov](https://img.shields.io/codecov/c/github/isopropylcyanide/async-metrics-codahale)\n![Maven Central](https://img.shields.io/maven-central/v/com.github.isopropylcyanide/async-codahale-metrics)\n![GitHub](https://img.shields.io/github/license/isopropylcyanide/async-metrics-codahale?color=blue)\n\nLeverage Codahale metrics (or any Metric Registry for that matter) to provide metrics on methods that complete asynchronously. The library requires `Guice AOP` to work (bundled by default)\n\n## Maven Artifacts\n\nThis project is available on Maven Central. To add it to your project you can add the following dependency to your\n`pom.xml`:\n\n```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.isopropylcyanide\u003c/groupId\u003e\n        \u003cartifactId\u003easync-codahale-metrics\u003c/artifactId\u003e\n        \u003cversion\u003e1.0\u003c/version\u003e\n     \u003c/dependency\u003e\n```\n        \n## Features\n\n| Annotation | Codahale Equivalent |\n| ------------- | ------------- |\n| @AsyncTimed |  @Timed |\n| @AsyncMetered | @Meter |\n| @AsyncExceptionMetered | @ExceptionMetered |\n\n\n## Usage\n\n- Initialise the Module in your Guice Injector\n\n```java\n    ...    \n    MetricRegistry registry = new MetricRegistry();\n    Guice.createInjector(new AsyncMetricsModule(metricRegistry));    \n    ...\n```\n\n- Annotate the required methods with the required annotation\n\n```java\n@AsyncTimed\n@AsyncExceptionMetered\nCompletableFuture\u003cInteger\u003e asyncMethodThatCompletesNormally() {\n    return CompletableFuture\n            .supplyAsync(() -\u003e StringUtils.split(getClass().getName(), \".\"))\n           .thenApply(s -\u003e s.length);\n}\n```\n\n```java\n@AsyncMetered\nCompletableFuture\u003cString\u003e asyncMethodThatCompletesNormally() {\n    return CompletableFuture.supplyAsync(() -\u003e \"Hello World\");\n}\n```\n\n## Why another metrics library?\nWe wish to leverage [`Dropwizard metrics`](https://github.com/dropwizard/metrics/tree/4.1-development/metrics-annotation/src/main/java/com/codahale/metrics/annotation) for async callbacks. The likes of `@Timed` or `@ExceptionMetered` for methods that return `Futures` or `CompletableFutures` or `Callbacks` \n\nThese annotation for marking a method of an annotated object make the code much more readable and separate the unnecessary boilerplate of marking metrics from the business logic\n\n```\n@Timed                                          @Timed\n@ExceptionMetered                               @ExceptionMetered                              \npublic X getX() {                               public Future\u003cX\u003e getX() {\n    //business logic                                //business logic that might execute asynchronously\n    return x;                                       return Future.of(x)        \n}                                               }\n     \n  Works as expected                             Doesn't work as expected\n```\n\nHowever, the second approach won't produce correct results as if the calling thread dispatches the work to another thread in the pool then this method execution completes without waiting for the result. Ideally, we want to mark our metrics and figure out a way to do meta stuff once the callback resolves either successfully or exceptionally. That is why this library as created.\n\n\n## Enhancements\n- Feel free to extend this to mark any `custom metrics`. All you need is an annotation and the corresponding aspects\n- Instead of `Codahale Metric Registry` it can be extended to any registry.\n- Instead of `completable future`, it can be any random callback. The only requirement is of a hook to execute action post callback resolution that doesn't block.\n\n\n## Testing\n- Create a driver class with a new metric registry\n- Install the module\n- Set up a local Console reporter\n\n```java\nConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)\n       .convertRatesTo(TimeUnit.SECONDS)\n       .convertDurationsTo(TimeUnit.MILLISECONDS)\n       .build();\n   reporter.start(1, TimeUnit.SECONDS);\n```\n\n## Wiki\nhttps://medium.com/@aman_garg/leveraging-async-metrics-using-aspects-81838b9b887e\n\n## Support\n\nPlease file bug reports and feature requests in [GitHub issues](https://github.com/isopropylcyanide/async-metrics-codahale/issues).\n\n\n## License\n\nCopyright (c) 2012-2020 Aman Garg\n\nThis library is licensed under the Apache License, Version 2.0.\n\nSee http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisopropylcyanide%2Fasync-metrics-codahale","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisopropylcyanide%2Fasync-metrics-codahale","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisopropylcyanide%2Fasync-metrics-codahale/lists"}