Code supporting the blog post related to Spring Observability support in Spring Boot 3.0.0
Original blog link : https://spring.io/blog/2022/10/12/observability-with-spring-boot-3
-
https://openvalue.blog/posts/2022/12/16/tracing-in-spring-boot-2-and-3/
-
https://spring.io/blog/2022/09/16/spring-cloud-sleuth-opentelemetry-otel-1-1-0-has-been-released
-
https://www.baeldung.com/spring-cloud-sleuth-single-application
-
https://github.com/micrometer-metrics/tracing/wiki/Spring-Cloud-Sleuth-3.1-Migration-Guide
-
https://grafana.com/grafana/dashboards/17175-spring-boot-observability/
-
app-server and app-boot-3 are compiled with native profile, installation of the necessary tools can be found in the file docker/ci/Dockerfile-nativeBuilder
$ mvn -pl app-client clean compile jib:dockerBuild -Djib.to.image=app-client:v1
$ mvn -pl app-boot-2 clean compile jib:dockerBuild -Djib.to.image=app-boot-2:v1
$ mvn -Pnative -pl app-boot-3 native:compile
$ bash -c "cd app-boot-3 && docker build -t app-boot-3:v1 . "
$ mvn -Pnative -pl app-server native:compile
$ bash -c "cd app-server && docker build -t app-server:v1 . "
$ docker compose up
$ docker compose --profile app up
-
Go to Grafana, go to dashboards, and click on the
Logs, Traces, Metrics
dashboard. There you can pick a trace ID value (for example,bbe3aea006077640b66d40f3e62f04b9
) to find all logs and traces from both applications that correspond to that trace ID.
$ ./runIdea.sh
-
no span created with contextualName using annotation but span are created using code @see FlightApplication.java
-
this command should build image using local docker service but it fails
mvn -Pnative -pl app-server spring-boot:build-image
PID %CPU %MEM VSZ RSS TT TIME CMD 2982 1.2 1.2 12,76GB 393,91MB pts/5 00:00:12 .sdkman/candidates/java/22.3.r17-nik/bin/java -cp app-boot-2/target/classes:org/springframework/boot/spring-boot/2.7.7/spring-boot 2723 1.4 0.8 12,79GB 279,57MB pts/4 00:00:15 .sdkman/candidates/java/22.3.r17-nik/bin/java -cp app-boot-3/target/classes:org/springframework/boot/spring-boot/3.0.0/spring-boot 3824 0.6 0.4 1,96GB 142,65MB pts/3 00:00:05 ./app-server/target/app-server 4029 0.4 0.4 2,09GB 141,13MB pts/6 00:00:04 ./app-client/target/app-client
# download crc executable and put in /usr/local/bin
crc setup
crc start
# open web console, should be https://console-openshift-console.apps-crc.testing/
crc console
# show credential to login
crc console --credentials
#oc login -u developer https://api.crc.testing:6443
oc config use-context crc-admin
oc whoami
crc stop
crc delete # warning, this will delete all !
crc cleanup # The crc cleanup command removes an existing Red Hat OpenShift Local instance and reverts changes to DNS entries created by the crc setup command
docker pull registry
docker run -d -p 5000:5000 --restart=always --name registry registry:2
oc config use-context crc-admin
oc registry login --insecure=true
export OC_PROJECT=demo-obs
oc delete project $OC_PROJECT
oc new-project $OC_PROJECT
export APP=app-client VERSION=v1 \
&& docker tag $APP:$VERSION localhost:5000/$APP:$VERSION \
&& docker push localhost:5000/$APP:$VERSION \
&& oc image mirror localhost:5000/$APP:$VERSION=default-route-openshift-image-registry.apps-crc.testing/$OC_PROJECT/$APP:$VERSION --insecure=true --filter-by-os=linux/amd64
export APP=app-server VERSION=v1 \
&& docker tag $APP:$VERSION localhost:5000/$APP:$VERSION \
&& docker push localhost:5000/$APP:$VERSION \
&& oc image mirror localhost:5000/$APP:$VERSION=default-route-openshift-image-registry.apps-crc.testing/$OC_PROJECT/$APP:$VERSION --insecure=true --filter-by-os=linux/amd64
export APP=app-boot-2 VERSION=v1 \
&& docker tag $APP:$VERSION localhost:5000/$APP:$VERSION \
&& docker push localhost:5000/$APP:$VERSION \
&& oc image mirror localhost:5000/$APP:$VERSION=default-route-openshift-image-registry.apps-crc.testing/$OC_PROJECT/$APP:$VERSION --insecure=true --filter-by-os=linux/amd64
export APP=app-boot-3 VERSION=v1 \
&& docker tag $APP:$VERSION localhost:5000/$APP:$VERSION \
&& docker push localhost:5000/$APP:$VERSION \
&& oc image mirror localhost:5000/$APP:$VERSION=default-route-openshift-image-registry.apps-crc.testing/$OC_PROJECT/$APP:$VERSION --insecure=true --filter-by-os=linux/amd64
oc get is
# with all parameters :
# oc process -f openshift/app-template.yml -p APP=app-boot-2 -p VERSION=v1 -p NAMESPACE=demo-obs -p GROUP=my-group | oc create -f -
oc process -f openshift/app-template.yml -p APP=app-boot-2 | oc apply -f -
oc process -f openshift/app-template.yml -p APP=app-boot-3 | oc apply -f -
oc process -f openshift/app-template.yml -p APP=app-server | oc apply -f -
oc process -f openshift/app-template.yml -p APP=app-client | oc apply -f -
-
Go to web console, login as admin kubeadmin, select project demo-obs, go to Topology view, client on app-client deployment then show logs You should get output similar to this:
2023-01-16T08:50:01.786Z INFO [app-client,,] 1 --- [ main] com.example.client.ClientApplication : Started ClientApplication in 6.408 seconds (process running for 7.043) 2023-01-16T08:50:01.921Z INFO [app-client,377c7685b7ad7ab63b7ba9d5d823d82c,f0835ee782e5228f] 1 --- [ main] com.example.client.ClientApplication : Will send a request to the server 2023-01-16T08:50:02.120Z INFO [app-client,377c7685b7ad7ab63b7ba9d5d823d82c,f0835ee782e5228f] 1 --- [ main] com.example.client.ClientApplication : Got response [foo] 2023-01-16T08:50:02.122Z INFO [app-client,377c7685b7ad7ab63b7ba9d5d823d82c,f0835ee782e5228f] 1 --- [ main] com.example.client.ClientApplication : call boot-3 flight service 2023-01-16T08:50:02.204Z INFO [app-client,377c7685b7ad7ab63b7ba9d5d823d82c,f0835ee782e5228f] 1 --- [ main] com.example.client.ClientApplication : boot-3 flight service response: [{"id":1,"origin":"Paris","destination":"New-York"},{"id":2,"origin":"New-York","destination":"Paris"},{"id":3,"origin":"Londre","destination":"Bruxelles"},{"id":4,"origin":"Rome","destination":"Madrid"},{"id":5,"origin":"Porto","destination":"Seoul"}] 2023-01-16T08:50:02.205Z INFO [app-client,377c7685b7ad7ab63b7ba9d5d823d82c,f0835ee782e5228f] 1 --- [ main] com.example.client.ClientApplication : call boot-2 application 2023-01-16T08:50:02.530Z INFO [app-client,377c7685b7ad7ab63b7ba9d5d823d82c,f0835ee782e5228f] 1 --- [ main] com.example.client.ClientApplication : boot-2 response: ok !
oc get all --selector app=$APP -o name
oc delete all --selector app=$APP
oc delete project $OC_PROJECT
oc registry login --insecure=true
oc image mirror registry.access.redhat.com/ubi8/ubi:latest=default-route-openshift-image-registry.apps-crc.testing/demo/ubi8:latest --insecure=true --filter-by-os=linux/amd64
oc get is
oc set image-lookup ubi8
oc run demo --image=ubi8 --command -- sleep 600s
# after this an app can be added using
# image-registry.openshift-image-registry.svc:5000/demo/ubi8
# or
# default-route-openshift-image-registry.apps-crc.testing/demo/ubi8:latest
in web console add > container images
multirepo-oab.si.fr.intraorange:5002/nfpatrs/observability/app-server:v1
check Allow Images from insecure registries
create secret with <bvgg0760>:<secret> found in: cat /home/bvgg0760/.docker/config.json
export OC_PROJECT=demo-helm
oc new-project $OC_PROJECT
-
upload images to new namespace registry
# from https://github.com/redhat-cop/template2helm
template2helm convert --template ./openshift/app-template.yml --chart ./openshift/charts
#add "apiVersion: v2" on top of Chat.yaml file so helm lint will not complains
helm lint openshift/charts/app-template/
helm install --set app=app-boot-2 --set namespace=demo-helm app-boot-2-chart openshift/charts/app-template
helm install --set app=app-boot-3 --set namespace=demo-helm app-boot-3-chart openshift/charts/app-template
helm install --set app=app-server --set namespace=demo-helm app-server-chart openshift/charts/app-template
helm install --set app=app-client --set namespace=demo-helm app-client-chart openshift/charts/app-template
helm delete app-boot-2-chart
helm delete app-boot-3-chart
helm delete app-server-chart
helm delete app-client-chart