snowdrop / opentracing-example

OpenTracing Jaeger booster
1 stars 7 forks source link
booster example kubernetes openshift opentracing spring-boot

== Purpose

A example that demonstrates how to configure and deploy a Spring Boot app instrumented using Opentracing.

== Technical details

This example showcases how to use include link:https://github.com/opentracing-contrib/java-spring-jaeger[opentracing-spring-jaeger-web-starter] to instrument a Spring Boot application by enabling the reporting of Traces to a OpenTracing compatible collector

== Deploying and interacting with the example

=== Spring Boot running locally

  1. Install Jaeger on OpenShift to collect the traces

[source,bash]

oc project jaeger oc process -f https://raw.githubusercontent.com/jaegertracing/jaeger-openshift/master/all-in-one/jaeger-all-in-one-template.yml | oc create -f -

  1. Create a route to access the Jaeger collector

[source,bash]

oc expose service jaeger-collector --port=14268 -n jaeger

  1. Specify next the url address of the Jaeger Collector to be used

Get the route address

[source,bash]

oc get route/jaeger-collector --template={{.spec.host}} -n jaeger

Add the following jaeger properties to the application.yml file with the route address of the collector

[source,yaml]

opentracing: jaeger: log-spans: true http-sender: url: http://jaeger-collector-jaeger.ocp.spring-boot.osepool.centralci.eng.rdu2.redhat.com/api/traces

  1. Start Spring Boot

[source,bash]

mvn spring-boot:run -Dspring.profiles.active=local

  1. Issue a http request

[source,bash]

http http://localhost:8080/hello HTTP/1.1 200 Content-Length: 23 Content-Type: text/plain;charset=UTF-8 Date: Wed, 10 Jan 2018 16:00:50 GMT

Hello from Spring Boot running on a local machine !'

  1. Open the Jaeger console to fetch the traces

[source,bash]

oc get route/jaeger-query --template={{.spec.host}} open https://jaeger-query-jaeger.ocp.spring-boot.osepool.centralci.eng.rdu2.redhat.com/search

or query it from a terminal

[source,bash]

http --verify=no https://jaeger-query-jaeger.ocp.spring-boot.osepool.centralci.eng.rdu2.redhat.com/api/traces?service=spring-boot HTTP/1.1 200 OK Cache-control: private Content-Type: application/json Date: Wed, 10 Jan 2018 17:13:34 GMT Set-Cookie: f2a76eea670eef399f3e86a8a443f3e5=713f7dc386ce37099352855f8ec66619; path=/; HttpOnly Transfer-Encoding: chunked

{ "data": [ { "processes": { "p1": { "serviceName": "spring-boot", "tags": [ { "key": "hostname", "type": "string", "value": "dabou" },


=== Spring Boot deployed on OpenShift with Jaeger Agent as sidecar

As Fabric8 Maven Plugin doesn't allow to easily add a side car container within the DeploymentConfig yaml file generated, then an OpenShift Template should be created to build/deploy it on OpenShift !!!!

  1. Instructions to install the template, create a new app/deployment from the template and next start the s2i build

[source,bash]

oc new-project demo oc create -f openshift/spring-boot-tracing.yml oc new-app spring-boot-tracing-template \ -p SOURCE_REPOSITORY_URL=https://github.com/snowdrop/opentracing-example.git ... oc logs -f bc/spring-boot-tracing-s2i

  1. To start a new build

[source,bash]

oc start-build spring-boot-tracing-s2i

  1. Get the route and curl the service

[source,bash]

oc get route/spring-boot-tracing --template={{.spec.host}} http http://spring-boot-tracing-demo.ocp.spring-boot.osepool.centralci.eng.rdu2.redhat.com/hello