{"id":20337332,"url":"https://github.com/expediadotcom/haystack-dropwizard-example","last_synced_at":"2025-10-26T06:40:32.245Z","repository":{"id":87471490,"uuid":"169056807","full_name":"ExpediaDotCom/haystack-dropwizard-example","owner":"ExpediaDotCom","description":null,"archived":false,"fork":false,"pushed_at":"2019-07-04T04:21:54.000Z","size":312,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-01-14T17:30:41.286Z","etag":null,"topics":["distributed-tracing","dropwizard","haystack","opentracing"],"latest_commit_sha":null,"homepage":null,"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/ExpediaDotCom.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-04T09:46:39.000Z","updated_at":"2019-11-07T02:52:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"6753774e-9e6d-471b-86bd-29e5ab71322b","html_url":"https://github.com/ExpediaDotCom/haystack-dropwizard-example","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/ExpediaDotCom%2Fhaystack-dropwizard-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fhaystack-dropwizard-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fhaystack-dropwizard-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fhaystack-dropwizard-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExpediaDotCom","download_url":"https://codeload.github.com/ExpediaDotCom/haystack-dropwizard-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241860013,"owners_count":20032318,"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":["distributed-tracing","dropwizard","haystack","opentracing"],"created_at":"2024-11-14T21:08:41.718Z","updated_at":"2025-10-26T06:40:27.206Z","avatar_url":"https://github.com/ExpediaDotCom.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Table of Contents\n\n- [Haystack-dropwizard](#Haystack-dropwizard)\n- [About this example](#about-this-example)\n  * [Instrumentation](#instrumentation)\n- [Running this example](#running-this-example)\n  * [Build](#build)\n  * [Run with no backend](#run-with-no-backend)\n  * [Run with Haystack server](#run-with-haystack-server)\n\n## Haystack-dropwizard\n\nIn this example, the two Dropwizard services call one from another to show a client and server working with tracing instrumentation. Telemetry from this application is recorded in [Haystack](http://expediadotcom.github.io/haystack/) server, a distributed tracing system. Haystack will allow one to see the service call dependency and how long it took for the whole operation to complete. Here is what a sample output in the UI will look like: \n\n![haystack-ui](doc/screenshot-traces.png)\n\n## About this example\n\nThis is a very basic example that can output the instrumentation to console and/or a Haystack server. This is an example application written with two simple Dropwizard Services to show how a dropwizard application can be instrumented with [haystack-client-java dropwizard integration](https://github.com/ExpediaDotCom/haystack-client-java/tree/master/integrations/dropwizard). \n\n* Frontend service:  This listens on port 9090 and exposes one endpoint: http://localhost:9090/hello  - this in turn calls the endpoint exposed by `Backend` and proxy the response\n\n* Backend service:  This listens on port 9091 and exposes one endpoint : http://localhost:9091/api - when invoked, it returns a simple string like `Hello, Haystack!`\n\n### Instrumentation\n\nIf one peeks into the code, both [Frontend.java](src/main/java/com/expedia/www/haystack/dropwizard/example/resources/Frontend.java) and [Backend.java](src/main/java/com/expedia/www/haystack/dropwizard/example/resources/Backend.java) are simple Dropwizard resources with no additional instrumentation code other than `@Traced` annotation. All of the required wiring are done in the [FrontendApplication.java](src/main/java/com/expedia/www/haystack/dropwizard/example/FrontendApplication.java) and BackendApplication.java respectively. Heavy lifting is done by the dependencies `haystack-client-dropwizard` and `opentracing-jaxrs2` that are included in the [pom.xml](pom.xml). For more information on how those libraries work, one can check the documentations at [https://github.com/opentracing-contrib/java-jaxrs](https://github.com/opentracing-contrib/java-jaxrs) and [https://github.com/ExpediaDotCom/haystack-client-java/tree/master/integrations/dropwizard](https://github.com/ExpediaDotCom/haystack-client-java/tree/master/integrations/dropwizard)\n\n## Running this example\n\n### Build\n\nRequired:\n\n* Java 1.8\n\n\nBuild:\n\n```bash\n./mvnw clean compile\n```\n\nThere are two modes to run the application. One with no `Haystack` server, where the instrumentation is simply logged to the console and with Haystack server.\n\n### Run with no backend\n\nIn this mode, the application runs with the configuration in [frontend_local.yml](frontend_local.yml) and [backend_local.yml](backend_local.yml) which configures the instrumentation to use a simple logger as the dispatcher.\n\nTo run the example in this mode, execute \n\n```bash\n./mvnw exec:java -Dexec.args=\"frontend local\"\n./mvnw exec:java -Dexec.args=\"backend local\"\n```\n\nand send a sample request\n\n```bash\ncurl http://localhost:9090/hello\n```\n\nWith that, one will see two lines in the console log of `Frontend`. One for the request it received from the `curl` with `span.kind=server` and one for the request it sent to the backend with `span.kind=client`\n\nFront end:\n\n```\n   INFO  [2019-02-08 09:56:48,150] dispatcher: {},c0fc5228-4422-4305-8dad-b6aa3d6016af,40cb7928-aa03-4bb1-9650-d78ff3329016,ea12803c-9955-4c2e-9be2-f208232b7d4a,false,GET,{http.status_code=200, span.kind=client, http.url=http://localhost:9091/api?name=Haystack, peer.hostname=localhost, peer.port=9091, http.method=GET},[],[child_of,{},c0fc5228-4422-4305-8dad-b6aa3d6016af,ea12803c-9955-4c2e-9be2-f208232b7d4a,\u003cnull\u003e,false],245000,1549619808150000,1549619807905000,true,[]\n   INFO  [2019-02-08 09:56:48,230] dispatcher: {},c0fc5228-4422-4305-8dad-b6aa3d6016af,ea12803c-9955-4c2e-9be2-f208232b7d4a,\u003cnull\u003e,false,/hello,{http.status_code=200, span.kind=server, http.url=http://localhost:9090/hello, http.method=GET},[],[],427000,1549619808230000,1549619807803000,true,[]\n```\n\nAnd one line in the backend console log for the request it received from the front end application. Another point to note will be the same ids between client and server.\n\n```\n   INFO  [2019-02-08 09:56:48,146] dispatcher: {},c0fc5228-4422-4305-8dad-b6aa3d6016af,40cb7928-aa03-4bb1-9650-d78ff3329016,ea12803c-9955-4c2e-9be2-f208232b7d4a,false,sayHello,{http.status_code=200, span.kind=server, http.url=http://localhost:9091/api?name=Haystack, http.method=GET},[],[child_of,{},c0fc5228-4422-4305-8dad-b6aa3d6016af,40cb7928-aa03-4bb1-9650-d78ff3329016,ea12803c-9955-4c2e-9be2-f208232b7d4a,true],88000,1549619808146000,1549619808058000,true,[]\n```\n\n\n### Run with Haystack server\n\nTo start haystack and agent locally, one can follow the instructions at [https://github.com/ExpediaDotCom/haystack-docker#to-start-haystacks-traces-trends-and-service-graph](https://github.com/ExpediaDotCom/haystack-docker#to-start-haystacks-traces-trends-and-service-graph)\n \nAfter starting Haystack server, run this example with the following commands. This starts the application with the configuration in [frontend_remote.yml](frontend_remote.yml) and [backend_remote.yml](backend_remote.yml)\n\n```bash\n./mvnw exec:java -Dexec.args=\"frontend remote\"\n./mvnw exec:java -Dexec.args=\"backend remote\"\n```\n\nand send a sample request\n\n```bash\ncurl http://localhost:9090/hello\n```\n\nAnd then open Haystack UI at [http://localhost:8080/](http://localhost:8080/) and search for `serviceName=Frontend` to see the traces. (see screenshot above)\n\nOne can also use the sample script we have to send more requests to the sample application and see metrics such as count, duration histogram etc in Haystack UI under trends.\n\n```bash\n./run.sh\n```\n\nScreenshot of the trends view with computed metrics:\n\n\n![haystack-ui](doc/screenshot-trends.png)\n\n   \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediadotcom%2Fhaystack-dropwizard-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpediadotcom%2Fhaystack-dropwizard-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediadotcom%2Fhaystack-dropwizard-example/lists"}