A example that demonstrates how to configure and deploy a Spring Boot app instrumented using Opentracing.
This example showcases how to use include opentracing-spring-jaeger-web-starter to instrument a Spring Boot application by enabling the reporting of Traces to a OpenTracing compatible collector
-
Install Jaeger on OpenShift to collect the traces
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 -
-
Create a route to access the Jaeger collector
oc expose service jaeger-collector --port=14268 -n jaeger
-
Specify next the url address of the Jaeger Collector to be used
Get the route address
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
opentracing:
jaeger:
log-spans: true
http-sender:
url: http://jaeger-collector-jaeger.ocp.spring-boot.osepool.centralci.eng.rdu2.redhat.com/api/traces
-
Start Spring Boot
mvn spring-boot:run -Dspring.profiles.active=local
-
Issue a http request
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 !'
-
Open the Jaeger console to fetch the traces
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
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"
},
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 !!!!
-
Instructions to install the template, create a new app/deployment from the template and next start the s2i build
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
-
To start a new build
oc start-build spring-boot-tracing-s2i
-
Get the route and curl the service
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