From 2a8c10770f6f69b8c6f1a250729500545ef214f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Fri, 25 Oct 2024 11:07:37 +0200 Subject: [PATCH 1/8] adds a GA that pulls images into ghcr.io --- .github/workflows/provide-docker-images.yml | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/provide-docker-images.yml diff --git a/.github/workflows/provide-docker-images.yml b/.github/workflows/provide-docker-images.yml new file mode 100644 index 0000000..e1b992c --- /dev/null +++ b/.github/workflows/provide-docker-images.yml @@ -0,0 +1,48 @@ +name: Provide needed docker images in ghcr.io + +on: + workflow_dispatch: + push: + +env: + REGISTRY_IMAGE: ghcr.io/novatecconsulting/opentelemetry-training + +jobs: + retag_and_push: + name: Provide docker image ${{ matrix.image.namespace }}/${{ matrix.image.name }}:${{ matrix.image.tag }} on ghcr.io + runs-on: [ubuntu-latest] + strategy: + matrix: + image: + - name: todobackend-springboot + tag: v2404 + namespace: maeddes + - name: todoui-thymeleaf + tag: v2404 + namespace: maeddes + - name: todoui-flask + tag: v2404 + namespace: maeddes + - name: simple-generator + tag: v2404 + namespace: maeddes + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Pull image from Docker Hub + run: | + docker pull docker.io/${{ matrix.image.namespace }}/${{ matrix.image.name }}:${{ matrix.image.tag }} + - name: Retag the image for GitHub Container Registry + run: | + docker tag ${{ matrix.image.namespace }}/${{ matrix.image.name }}:${{ matrix.image.tag }} ${{ env.REGISTRY_IMAGE }}-${{ matrix.image.name }}:${{ matrix.image.tag }} + - name: Push image to GitHub Container Registry + run: | + docker push ${{ env.REGISTRY_IMAGE }}-${{ matrix.image.name }}:${{ matrix.image.tag }} \ No newline at end of file From 6f20a3d24a6ac39613974f1ec848d85a339ba904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Fri, 25 Oct 2024 11:07:58 +0200 Subject: [PATCH 2/8] ignore nix specific files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 993cf53..422f008 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ *.jar settings.json +.direnv +.devenv +.envrc \ No newline at end of file From 7e78df20f15819f7e4ca0ce41465000041b8c7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Fri, 25 Oct 2024 11:14:40 +0200 Subject: [PATCH 3/8] fixed as casing --- .../initial/todobackend-springboot/Dockerfile | 2 +- .../solution/todobackend-springboot/Dockerfile | 2 +- .../initial/todobackend-springboot/Dockerfile | 2 +- .../initial/todoui-thymeleaf/Dockerfile | 2 +- .../solution/todobackend-springboot/Dockerfile | 2 +- .../otel-in-action/todobackend-springboot/Dockerfile | 2 +- exercises/otel-in-action/todoui-thymeleaf/Dockerfile | 2 +- tutorial/Dockerfile | 8 ++++---- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile b/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile index bcc02e7..5893092 100644 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile b/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile index bcc02e7..5893092 100644 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile index bcc02e7..5893092 100644 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile index ba32ead..be98665 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile index bcc02e7..5893092 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/exercises/otel-in-action/todobackend-springboot/Dockerfile b/exercises/otel-in-action/todobackend-springboot/Dockerfile index bcc02e7..5893092 100644 --- a/exercises/otel-in-action/todobackend-springboot/Dockerfile +++ b/exercises/otel-in-action/todobackend-springboot/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/exercises/otel-in-action/todoui-thymeleaf/Dockerfile b/exercises/otel-in-action/todoui-thymeleaf/Dockerfile index ba32ead..be98665 100644 --- a/exercises/otel-in-action/todoui-thymeleaf/Dockerfile +++ b/exercises/otel-in-action/todoui-thymeleaf/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/maven:3-eclipse-temurin-21 as build +FROM docker.io/maven:3-eclipse-temurin-21 AS build WORKDIR /workspace/app COPY pom.xml . diff --git a/tutorial/Dockerfile b/tutorial/Dockerfile index 4761136..b778657 100644 --- a/tutorial/Dockerfile +++ b/tutorial/Dockerfile @@ -1,10 +1,10 @@ -FROM golang:1.21-alpine as base +FROM golang:1.21-alpine AS base RUN apk add --update --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \ bash \ hugo -FROM base as rt-dev +FROM base AS rt-dev WORKDIR /workspace @@ -13,7 +13,7 @@ COPY --chmod=0755 entrypoint.sh /tmp CMD [ "sh", "-c", "/tmp/entrypoint.sh" ] -FROM base as builder +FROM base AS builder WORKDIR /opt/app @@ -24,7 +24,7 @@ RUN wget -qO- https://github.com/McShelby/hugo-theme-relearn/archive/main.zip | RUN hugo -FROM nginx:1.25-alpine as rt +FROM nginx:1.25-alpine AS rt ARG USER=otel From 9cd93cf280400e5ab9e15b8b2d8749a19f97c655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Fri, 25 Oct 2024 11:28:21 +0200 Subject: [PATCH 4/8] exclude byte-buddy and mockito from dependencies --- .../initial/todobackend-springboot/pom.xml | 14 ++++ .../solution/todobackend-springboot/pom.xml | 16 +++- .../initial/todobackend-springboot/pom.xml | 16 +++- .../initial/todoui-thymeleaf/pom.xml | 83 +++++++++++-------- .../solution/todobackend-springboot/pom.xml | 80 ++++++++++-------- .../todobackend-springboot/pom.xml | 16 +++- .../otel-in-action/todoui-thymeleaf/pom.xml | 29 +++++-- 7 files changed, 177 insertions(+), 77 deletions(-) diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml b/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml index efe02e6..20bc47a 100644 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml @@ -53,6 +53,20 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml b/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml index 6d99fd4..6656335 100644 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml @@ -53,6 +53,20 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + io.opentelemetry.instrumentation @@ -71,4 +85,4 @@ todobackend-${version} - \ No newline at end of file + diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml index 1e8f51c..3cff943 100644 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml @@ -53,6 +53,20 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + org.springframework.boot @@ -72,4 +86,4 @@ todobackend-${version} - \ No newline at end of file + diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml index 781505c..c4d9ac7 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -15,7 +16,7 @@ org.springframework.boot spring-boot-starter-parent 2.7.16 - + @@ -41,42 +42,56 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + + + + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-sdk + + + io.opentelemetry + opentelemetry-exporter-logging + + + io.opentelemetry + opentelemetry-exporter-otlp + + + + io.opentelemetry.semconv + opentelemetry-semconv + 1.26.0-alpha - - io.opentelemetry - opentelemetry-api - - - io.opentelemetry - opentelemetry-sdk - - - io.opentelemetry - opentelemetry-exporter-logging - - - io.opentelemetry - opentelemetry-exporter-otlp - - - - io.opentelemetry.semconv - opentelemetry-semconv - 1.26.0-alpha - - - - io.opentelemetry - opentelemetry-bom - 1.40.0 - pom - import - - - + + + io.opentelemetry + opentelemetry-bom + 1.40.0 + pom + import + + + diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml index 12abece..43f1350 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml @@ -53,6 +53,20 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + org.springframework.boot @@ -60,27 +74,27 @@ runtime true - - io.opentelemetry - opentelemetry-api - - - io.opentelemetry - opentelemetry-sdk - - - io.opentelemetry - opentelemetry-exporter-logging - - - io.opentelemetry - opentelemetry-exporter-otlp - - - io.opentelemetry.semconv - opentelemetry-semconv - 1.26.0-alpha - + + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-sdk + + + io.opentelemetry + opentelemetry-exporter-logging + + + io.opentelemetry + opentelemetry-exporter-otlp + + + io.opentelemetry.semconv + opentelemetry-semconv + 1.26.0-alpha + @@ -94,16 +108,16 @@ todobackend-${version} - - - - io.opentelemetry - opentelemetry-bom - 1.40.0 - pom - import - - - + + + + io.opentelemetry + opentelemetry-bom + 1.40.0 + pom + import + + + - \ No newline at end of file + diff --git a/exercises/otel-in-action/todobackend-springboot/pom.xml b/exercises/otel-in-action/todobackend-springboot/pom.xml index 79c0651..9777218 100644 --- a/exercises/otel-in-action/todobackend-springboot/pom.xml +++ b/exercises/otel-in-action/todobackend-springboot/pom.xml @@ -53,6 +53,20 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + io.opentelemetry.instrumentation @@ -71,4 +85,4 @@ - \ No newline at end of file + diff --git a/exercises/otel-in-action/todoui-thymeleaf/pom.xml b/exercises/otel-in-action/todoui-thymeleaf/pom.xml index 3dc4994..39a3a01 100644 --- a/exercises/otel-in-action/todoui-thymeleaf/pom.xml +++ b/exercises/otel-in-action/todoui-thymeleaf/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -15,7 +16,7 @@ org.springframework.boot spring-boot-starter-parent 2.7.16 - + @@ -42,16 +43,30 @@ org.springframework.boot spring-boot-starter-test test + + + org.mockito + mockito-core + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + - - +--> + - + From d2cc3625b0b81374524d6d44b788b6f4e757e94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Fri, 25 Oct 2024 11:28:30 +0200 Subject: [PATCH 5/8] adds editorconfig --- .editorconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8e1a769 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ + + +# EditorConfig is awesome: https://editorconfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.xml] +indent_size = 4 +indent_style = tab From 1f6db0e04edc6eed89b383da468e4fba01ef5046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Fri, 25 Oct 2024 11:47:17 +0200 Subject: [PATCH 6/8] change package name to info.novatec --- .../initial/todobackend-springboot/Dockerfile | 2 +- .../initial/todobackend-springboot/pom.xml | 2 +- .../todobackend/TodobackendApplication.java | 10 +-- ...odobackendApplicationIntegrationTests.java | 4 +- .../todobackend-springboot/Dockerfile | 2 +- .../solution/todobackend-springboot/pom.xml | 2 +- .../todobackend/TodobackendApplication.java | 10 +-- ...odobackendApplicationIntegrationTests.java | 4 +- .../initial/todobackend-springboot/Dockerfile | 2 +- .../initial/todobackend-springboot/pom.xml | 2 +- .../todobackend/TodobackendApplication.java | 14 ++-- ...odobackendApplicationIntegrationTests.java | 4 +- .../initial/todoui-thymeleaf/Dockerfile | 4 +- .../initial/todoui-thymeleaf/pom.xml | 2 +- .../todoui/OpenTelemetryConfiguration.java | 6 +- .../io/novatec/todoui/TodouiApplication.java | 4 +- .../todobackend-springboot/Dockerfile | 2 +- .../solution/todobackend-springboot/pom.xml | 2 +- .../OpenTelemetryConfiguration.java | 2 +- .../todobackend/TodobackendApplication.java | 4 +- ...odobackendApplicationIntegrationTests.java | 4 +- exercises/manual-instrumentation-java/steps | 2 +- .../todobackend-springboot/Dockerfile | 2 +- .../todobackend-springboot/pom.xml | 2 +- .../todobackend/TodobackendApplication.java | 10 +-- ...odobackendApplicationIntegrationTests.java | 4 +- .../todoui-thymeleaf/Dockerfile | 4 +- .../otel-in-action/todoui-thymeleaf/pom.xml | 2 +- .../io/novatec/todoui/TodouiApplication.java | 2 +- .../automatic/code-based/index.md | 20 +++--- .../automatic/zero-code/index.md | 8 +-- .../manual_java/metrics/index.md | 36 +++++----- .../manual_java/traces/index.md | 70 +++++++++---------- 33 files changed, 125 insertions(+), 125 deletions(-) diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile b/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile index 5893092..4d74f68 100644 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile @@ -20,4 +20,4 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todobackend -ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] \ No newline at end of file +ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml b/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml index 20bc47a..0d2d33f 100644 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml @@ -11,7 +11,7 @@ - io.novatec + info.novatec todobackend-automatic 0.0.1-SNAPSHOT todobackend-automatic diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/automatic-instrumentation/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java index 5c1cc18..7f15ea1 100644 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import java.util.ArrayList; import java.util.List; @@ -87,13 +87,13 @@ String someInternalMethod(String todo){ } catch (InterruptedException e) { e.printStackTrace(); } - } + } if(todo.equals("fail")){ System.out.println("Failing ..."); throw new RuntimeException(); - - } + + } return todo; } @@ -136,4 +136,4 @@ public void setTodo(String todo) { interface TodoRepository extends CrudRepository { -} \ No newline at end of file +} diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/automatic-instrumentation/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java index b18589d..b4f245c 100755 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -9,4 +9,4 @@ public class TodobackendApplicationIntegrationTests { @Test void contextLoads() { } -} \ No newline at end of file +} diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile b/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile index 5893092..4d74f68 100644 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile @@ -20,4 +20,4 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todobackend -ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] \ No newline at end of file +ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml b/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml index 6656335..fb8205f 100644 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml @@ -11,7 +11,7 @@ - io.novatec + info.novatec todobackend-automatic-solution 0.0.1-SNAPSHOT todobackend-automatic-solution diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/automatic-instrumentation/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java index cf69f70..a1940ba 100644 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import java.util.ArrayList; import java.util.List; @@ -91,13 +91,13 @@ String someInternalMethod(@SpanAttribute String todo){ } catch (InterruptedException e) { e.printStackTrace(); } - } + } if(todo.equals("fail")){ System.out.println("Failing ..."); throw new RuntimeException(); - - } + + } return todo; } @@ -140,4 +140,4 @@ public void setTodo(String todo) { interface TodoRepository extends CrudRepository { -} \ No newline at end of file +} diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/automatic-instrumentation/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java index b18589d..b4f245c 100755 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -9,4 +9,4 @@ public class TodobackendApplicationIntegrationTests { @Test void contextLoads() { } -} \ No newline at end of file +} diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile index 5893092..4d74f68 100644 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile @@ -20,4 +20,4 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todobackend -ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] \ No newline at end of file +ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml index 3cff943..a56df71 100644 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml @@ -11,7 +11,7 @@ - io.novatec + info.novatec todobackend-manual 0.0.1-SNAPSHOT todobackend-manual diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java index 35694f8..b9a5fa5 100644 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import java.util.ArrayList; import java.util.List; @@ -82,25 +82,25 @@ String addTodo(HttpServletRequest request, HttpServletResponse response, @PathVa return todo; - } + } String someInternalMethod(String todo){ todoRepository.save(new Todo(todo)); - + if(todo.equals("slow")){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } - } + } if(todo.equals("fail")){ System.out.println("Failing ..."); throw new RuntimeException(); - - } + + } return todo; @@ -146,4 +146,4 @@ public void setTodo(String todo) { interface TodoRepository extends CrudRepository { -} \ No newline at end of file +} diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java index b18589d..b4f245c 100755 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -9,4 +9,4 @@ public class TodobackendApplicationIntegrationTests { @Test void contextLoads() { } -} \ No newline at end of file +} diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile index be98665..d6b71ae 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile @@ -21,6 +21,6 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todoui/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todoui -ENTRYPOINT ["java","-cp","/opt/todoui/app:/opt/todoui/app/lib/*", "-javaagent:/opt/todoui/opentelemetry-javaagent.jar", "io.novatec.todoui.TodouiApplication"] -#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] +ENTRYPOINT ["java","-cp","/opt/todoui/app:/opt/todoui/app/lib/*", "-javaagent:/opt/todoui/opentelemetry-javaagent.jar", "info.novatec.todoui.TodouiApplication"] +#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml index c4d9ac7..e42b3dc 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - io.novatec + info.novatec todoui-manual 0.0.1-SNAPSHOT jar diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java index 06582e7..8766eb5 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/OpenTelemetryConfiguration.java @@ -1,4 +1,4 @@ -package io.novatec.todoui; +package info.novatec.todoui; import java.util.concurrent.TimeUnit; @@ -45,8 +45,8 @@ public OpenTelemetry openTelemetry(){ .addSpanProcessor(SimpleSpanProcessor.create(jaegerOtlpExporter)) // .addSpanProcessor(BatchSpanProcessor.builder(LoggingSpanExporter.create()).build()) // same results for now .setResource(resource) - .build(); - // .buildAndRegisterGlobal(); + .build(); + // .buildAndRegisterGlobal(); OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java index dd9f5e9..ec80cfd 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todoui; +package info.novatec.todoui; import java.util.ArrayList; import java.util.List; @@ -122,7 +122,7 @@ public String addItem(String toDo){ template.postForEntity(endpoint+"/todos/"+toDo, null, String.class); - + span.end(); diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile index 5893092..4d74f68 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/Dockerfile @@ -20,4 +20,4 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todobackend -ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] \ No newline at end of file +ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml index 43f1350..721aed7 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml @@ -11,7 +11,7 @@ - io.novatec + info.novatec todobackend-manual-solution 0.0.1-SNAPSHOT todobackend-manual-solution diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java index e4026e9..4c54b37 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/OpenTelemetryConfiguration.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import java.time.Duration; diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java index c51907d..155f694 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import static io.opentelemetry.api.common.AttributeKey.stringKey; @@ -197,4 +197,4 @@ public void setTodo(String todo) { interface TodoRepository extends CrudRepository { -} \ No newline at end of file +} diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java index b18589d..b4f245c 100755 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -9,4 +9,4 @@ public class TodobackendApplicationIntegrationTests { @Test void contextLoads() { } -} \ No newline at end of file +} diff --git a/exercises/manual-instrumentation-java/steps b/exercises/manual-instrumentation-java/steps index 05f164a..166f2d2 100644 --- a/exercises/manual-instrumentation-java/steps +++ b/exercises/manual-instrumentation-java/steps @@ -105,7 +105,7 @@ export BACKEND_URL=http://localhost:8080 Put everything in own Config class: -package io.novatec.todobackend; +package info.novatec.todobackend; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/exercises/otel-in-action/todobackend-springboot/Dockerfile b/exercises/otel-in-action/todobackend-springboot/Dockerfile index 5893092..4d74f68 100644 --- a/exercises/otel-in-action/todobackend-springboot/Dockerfile +++ b/exercises/otel-in-action/todobackend-springboot/Dockerfile @@ -20,4 +20,4 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todobackend -ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] \ No newline at end of file +ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/otel-in-action/todobackend-springboot/pom.xml b/exercises/otel-in-action/todobackend-springboot/pom.xml index 9777218..8a37ea9 100644 --- a/exercises/otel-in-action/todobackend-springboot/pom.xml +++ b/exercises/otel-in-action/todobackend-springboot/pom.xml @@ -11,7 +11,7 @@ - io.novatec + info.novatec todobackend 0.0.1-SNAPSHOT todobackend diff --git a/exercises/otel-in-action/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java b/exercises/otel-in-action/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java index a595a0f..4cef808 100644 --- a/exercises/otel-in-action/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java +++ b/exercises/otel-in-action/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import java.util.ArrayList; import java.util.List; @@ -98,13 +98,13 @@ String someInternalMethod(@SpanAttribute String todo){ } catch (InterruptedException e) { e.printStackTrace(); } - } + } if(todo.equals("fail")){ System.out.println("Failing ..."); throw new RuntimeException(); - - } + + } return todo; } @@ -147,4 +147,4 @@ public void setTodo(String todo) { interface TodoRepository extends CrudRepository { -} \ No newline at end of file +} diff --git a/exercises/otel-in-action/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java b/exercises/otel-in-action/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java index b18589d..b4f245c 100755 --- a/exercises/otel-in-action/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java +++ b/exercises/otel-in-action/todobackend-springboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java @@ -1,4 +1,4 @@ -package io.novatec.todobackend; +package info.novatec.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -9,4 +9,4 @@ public class TodobackendApplicationIntegrationTests { @Test void contextLoads() { } -} \ No newline at end of file +} diff --git a/exercises/otel-in-action/todoui-thymeleaf/Dockerfile b/exercises/otel-in-action/todoui-thymeleaf/Dockerfile index be98665..d6b71ae 100644 --- a/exercises/otel-in-action/todoui-thymeleaf/Dockerfile +++ b/exercises/otel-in-action/todoui-thymeleaf/Dockerfile @@ -21,6 +21,6 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todoui/app ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /opt/todoui -ENTRYPOINT ["java","-cp","/opt/todoui/app:/opt/todoui/app/lib/*", "-javaagent:/opt/todoui/opentelemetry-javaagent.jar", "io.novatec.todoui.TodouiApplication"] -#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"] +ENTRYPOINT ["java","-cp","/opt/todoui/app:/opt/todoui/app/lib/*", "-javaagent:/opt/todoui/opentelemetry-javaagent.jar", "info.novatec.todoui.TodouiApplication"] +#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","info.novatec.todobackend.TodobackendApplication"] diff --git a/exercises/otel-in-action/todoui-thymeleaf/pom.xml b/exercises/otel-in-action/todoui-thymeleaf/pom.xml index 39a3a01..f751cbc 100644 --- a/exercises/otel-in-action/todoui-thymeleaf/pom.xml +++ b/exercises/otel-in-action/todoui-thymeleaf/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - io.novatec + info.novatec todoui 0.0.1-SNAPSHOT jar diff --git a/exercises/otel-in-action/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java b/exercises/otel-in-action/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java index f98c072..935e946 100644 --- a/exercises/otel-in-action/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java +++ b/exercises/otel-in-action/todoui-thymeleaf/src/main/java/io/novatec/todoui/TodouiApplication.java @@ -1,4 +1,4 @@ -package io.novatec.todoui; +package info.novatec.todoui; import javax.annotation.PostConstruct; diff --git a/tutorial/content/exercises/instrumentation/automatic/code-based/index.md b/tutorial/content/exercises/instrumentation/automatic/code-based/index.md index 18124ab..a0b3418 100644 --- a/tutorial/content/exercises/instrumentation/automatic/code-based/index.md +++ b/tutorial/content/exercises/instrumentation/automatic/code-based/index.md @@ -32,7 +32,7 @@ While instrumentation libraries offer a valuable solution for enhancing observab ### How to perform the exercise -* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) +* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) * All exercises are in the subdirectory `exercises`. There is also an environment variable `$EXERCISES` pointing to this directory. All directories given are relative to this one. * Initial directory: `automatic-instrumentation/initial` * Solution directory: `automatic-instrumentation/solution` @@ -51,7 +51,7 @@ Developers often encapsulate related logic in dedicated functions to improve cod The OpenTelemetry agent may lack awareness of these custom functions. It has no way of knowing whether they are important and what telemetry data to capture from them. -To apply a more granular configuration to the already existing agent you can use the `opentelemetry-instrumentation-annotations` library. +To apply a more granular configuration to the already existing agent you can use the `opentelemetry-instrumentation-annotations` library. If the Java part of the application is still running from this exercise, stop it using `Ctrl+C` in the corresponding terminal window. @@ -87,7 +87,7 @@ Add the following dependency to it and make sure to align/indent with the alread and save the file. -Now re-run the build command +Now re-run the build command ```sh mvn clean package @@ -231,7 +231,7 @@ Among other details you will be able to see the details of the method and name o ``` code.function - someInternalMethod -code.namespace - io.novatec.todobackend.TodobackendApplication +code.namespace - info.novatec.todobackend.TodobackendApplication otel.library.name - io.opentelemetry.opentelemetry-instrumentation-annotations-1.16 otel.library.version - 2.5.0-alpha @@ -279,7 +279,7 @@ This means you can now also see the specific parameter which has been passed and Leave the Java application running, you will need it for the Python part as well. -### Alternative approach +### Alternative approach These are no exercise steps, this is just supporting information. @@ -293,13 +293,13 @@ As the name already implies they configure methods to be included as spans or ex In our example the corresponding environment setting to include the `someInternalMethod` to the spans without using the `@WithSpan` annotation in code would be: ``` -export OTEL_INSTRUMENTATION_METHODS_INCLUDE=io.novatec.todobackend.TodobackendApplication[someInternalMethod] +export OTEL_INSTRUMENTATION_METHODS_INCLUDE=info.novatec.todobackend.TodobackendApplication[someInternalMethod] ``` In case the `@WithSpan` annotation was already present in the compiled jar and you want to exclude it without rebuild you have to set: ``` -export OTEL_INSTRUMENTATION_OPENTELEMETRY_INSTRUMENTATION_ANNOTATIONS_EXCLUDE_METHODS=io.novatec.todobackend.TodobackendApplication[someInternalMethod] +export OTEL_INSTRUMENTATION_OPENTELEMETRY_INSTRUMENTATION_ANNOTATIONS_EXCLUDE_METHODS=info.novatec.todobackend.TodobackendApplication[someInternalMethod] ``` Both environment variables only correspond with the `@WithSpan` annotation. There is no possibility (yet) to configure span attributes through environment setting. This only works on code level. @@ -308,7 +308,7 @@ The part of the Java library exercise completes with this step. --- -### exercise - Python mixed automatic and manual instrumentation +### exercise - Python mixed automatic and manual instrumentation Change to the directory within to `exercises/automatic-instrumentation/initial/todoui-flask` path, if you are in the project root directory it is: @@ -457,7 +457,7 @@ The following chapter `manual instrumentatoin` will do this in full depth. Please stop all Java, Python and docker processes. - diff --git a/tutorial/content/exercises/instrumentation/automatic/zero-code/index.md b/tutorial/content/exercises/instrumentation/automatic/zero-code/index.md index a532211..17f972d 100644 --- a/tutorial/content/exercises/instrumentation/automatic/zero-code/index.md +++ b/tutorial/content/exercises/instrumentation/automatic/zero-code/index.md @@ -83,7 +83,7 @@ Therefore, not all languages come with support for auto-instrumentation. ## Exercise ### How to perform the exercise -* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) +* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) * All exercises are in the subdirectory `exercises`. There is also an environment variable `$EXERCISES` pointing to this directory. All directories given are relative to this one. * Initial directory: `automatic-instrumentation/initial` * Solution directory: `automatic-instrumentation/solution` @@ -227,9 +227,9 @@ If you switch back to the terminal of the Java application process you should se ``` [otel.javaagent 2024-04-17 07:04:57:384 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'SELECT testdb.todo' : 22571b7a308941882c3d203a2c1b2179 fcabde9f56343650 CLIENT [tracer: io.opentelemetry.jdbc:2.3.0-alpha] AttributesMap{data={db.operation=SELECT, db.sql.table=todo, db.name=testdb, thread.name=http-nio-8080-exec-1, thread.id=44, db.user=sa, db.connection_string=h2:mem:, db.system=h2, db.statement=select t1_0.todo from todo t1_0}, capacity=128, totalAddedValues=9} -[otel.javaagent 2024-04-17 07:04:57:387 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'SELECT io.novatec.todobackend.Todo' : 22571b7a308941882c3d203a2c1b2179 8a64843c1fb5217d INTERNAL [tracer: io.opentelemetry.hibernate-6.0:2.3.0-alpha] AttributesMap{data={thread.name=http-nio-8080-exec-1, thread.id=44}, capacity=128, totalAddedValues=2} +[otel.javaagent 2024-04-17 07:04:57:387 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'SELECT info.novatec.todobackend.Todo' : 22571b7a308941882c3d203a2c1b2179 8a64843c1fb5217d INTERNAL [tracer: io.opentelemetry.hibernate-6.0:2.3.0-alpha] AttributesMap{data={thread.name=http-nio-8080-exec-1, thread.id=44}, capacity=128, totalAddedValues=2} [otel.javaagent 2024-04-17 07:04:57:397 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'Transaction.commit' : 22571b7a308941882c3d203a2c1b2179 a5b7712f0edab44e INTERNAL [tracer: io.opentelemetry.hibernate-6.0:2.3.0-alpha] AttributesMap{data={thread.name=http-nio-8080-exec-1, thread.id=44}, capacity=128, totalAddedValues=2} -[otel.javaagent 2024-04-17 07:04:57:397 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'TodoRepository.findAll' : 22571b7a308941882c3d203a2c1b2179 0463a11569155a8d INTERNAL [tracer: io.opentelemetry.spring-data-1.8:2.3.0-alpha] AttributesMap{data={thread.name=http-nio-8080-exec-1, code.namespace=io.novatec.todobackend.TodoRepository, thread.id=44, code.function=findAll}, capacity=128, totalAddedValues=4} +[otel.javaagent 2024-04-17 07:04:57:397 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'TodoRepository.findAll' : 22571b7a308941882c3d203a2c1b2179 0463a11569155a8d INTERNAL [tracer: io.opentelemetry.spring-data-1.8:2.3.0-alpha] AttributesMap{data={thread.name=http-nio-8080-exec-1, code.namespace=info.novatec.todobackend.TodoRepository, thread.id=44, code.function=findAll}, capacity=128, totalAddedValues=4} 2024-04-17T07:04:57.397+02:00 INFO 79699 --- [springboot-backend ] [nio-8080-exec-1] i.n.todobackend.TodobackendApplication : GET /todos/ [] [otel.javaagent 2024-04-17 07:04:57:422 +0200] [http-nio-8080-exec-1] INFO io.opentelemetry.exporter.logging.LoggingSpanExporter - 'GET /todos/' : 22571b7a308941882c3d203a2c1b2179 61a3089ef357ce36 SERVER [tracer: io.opentelemetry.tomcat-10.0:2.3.0-alpha] AttributesMap{data={url.path=/todos/, thread.id=44, network.peer.address=0:0:0:0:0:0:0:1, server.address=localhost, client.address=0:0:0:0:0:0:0:1, http.response.status_code=200, http.route=/todos/, server.port=8080, http.request.method=GET, url.scheme=http, thread.name=http-nio-8080-exec-1, user_agent.original=curl/8.4.0, network.protocol.version=1.1, network.peer.port=52219}, capacity=128, totalAddedValues=14} ``` @@ -619,4 +619,4 @@ Therefore, it is crucial to find the right balance between them to create an obs - https://www.youtube.com/watch?v=hXTlV_RnELc - https://opentelemetry.io/docs/instrumentation/java/automatic/extensions/ - https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/examples/extension ---> \ No newline at end of file +--> diff --git a/tutorial/content/exercises/instrumentation/manual_java/metrics/index.md b/tutorial/content/exercises/instrumentation/manual_java/metrics/index.md index 8b57309..ea10e89 100644 --- a/tutorial/content/exercises/instrumentation/manual_java/metrics/index.md +++ b/tutorial/content/exercises/instrumentation/manual_java/metrics/index.md @@ -26,7 +26,7 @@ By the end of this lab, you will be able to: - Use the OpenTelemetry API and configure the SDK to generate metrics - Understand the basic structure and dimensions of a metric - Generate custom metrics from your application and configure the exporting - @@ -43,7 +43,7 @@ In this lab, we output metrics to the local console to keep things simple. The environment consists of a Java service that we want to instrument. -* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) +* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) * All exercises are in the subdirectory `exercises`. There is also an environment variable `$EXERCISES` pointing to this directory. All directories given are relative to this one. * Initial directory: `manual-instrumentation-java/initial` * Solution directory: `manual-instrumentation-java/solution` @@ -62,7 +62,7 @@ The environment consists of one component: To start with this lab, open **two terminals**. 1. Terminal to run the echo server -Navigate to +Navigate to ```sh cd $EXERCISES @@ -72,7 +72,7 @@ cd manual-instrumentation-java/initial/todobackend-springboot Run: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` @@ -99,7 +99,7 @@ If you get stuck, you can find the solution in the `exercises/manual-instrumenta Before we can make changes to the Java code we need to make sure some necessary dependencies are in place. -In the first window stop the app using `Ctrl+C` and edit the `pom.xml` file. +In the first window stop the app using `Ctrl+C` and edit the `pom.xml` file. Add the following dependencies. Do not add the dots (...). Just embed the dependencies. @@ -158,7 +158,7 @@ We'll use it to separate tracing-related configuration from the main application Add the following content to this file: ```java { title="OpenTelemetryConfiguration.java" } -package io.novatec.todobackend; +package info.novatec.todobackend; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -210,7 +210,7 @@ Your integrated code will look like this then: .build(); ``` -Let’s begin by importing OpenTelemetry’s meter API and the MeterProvider from the SDK in our main Java application as shown below. +Let’s begin by importing OpenTelemetry’s meter API and the MeterProvider from the SDK in our main Java application as shown below. Open `TodobackendApplication.java` in your editor and tart by addind the following import statements. Place them below the already existing ones: ```java { title="TodobackendApplication.java" } @@ -253,7 +253,7 @@ At this point it is recommended to rebuild and run the application to verify if In your main terminal window run: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` If there are any errors review the changes and repeat. @@ -325,7 +325,7 @@ Let's test the behaviour. Go back to your terminal and execute the following com In case your application is not running any more, start it in the first terminal: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` In your second terminal issue the REST request again. @@ -339,7 +339,7 @@ Observe the logs in your main terminal, this should display something like: ```sh 2024-07-25T12:23:47.929Z INFO 20323 --- [springboot-backend ] [nio-8080-exec-1] i.n.todobackend.TodobackendApplication : GET /todos/ [] 2024-07-25T12:23:54.267Z INFO 20323 --- [springboot-backend ] [cMetricReader-1] i.o.e.logging.LoggingMetricExporter : Received a collection of 1 metrics for export. -2024-07-25T12:23:54.267Z INFO 20323 --- [springboot-backend ] [cMetricReader-1] i.o.e.logging.LoggingMetricExporter : metric: ImmutableMetricData{resource=Resource{schemaUrl=null, attributes={service.name="todobackend", service.version="0.1.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.40.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=io.novatec.todobackend.TodobackendApplication, version=null, schemaUrl=null, attributes={}}, name=todobackend.requests.counter, description=How many times the GET call has been invoked., unit=requests, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1721910224265851430, epochNanos=1721910234267050129, attributes={}, value=1, exemplars=[]}], monotonic=true, aggregationTemporality=CUMULATIVE}} +2024-07-25T12:23:54.267Z INFO 20323 --- [springboot-backend ] [cMetricReader-1] i.o.e.logging.LoggingMetricExporter : metric: ImmutableMetricData{resource=Resource{schemaUrl=null, attributes={service.name="todobackend", service.version="0.1.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.40.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=info.novatec.todobackend.TodobackendApplication, version=null, schemaUrl=null, attributes={}}, name=todobackend.requests.counter, description=How many times the GET call has been invoked., unit=requests, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1721910224265851430, epochNanos=1721910234267050129, attributes={}, value=1, exemplars=[]}], monotonic=true, aggregationTemporality=CUMULATIVE}} ``` The second line of logs written by the `LoggingMetricExporter` contains the information we just generated: `value=1`. @@ -357,7 +357,7 @@ This because we specified this behaviour in the configuration class: .build()) .setResource(resource) .build(); - + ``` The standard interval is 60 seconds. We apply 10 seconds here for demo purposes. @@ -391,7 +391,7 @@ Change the counter statement in the following way: After generating some more traffic, you will see that the logging statement has changed to this: ```sh -2024-07-25T12:50:09.567Z INFO 20323 --- [springboot-backend ] [cMetricReader-1] i.o.e.logging.LoggingMetricExporter : metric: ImmutableMetricData{resource=Resource{schemaUrl=null, attributes={service.name="todobackend", service.version="0.1.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.40.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=io.novatec.todobackend.TodobackendApplication, version=null, schemaUrl=null, attributes={}}, name=todobackend.requests.counter, description=How many times the GET call has been invoked., unit=requests, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1721911669561139043, epochNanos=1721911809567179469, attributes={http.method="GET"}, value=1, exemplars=[]}], monotonic=true, aggregationTemporality=CUMULATIVE}} +2024-07-25T12:50:09.567Z INFO 20323 --- [springboot-backend ] [cMetricReader-1] i.o.e.logging.LoggingMetricExporter : metric: ImmutableMetricData{resource=Resource{schemaUrl=null, attributes={service.name="todobackend", service.version="0.1.0", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.40.0"}}, instrumentationScopeInfo=InstrumentationScopeInfo{name=info.novatec.todobackend.TodobackendApplication, version=null, schemaUrl=null, attributes={}}, name=todobackend.requests.counter, description=How many times the GET call has been invoked., unit=requests, type=LONG_SUM, data=ImmutableSumData{points=[ImmutableLongPointData{startEpochNanos=1721911669561139043, epochNanos=1721911809567179469, attributes={http.method="GET"}, value=1, exemplars=[]}], monotonic=true, aggregationTemporality=CUMULATIVE}} ``` The attributes are now listed, too: @@ -452,7 +452,7 @@ def create_meter(name: str, version: str) -> metric_api.Meter: return meter ``` -- TODO re-use resource_utils +- TODO re-use resource_utils Finally, open `app.py` and import `create_meter`. Invoke the function and assign the return value to a global variable `meter`. @@ -528,12 +528,12 @@ if __name__ == "__main__": # ... ``` -Start the web server using +Start the web server using ```sh python app.py ``` -Use the second terminal to send a request to `/` via +Use the second terminal to send a request to `/` via ```bash curl -XGET localhost:5000; echo @@ -614,7 +614,7 @@ def index(): ) ``` -Send a couple of POST and GET requests to `/` via +Send a couple of POST and GET requests to `/` via ```bash curl -XPOST localhost:5000; echo @@ -713,7 +713,7 @@ def index(): do_stuff() current_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()) return f"Hello, World! It's currently {current_time}" -``` +``` Instead, let's create a custom function `before_request_func` and annotate it with Flask's `@app.before_request` decorator. Thereby, the function is executed on incoming requests before they are handled by the view serving a route. @@ -726,7 +726,7 @@ def before_request_func(): ) ``` -Send a couple of POST and GET requests to `/` via +Send a couple of POST and GET requests to `/` via ```bash curl -XPOST localhost:5000; echo diff --git a/tutorial/content/exercises/instrumentation/manual_java/traces/index.md b/tutorial/content/exercises/instrumentation/manual_java/traces/index.md index c43a756..beffd80 100644 --- a/tutorial/content/exercises/instrumentation/manual_java/traces/index.md +++ b/tutorial/content/exercises/instrumentation/manual_java/traces/index.md @@ -26,7 +26,7 @@ In this lab, we output spans to the local console to keep things simple and expo ## Learning Objectives By the end of this lab, you will be able to: -- Apply manual instrumentation for tracing to a Java application +- Apply manual instrumentation for tracing to a Java application - Use the OpenTelemetry API and configure the SDK to generate spans - Understand the basic structure of a span - Enrich spans with additional metadata @@ -34,7 +34,7 @@ By the end of this lab, you will be able to: ### How to perform the exercises -* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) +* This exercise is based on the following repository [repository](https://github.com/NovatecConsulting/opentelemetry-training/) * All exercises are in the subdirectory `exercises`. There is also an environment variable `$EXERCISES` pointing to this directory. All directories given are relative to this one. * Initial directory: `manual-instrumentation-java/initial` * Solution directory: `manual-instrumentation-java/solution` @@ -50,7 +50,7 @@ The environment consists of one component: To start with this lab, open **two terminals**. 1. Terminal to run the echo server -Navigate to +Navigate to ```sh cd $EXERCISES @@ -60,7 +60,7 @@ cd manual-instrumentation-java/initial/todobackend-springboot Run: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` @@ -87,7 +87,7 @@ If you get stuck, you can find the solution in the `exercises/manual-instrumenta The application has not been modified for OpenTelemetry, so we start entirely from scratch. Before we can make changes to the Java code we need to add some necessary dependencies. -In the first window stop the app using `Ctrl+C` and edit the `pom.xml` file. +In the first window stop the app using `Ctrl+C` and edit the `pom.xml` file. Add the following dependencies. Do not add the dots (...). Just embed the dependencies. @@ -146,7 +146,7 @@ We'll use it to separate tracing-related configuration from the main application Add the following content to this file: ```java { title="OpenTelemetryConfiguration.java" } -package io.novatec.todobackend; +package info.novatec.todobackend; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -175,7 +175,7 @@ public class OpenTelemetryConfiguration { SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) .setResource(resource) - .build(); + .build(); OpenTelemetry openTelemetry = OpenTelemetrySdk.builder() .setTracerProvider(sdkTracerProvider) @@ -188,7 +188,7 @@ public class OpenTelemetryConfiguration { ``` Explanation about the contents of this file: -This Configuration class will create a Bean to access OpenTelemetry API functionality. +This Configuration class will create a Bean to access OpenTelemetry API functionality. It is an initial configuration for tracing properties only. For easy debugging purposes, we'll instantiate a `LoggingSpanExporter` to output spans to the local console. @@ -207,7 +207,7 @@ We created a `SimpleSpanProcessor` and pass the exporter to the `create` method It is recommended to keep this file open in the editor as there will be addition to it over the course of this exercise. -Let’s begin by importing OpenTelemetry’s tracing API and the TracerProvider from the SDK in our main Java application as shown below. +Let’s begin by importing OpenTelemetry’s tracing API and the TracerProvider from the SDK in our main Java application as shown below. Open `TodobackendApplication.java` in your editor and tart by addind the following import statements. Place them below the already existing ones: ```java { title="TodobackendApplication.java" } @@ -243,7 +243,7 @@ In this constuctor we instantiate the OpenTelemetry and Tracer object and make t public TodobackendApplication(OpenTelemetry openTelemetry) { this.openTelemetry = openTelemetry; tracer = openTelemetry.getTracer(TodobackendApplication.class.getName(), "0.1.0"); - + } ``` @@ -252,7 +252,7 @@ At this point it is recommended to rebuild and run the application to verify if In your main terminal window run: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` If there are any errors review the changes and repeat. @@ -289,11 +289,11 @@ The resulting code is supposed to look like this: String addTodo(@PathVariable String todo){ Span span = tracer.spanBuilder("addTodo").startSpan(); - + this.someInternalMethod(todo); logger.info("POST /todos/ "+todo.toString()); - span.end(); + span.end(); return todo; @@ -305,7 +305,7 @@ As you can see we referenced the `tracer` object which was initialized in the co Stop, rebuild and restart the application: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` Switch to your other terminal and use the following command to send a request to the `/` endpoint: @@ -319,7 +319,7 @@ Take a look at the terminal where you application is running. You should see a log statement similar to the one shown below. ```log -2024-07-21T12:58:04.842Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : ba6c894e6774d02d78fe2d48acbdfcc6 72cba2d03eab76a8 INTERNAL [tracer: io.novatec.todobackend.TodobackendApplication:0.1.0] {} +2024-07-21T12:58:04.842Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : ba6c894e6774d02d78fe2d48acbdfcc6 72cba2d03eab76a8 INTERNAL [tracer: info.novatec.todobackend.TodobackendApplication:0.1.0] {} ``` This shows that it actually works, however the output is still a bit cryptic. @@ -339,7 +339,7 @@ Add the following log statement between the `span.end()` call and the return sta Stop, rebuild and restart the application: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` Switch to your other terminal and use the following command to send a request to the `/` endpoint: @@ -351,7 +351,7 @@ curl -XPOST localhost:8080/todos/NEW; echo Below the logging statement from the `LoggingExporter` you should now see more descriptive details: ```log -2024-07-21T13:05:27.650Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : 49fa6e942dd137fdc11ef1178f938078 eeda77d2bfd15a0c INTERNAL [tracer: io.novatec.todobackend.TodobackendApplication:0.1.0] {} +2024-07-21T13:05:27.650Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : 49fa6e942dd137fdc11ef1178f938078 eeda77d2bfd15a0c INTERNAL [tracer: info.novatec.todobackend.TodobackendApplication:0.1.0] {} 2024-07-21T13:05:27.651Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.n.todobackend.TodobackendApplication : Span.toString():SdkSpan{traceId=49fa6e942dd137fdc11ef1178f938078, spanId=eeda77d2bfd15a0c, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=addTodo, kind=INTERNAL, attributes=null, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1721567127643127423, endEpochNanos=1721567127650834923} ``` @@ -361,7 +361,7 @@ A span in OpenTelemetry represents a single operation within a trace and carries This is also tells us a bit more about the output of the LoggingSpanExporter: ```log -2024-07-21T13:05:27.650Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : 49fa6e942dd137fdc11ef1178f938078 eeda77d2bfd15a0c INTERNAL [tracer: io.novatec.todobackend.TodobackendApplication:0.1.0] {} +2024-07-21T13:05:27.650Z INFO 23816 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : 49fa6e942dd137fdc11ef1178f938078 eeda77d2bfd15a0c INTERNAL [tracer: info.novatec.todobackend.TodobackendApplication:0.1.0] {} ``` The first identifier is the `traceId`, the second one is `spandId` followed by `SpanKind`. @@ -381,7 +381,7 @@ And specify two attributes: ```java { title="TodobackendApplication.java" } Span span = tracer.spanBuilder("addTodo").setSpanKind(SpanKind.SERVER).startSpan(); - + span.setAttribute("http.method", "POST"); span.setAttribute("http.url", "/todos/{todo}"); ``` @@ -389,7 +389,7 @@ And specify two attributes: Stop, rebuild and restart the application: ```sh -mvn spring-boot:run +mvn spring-boot:run ``` Switch to your other terminal and use the following command to send a request to the `/` endpoint: @@ -401,7 +401,7 @@ curl -XPOST localhost:8080/todos/NEW; echo The resulting output will look like: ```log -2024-07-24T09:22:07.460Z INFO 7977 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : f150c6404cf8c58398d94bbecb094fdb cd93535232b8d8ca SERVER [tracer: io.novatec.todobackend.TodobackendApplication:0.1.0] AttributesMap{data={http.url=/todos/{todo}, http.method=POST}, capacity=128, totalAddedValues=2} +2024-07-24T09:22:07.460Z INFO 7977 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : f150c6404cf8c58398d94bbecb094fdb cd93535232b8d8ca SERVER [tracer: info.novatec.todobackend.TodobackendApplication:0.1.0] AttributesMap{data={http.url=/todos/{todo}, http.method=POST}, capacity=128, totalAddedValues=2} 2024-07-24T09:22:07.461Z INFO 7977 --- [springboot-backend ] [nio-8080-exec-1] i.n.todobackend.TodobackendApplication : Span.toString():SdkSpan{traceId=f150c6404cf8c58398d94bbecb094fdb, spanId=cd93535232b8d8ca, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=addTodo, kind=SERVER, attributes=AttributesMap{data={http.url=/todos/{todo}, http.method=POST}, capacity=128, totalAddedValues=2}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1721812927453408887, endEpochNanos=1721812927460726137} ``` @@ -420,7 +420,7 @@ Modify the entire method to look like this: span.setAttribute("http.url", request.getRequestURL().toString()); span.setAttribute("client.address", request.getRemoteAddr()); span.setAttribute("user.agent",request.getHeader("User-Agent")); - + this.someInternalMethod(todo); logger.info("POST /todos/ "+todo.toString()); @@ -433,7 +433,7 @@ Modify the entire method to look like this: return todo; } -``` +``` If your editor does not automatically add the import statements, you need to do this manually. Make sure the following import statements are in place: @@ -441,14 +441,14 @@ Make sure the following import statements are in place: ```java { title="TodobackendApplication.java" } import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -``` +``` Restart the app and repeat the curl call. The resulting output will look like: ```log -2024-07-21T13:46:08.336Z INFO 43453 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : 21d97f2813576a1a2942457e9f0c671b 7474ed21e4081af8 SERVER [tracer: io.novatec.todobackend.TodobackendApplication:0.1.0] AttributesMap{data={client.address=127.0.0.1, user.agent=curl/7.81.0, http.url=http://localhost:8080/todos/NEW, response.status=201, http.method=POST}, capacity=128, totalAddedValues=5} +2024-07-21T13:46:08.336Z INFO 43453 --- [springboot-backend ] [nio-8080-exec-1] i.o.e.logging.LoggingSpanExporter : 'addTodo' : 21d97f2813576a1a2942457e9f0c671b 7474ed21e4081af8 SERVER [tracer: info.novatec.todobackend.TodobackendApplication:0.1.0] AttributesMap{data={client.address=127.0.0.1, user.agent=curl/7.81.0, http.url=http://localhost:8080/todos/NEW, response.status=201, http.method=POST}, capacity=128, totalAddedValues=5} 2024-07-21T13:46:08.336Z INFO 43453 --- [springboot-backend ] [nio-8080-exec-1] i.n.todobackend.TodobackendApplication : Span.toString():SdkSpan{traceId=21d97f2813576a1a2942457e9f0c671b, spanId=7474ed21e4081af8, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=addTodo, kind=SERVER, attributes=AttributesMap{data={client.address=127.0.0.1, user.agent=curl/7.81.0, http.url=http://localhost:8080/todos/NEW, response.status=201, http.method=POST}, capacity=128, totalAddedValues=5}, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1721569568329729512, endEpochNanos=1721569568336094221} ``` @@ -531,15 +531,15 @@ The OpenTelemetry API offers also an automated way to propagate the parent span ### Handling an error -The `someInternalMethod` can simulate an error behaviour and throw an exception, if somebody uses the todo with name `fail`. +The `someInternalMethod` can simulate an error behaviour and throw an exception, if somebody uses the todo with name `fail`. ```java { title="TodobackendApplication.java" } if(todo.equals("fail")){ System.out.println("Failing ..."); throw new RuntimeException(); - - } + + } ``` We can catch this exception in the `addTodo` method. @@ -561,7 +561,7 @@ Extend the `try{}` block we created in the previous step with the following code } ``` -Restart the app. +Restart the app. This time execute the curl call with the todo triggering a failure. @@ -603,7 +603,7 @@ Modify the beginning of the class to the code shown below: .addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())) .addSpanProcessor(SimpleSpanProcessor.create(jaegerOtlpExporter)) .setResource(resource) - .build(); + .build(); ``` Also make sure the following import exists: @@ -618,10 +618,10 @@ As you can see we created an instance of `OtlpGrpcSpanExporter` called `jaegerOt In the Tracer Provider we just added another `addSpanProcessor` call to the already existing one. OpenTelemetry is able to handle mulitple different and parallel processors. -Rebuild, restart and issue a curl call. +Rebuild, restart and issue a curl call. ```sh -mvn spring-boot:run +mvn spring-boot:run ``` ```bash @@ -635,7 +635,7 @@ Besides the familiar logging statements, you will see two errors in the logs now 2024-07-21T16:18:20.179Z WARN 70461 --- [springboot-backend ] [alhost:4317/...] i.o.exporter.internal.grpc.GrpcExporter : Failed to export spans. Server responded with gRPC status code 2. Error message: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4317 ``` -This is because there is nothing listening on `http://localhost:4317`. +This is because there is nothing listening on `http://localhost:4317`. Open another terminal window and start a docker container like this: @@ -652,7 +652,7 @@ After this container has started, execute a couple of traces and investigate the The exercise completes with this step. - -