{"id":28540312,"url":"https://github.com/airbrake/javabrake","last_synced_at":"2025-07-07T10:31:24.443Z","repository":{"id":23416134,"uuid":"96228578","full_name":"airbrake/javabrake","owner":"airbrake","description":"Airbrake notifier for Java","archived":false,"fork":false,"pushed_at":"2023-01-05T05:43:46.000Z","size":16459,"stargazers_count":14,"open_issues_count":2,"forks_count":8,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-06-09T19:08:58.009Z","etag":null,"topics":["airbrake","error-reporting","java","logging","notifier"],"latest_commit_sha":null,"homepage":"https://docs.airbrake.io/docs/platforms/java/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/airbrake.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","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":"2017-07-04T14:50:53.000Z","updated_at":"2025-03-05T10:04:13.000Z","dependencies_parsed_at":"2023-01-13T23:16:11.700Z","dependency_job_id":null,"html_url":"https://github.com/airbrake/javabrake","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/airbrake/javabrake","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fjavabrake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fjavabrake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fjavabrake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fjavabrake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/airbrake","download_url":"https://codeload.github.com/airbrake/javabrake/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fjavabrake/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264060553,"owners_count":23551255,"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":["airbrake","error-reporting","java","logging","notifier"],"created_at":"2025-06-09T19:09:01.736Z","updated_at":"2025-07-07T10:31:24.437Z","avatar_url":"https://github.com/airbrake.png","language":"Java","readme":"Javabrake\n=========\n\n[![.github/workflows/test.yml](https://github.com/airbrake/javabrake/actions/workflows/test.yml/badge.svg)](https://github.com/airbrake/javabrake/actions/workflows/test.yml)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://airbrake-github-assets.s3.amazonaws.com/brand/airbrake-full-logo.png\" width=\"200\"\u003e\n\u003c/p\u003e\n\n## Introduction\n\nJavabrake is a Java notifier for Airbrake.\n\n## Installation\n\nGradle:\n\n```gradle\nimplementation 'io.airbrake:javabrake:0.3.0'\n```\n\nMaven:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.airbrake\u003c/groupId\u003e\n  \u003cartifactId\u003ejavabrake\u003c/artifactId\u003e\n  \u003cversion\u003e0.3.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nIvy:\n\n```xml\n\u003cdependency org='io.airbrake' name='javabrake' rev='0.3.0'\u003e\n  \u003cartifact name='javabrake' ext='pom'\u003e\u003c/artifact\u003e\n\u003c/dependency\u003e\n```\n\n## Quickstart\n\nConfiguration:\n\n```java\nimport io.airbrake.javabrake.Notifier;\nimport io.airbrake.javabrake.Config;\n\nConfig config = new Config();\nconfig.projectId = 12345;\nconfig.projectKey = \"FIXME\";\nNotifier notifier = new Notifier(config);\n\nnotifier.addFilter(\n    (Notice notice) -\u003e {\n      notice.setContext(\"environment\", \"production\");\n      return notice;\n    });\n```\n\n## Error Monitoring\n\n### Sending errors to Airbrake\n\n#### Using `notifier` directly\n\n```java\ntry {\n  do();\n} catch (IOException e) {\n  notifier.report(e);\n}\n```\n\n#### Using `Airbrake` proxy class\n\n```java\nimport io.airbrake.javabrake.Airbrake;\n\ntry {\n  do();\n} catch (IOException e) {\n  Airbrake.report(e);\n}\n```\n\n### Sending errors synchronously\n\nBy default `report` sends errors asynchronously returning a `Future`, but synchronous API is also available:\n\n```java\nimport io.airbrake.javabrake.Notice;\n\nNotice notice = Airbrake.reportSync(e);\nif (notice.exception != null) {\n    logger.info(notice.exception);\n} else {\n    logger.info(notice.id);\n}\n```\n\n### Adding custom params\n\nTo set custom params you can build and send notice in separate steps:\n\n```java\nimport io.airbrake.javabrake.Notice;\n\nNotice notice = Airbrake.buildNotice(e);\nnotice.setContext(\"component\", \"mycomponent\");\nnotice.setParam(\"param1\", \"value1\");\nAirbrake.send(notice);\n```\n\nYou can also set custom params on all reported notices:\n\n```java\nnotifier.addFilter(\n    (Notice notice) -\u003e {\n      notice.setParam(\"myparam\", \"myvalue\");\n      return notice;\n    });\n```\n\n### Linking errors to routes\n\nYou can link error notices with the routes by setting the route e.g. /hello and httpMethod e.g. GET, POST in the custom parameters for error notices. For example:\n\n```java\nNotice notice = notifier.buildNotice(e);\nnotice.setContext(\"route\", \"route-name\");\nnotice.setContext(\"httpMethod\", \"http-method-name\");\n```\n\n### Ignoring notices\n\ngnore specific notice:\n\n```java\nnotifier.addFilter(\n    (Notice notice) -\u003e {\n      if (notice.context.get(\"environment\") == \"development\") {\n          // Ignore notice.\n          return null;\n      }\n      return notice;\n    });\n```\n\n### Debugging notices\n\nTo debug why notices are not sent you can use `onReportedNotice` hook:\n\n```java\nnotifier.onReportedNotice(\n    (notice) -\u003e {\n      if (notice.exception != null) {\n        logger.info(notice.exception);\n      } else {\n        logger.info(String.format(\"notice id=%s url=%s\", notice.id, notice.url));\n      }\n    });\n```\n\n## Performance Monitoring\n\nYou can read more about our [Performance Monitoring offering in our docs][docs/performance].\n\n### Sending route stats\n\n`notifier.routes.notify` allows sending route stats to Airbrake. You can also use this API manually:\n\n```java\nimport io.airbrake.javabrake.RouteMetric;\n\nRouteMetric metric = new RouteMetric(request.getMethod(), request.getRequestURI());\nmetric.statusCode = response.getStatus();\nmetric.contentType = response.getContentType();\nmetric.endTime = new Date();\n\nnotifier.routes.notify(metric);\n```\n\n### Sending route breakdowns\n\n`notifier.routes.notify` allows sending performance breakdown stats\nto Airbrake. You can use this API manually:\n\n```java\nimport io.airbrake.javabrake.RouteMetric;\n\nRouteMetric metric = new RouteMetric(request.getMethod(), request.getRequestURI());\n\nmetric.startSpan(\"span1 name\", new Date());\ntry {\n\tdo();\n} catch (Exception e) {\n\te.printStackTrace();\n}\nmetric.endSpan(\"span1 name\", new Date());\n\nmetric.startSpan(\"span2 name\", new Date());\ntry {\n  do();\n} catch (Exception e) {\n\te.printStackTrace();\n}\nmetric.endSpan(\"span2 name\", new Date());\t\t\nmetric.end();\n\nmetric.statusCode = response.getStatus();\nmetric.contentType = response.getContentType();\n\nnotifier.routes.notify(metric);\n```\n\n### Sending query stats\n\n`notifier.queries.notify` allows sending SQL query stats to Airbrake. You can also use this API manually:\n\n```java\nDate startTime = new Date();\ntry\n{\n  do();\n}catch(\nException e)\n{\n  e.printStackTrace();\n}\nDate endTime = new Date();\n\nnotifier.queries.notify(request.getMethod(),request.getRequestURI()\n,\"SELECT * FROM foos\",startTime,endTime);\n```\n\n### Sending queue stats\n\n`notifier.queues.notify` allows sending queue (job) stats to Airbrake. You can also use this API manually:\n\n```java\nimport io.airbrake.javabrake.QueueMetric;\n\nQueueMetric metric = new QueueMetric(\"foo_queue\");\n\nmetric.startSpan(\"span1 name\", new Date());\ntry {\n    do();\n} catch (Exception e) {\n    e.printStackTrace();\n}\nmetric.endSpan(\"span1 name\", new Date());\n\nmetric.startSpan(\"span2 name\", new Date());\ntry {\n  do();\n} catch (Exception e) {\n  e.printStackTrace();\n}\nmetric.endSpan(\"span2 name\", new Date());\nmetric.end();\n\nnotifier.queues.notify(metric);\n\n```\n\nFor more information visit [docs](https://docs.airbrake.io/docs/platforms/java/)\n\n## log4j2 integration\n\nSee https://github.com/airbrake/log4javabrake2\n\n## logback integration\n\nSee https://github.com/airbrake/logback\n\n## HTTP proxy\n\njavabrake uses [OkHttp](http://square.github.io/okhttp/) as an HTTP client. So in order to use proxy all you have to do is to configure OkHttpClient:\n\n```java\nimport java.net.InetSocketAddress;\n\nimport okhttp3.OkHttpClient;\nimport okhttp3.Proxy;\n\nimport io.airbrake.javabrake.OkSender;\n\nProxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(\"192.168.1.105\", 8081);\nOkHttpClient httpClient =\n    new OkHttpClient.Builder()\n        .connectTimeout(3000, TimeUnit.MILLISECONDS)\n        .readTimeout(3000, TimeUnit.MILLISECONDS)\n        .writeTimeout(3000, TimeUnit.MILLISECONDS)\n        .proxy(proxy)\n        .build();\nOkSender.setOkHttpClient(httpClient);\n```\n\n## Notifier release instrucitons\n\n### A note on Java version\nMake sure you build and release this notifier with open-jdk-8, one way to manage your local java version is using [asdf](https://asdf-vm.com). You can install this tool via homebrew:\n```\nbrew install asdf\n```\nThen install open-jdk-8 and set it as JAVA home before running any of the `./gradlew` commands:\n```\nasdf plugin add java\nasdf install java adoptopenjdk-8.0.312+7\nexport JAVA_HOME=$HOME/.asdf/installs/java/adoptopenjdk-8.0.312+7\n```\n\n### Build\n\n```shell\n./gradlew build\n```\n\nUpload to JCentral:\n\n```shell\n./gradlew bintrayUpload\n```\n\nUpload to Maven Central:\n\n```shell\n./gradlew uploadArchives\n./gradlew closeAndReleaseRepository\n```\n\nUsefull links:\n - http://central.sonatype.org/pages/gradle.html\n - http://central.sonatype.org/pages/releasing-the-deployment.html\n\n\n[docs/performance]: https://docs.airbrake.io/docs/overview/apm/#monitoring-java-apps","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairbrake%2Fjavabrake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fairbrake%2Fjavabrake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairbrake%2Fjavabrake/lists"}