{"id":20337340,"url":"https://github.com/expediadotcom/opentracing-spring-haystack-example","last_synced_at":"2025-10-09T06:17:45.533Z","repository":{"id":87471538,"uuid":"163644453","full_name":"ExpediaDotCom/opentracing-spring-haystack-example","owner":"ExpediaDotCom","description":null,"archived":false,"fork":false,"pushed_at":"2020-01-28T10:14:10.000Z","size":334,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-11T22:42:42.552Z","etag":null,"topics":["distributed-tracing","haystack","opentracing","spring"],"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,"zenodo":null}},"created_at":"2018-12-31T06:14:48.000Z","updated_at":"2022-07-23T08:35:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"e83565a7-e12a-4cd2-b91d-a61af90365f9","html_url":"https://github.com/ExpediaDotCom/opentracing-spring-haystack-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ExpediaDotCom/opentracing-spring-haystack-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fopentracing-spring-haystack-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fopentracing-spring-haystack-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fopentracing-spring-haystack-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fopentracing-spring-haystack-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExpediaDotCom","download_url":"https://codeload.github.com/ExpediaDotCom/opentracing-spring-haystack-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaDotCom%2Fopentracing-spring-haystack-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000854,"owners_count":26082950,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","haystack","opentracing","spring"],"created_at":"2024-11-14T21:08:42.426Z","updated_at":"2025-10-09T06:17:45.529Z","avatar_url":"https://github.com/ExpediaDotCom.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/ExpediaDotCom/opentracing-spring-haystack-example.svg?branch=master)](https://travis-ci.org/ExpediaDotCom/opentracing-spring-haystack-example)\n[![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://github.com/ExpediaDotCom/haystack/blob/master/LICENSE)\n## Table of Contents\n\n- [Opentracing-spring-haystack-web-starter example](#opentracing-spring-haystack-web-starter-example)\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## Opentracing-spring-haystack-web-starter example\n\nIn this example, the two spring controllers 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.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. It also shows the blobs integration. Every request/response that hits the server and sent by REST client is captured as the blobs. A corresponding tag is written to derefer the blobs' location. This is an example application written with two simple Spring controllers to show how a spring application can be instrumented with [opentracing-spring-haystack-web-starter](https://github.com/ExpediaDotCom/haystack-client-java/tree/master/integrations/opentracing-spring-haystack-web-starter). \n\n* Controller one:  Backend.  This listens on port 9091 and exposes one endpoint : http://localhost:9091/api/hello - when invoked, it returns a simple string like `Hello, It's Wed Jan 30 11:06:37 PST 2019`\n\n* Controller two:  Frontend:  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### Instrumentation\n\nIf one peeks into the code, both [Frontend.java](src/main/java/com/expedia/haystack/opentracing/spring/example/Frontend.java) and [Backend.java](src/main/java/com/expedia/haystack/opentracing/spring/example/Backend.java) are simple Spring controllers with no additional instrumentation code.  Most of the instrumentation is done by the dependency `opentracing-spring-haystack-web-starter`, that is included in the [pom.xml](pom.xml). For more information how this library works, one can check the documentations at [https://github.com/opentracing-contrib/java-spring-cloud](https://github.com/opentracing-contrib/java-spring-cloud) and [https://github.com/ExpediaDotCom/haystack-client-java/tree/master/integrations/opentracing-spring-haystack-web-starter](https://github.com/ExpediaDotCom/haystack-client-java/tree/master/integrations/opentracing-spring-haystack-web-starter)\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 [application.yml](src/main/resources/application.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 -Dstart-class=com.expedia.haystack.opentracing.spring.example.Starter -Dexec.args=\"backend\" \n./mvnw exec:java -Dstart-class=com.expedia.haystack.opentracing.spring.example.Starter -Dexec.args=\"frontend\"\n```\n\nor with docker \n\n```\ndocker build -t opentracing-spring-haystack-example .\ndocker run -e APP_MODE=frontend -p 9090:9090 -t opentracing-spring-haystack-example:latest\ndocker run -e APP_MODE=backend -p 9091:9091 -t opentracing-spring-haystack-example:latest\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   2019-01-30 11:33:34.679  INFO 99714 --- [nio-9090-exec-1] span-logger                              : {},707ab6be-79b3-49e9-ad16-0894dfe4267a,ef38e68f-94d7-488b-9430-1ca9339a2a64,2967e7f0-3356-4262-a1f6-f307999425a9,false,GET,{http.status_code=200, component=java-spring-rest-template, span.kind=client, http.url=http://localhost:9091/api/hello, peer.port=9091, http.method=GET},[],[child_of,{},707ab6be-79b3-49e9-ad16-0894dfe4267a,2967e7f0-3356-4262-a1f6-f307999425a9,\u003cnull\u003e,false],149000,1548876814679000,1548876814530000,true,[]\n   2019-01-30 11:33:34.745  INFO 99714 --- [nio-9090-exec-1] span-logger                              : {},707ab6be-79b3-49e9-ad16-0894dfe4267a,2967e7f0-3356-4262-a1f6-f307999425a9,\u003cnull\u003e,false,callBackend,{http.status_code=200, component=java-web-servlet, span.kind=server, http.url=http://localhost:9090/hello, http.method=GET},[868766461349835,{handler.class_simple_name=Frontend, handler=public java.lang.String com.expedia.haystack.opentracing.spring.example.Frontend.callBackend(), event=preHandle, handler.method_name=callBackend}, 868766700946419,{event=afterCompletion, handler=public java.lang.String com.expedia.haystack.opentracing.spring.example.Frontend.callBackend()}],[],267000,1548876814745000,1548876814478000,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   2019-01-30 11:33:34.678  INFO 99244 --- [io-9091-exec-10] span-logger                              : {},707ab6be-79b3-49e9-ad16-0894dfe4267a,ef38e68f-94d7-488b-9430-1ca9339a2a64,2967e7f0-3356-4262-a1f6-f307999425a9,false,sayHello,{http.status_code=200, component=java-web-servlet, span.kind=server, http.url=http://localhost:9091/api/hello, http.method=GET},[868766521744239,{handler.class_simple_name=Backend, handler=public java.lang.String com.expedia.haystack.opentracing.spring.example.Backend.sayHello() throws java.lang.InterruptedException, event=preHandle, handler.method_name=sayHello}, 868766641580836,{event=afterCompletion, handler=public java.lang.String com.expedia.haystack.opentracing.spring.example.Backend.sayHello() throws java.lang.InterruptedException}],[child_of,{},707ab6be-79b3-49e9-ad16-0894dfe4267a,ef38e68f-94d7-488b-9430-1ca9339a2a64,2967e7f0-3356-4262-a1f6-f307999425a9,true],123000,1548876814678000,1548876814555000,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 [application-remote.yml](src/main/resources/application-remote.yml)\n\n```bash\n./mvnw exec:java -Dstart-class=com.expedia.haystack.opentracing.spring.example.Starter -Dexec.args=\"backend\" -Dspring.profiles.active=remote\n./mvnw exec:java -Dstart-class=com.expedia.haystack.opentracing.spring.example.Starter -Dexec.args=\"frontend\" -Dspring.profiles.active=remote\n```\nor with docker as\n\n```\ndocker build -t opentracing-spring-haystack-example .\ndocker run -e APP_MODE=frontend -e SPRING_PROFILE=remote -p 9090:9090 -t opentracing-spring-haystack-example:latest\ndocker run -e APP_MODE=backend -e SPRING_PROFILE=remote -p 9091:9091 -t opentracing-spring-haystack-example:latest\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%2Fopentracing-spring-haystack-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpediadotcom%2Fopentracing-spring-haystack-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediadotcom%2Fopentracing-spring-haystack-example/lists"}