From 47ce51bb739e6875d0055c68beb569829f59ccd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pl=C3=BCddemann?= Date: Thu, 24 Oct 2024 10:44:11 +0200 Subject: [PATCH] updated package names, image names and added github action to pull and retag images --- .github/workflows/provide-docker-images.yml | 41 +++++++++++ .gitignore | 4 ++ .gitpod.yml | 3 +- .../initial/todobackend-springboot/Dockerfile | 2 +- .../initial/todobackend-springboot/pom.xml | 4 +- .../todobackend/TodobackendApplication.java | 8 +-- ...odobackendApplicationIntegrationTests.java | 2 +- .../todobackend-springboot/Dockerfile | 2 +- .../solution/todobackend-springboot/pom.xml | 4 +- .../todobackend/TodobackendApplication.java | 8 +-- ...odobackendApplicationIntegrationTests.java | 2 +- .../initial/todobackend-springboot/Dockerfile | 2 +- .../initial/todobackend-springboot/pom.xml | 4 +- .../todobackend/TodobackendApplication.java | 12 ++-- ...odobackendApplicationIntegrationTests.java | 2 +- .../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 | 4 +- .../OpenTelemetryConfiguration.java | 2 +- .../todobackend/TodobackendApplication.java | 2 +- ...odobackendApplicationIntegrationTests.java | 2 +- exercises/manual-instrumentation-java/steps | 2 +- exercises/otel-in-action/docker-compose.yaml | 8 +-- .../todobackend-springboot/Dockerfile | 2 +- .../todobackend-springboot/pom.xml | 4 +- .../todobackend/TodobackendApplication.java | 8 +-- ...odobackendApplicationIntegrationTests.java | 2 +- .../todoui-thymeleaf/Dockerfile | 4 +- .../otel-in-action/todoui-thymeleaf/pom.xml | 8 +-- .../io/novatec/todoui/TodouiApplication.java | 2 +- .../automatic/code-based/index.md | 20 +++--- .../automatic/zero-code/index.md | 6 +- .../manual_java/metrics/index.md | 36 +++++----- .../manual_java/traces/index.md | 70 +++++++++---------- 37 files changed, 172 insertions(+), 128 deletions(-) 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..aaed24c --- /dev/null +++ b/.github/workflows/provide-docker-images.yml @@ -0,0 +1,41 @@ +name: Provide needed docker images in ghcr.io + +on: + workflow_dispatch: + +env: + REGISTRY_IMAGE: ghcr.io/novatecconsulting/opentelemetry-training + +jobs: + retag_and_push: + name: Provide docker image ${{ matrix.image }} on ghcr.io + runs-on: [ubuntu-latest] + strategy: + matrix: + image: + - ghcr.io/novatecconsulting/openteleemetry-training-todobackend-springboot:v2404 + - ghcr.io/novatecconsulting/openteleemetry-training-todoui-thymeleaf:v2404 + - ghcr.io/novatecconsulting/openteleemetry-training-todoui-flask:v2404 + - ghcr.io/novatecconsulting/openteleemetry-training-simple-generator:v2404 + 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 }} + + - name: Retag the image for GitHub Container Registry + run: | + docker tag ${{ matrix.image }} ${{ env.REGISTRY_IMAGE }}-${{ matrix.image }} + + - name: Push image to GitHub Container Registry + run: | + docker push ${{ env.REGISTRY_IMAGE }}-${{ matrix.image }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 993cf53..94f19b8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ *.jar settings.json + +.direnv +.devenv +.envrc \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index dacee76..5b0652e 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,13 +1,12 @@ # Image of workspace. Learn more: https://www.gitpod.io/docs/configure/workspaces/workspace-image image: maeddes/gitpod:full -workspaceLocation: '/workspace/opentelemetry-training/exercises' +workspaceLocation: "/workspace/opentelemetry-training/exercises" tasks: - name: Set environment variable command: eval $(gp env -e EXERCISES=/workspace/opentelemetry-training/exercises) - name: Add Python Otel libs command: pip3 install requests flask Faker opentelemetry-api opentelemetry-sdk opentelemetry-exporter-prometheus opentelemetry-exporter-otlp - # - name: Start httpbin # command: docker run -p 6000:80 ealen/echo-server:0.9.2 # - name: Enable httpbin diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile b/exercises/automatic-instrumentation/initial/todobackend-springboot/Dockerfile index bcc02e7..0ac5ba3 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","com.example.todobackend.TodobackendApplication"] \ No newline at end of file diff --git a/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml b/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml index efe02e6..24dee18 100644 --- a/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml +++ b/exercises/automatic-instrumentation/initial/todobackend-springboot/pom.xml @@ -11,11 +11,11 @@ - io.novatec + com.example todobackend-automatic 0.0.1-SNAPSHOT todobackend-automatic - Novatec Demo Application + Demo Application 21 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..fa6560f 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 com.example.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; } 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..97a63c0 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 com.example.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile b/exercises/automatic-instrumentation/solution/todobackend-springboot/Dockerfile index bcc02e7..0ac5ba3 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","com.example.todobackend.TodobackendApplication"] \ No newline at end of file diff --git a/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml b/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml index 6d99fd4..6277333 100644 --- a/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml +++ b/exercises/automatic-instrumentation/solution/todobackend-springboot/pom.xml @@ -11,11 +11,11 @@ - io.novatec + com.example todobackend-automatic-solution 0.0.1-SNAPSHOT todobackend-automatic-solution - Novatec Demo Application + Demo Application 21 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..1761cc8 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 com.example.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; } 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..97a63c0 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 com.example.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile b/exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile index bcc02e7..0ac5ba3 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","com.example.todobackend.TodobackendApplication"] \ 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..90503d5 100644 --- a/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml +++ b/exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml @@ -11,11 +11,11 @@ - io.novatec + com.example todobackend-manual 0.0.1-SNAPSHOT todobackend-manual - Novatec Demo Application + Demo Application 21 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..bdb237b 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 com.example.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; 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..97a63c0 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 com.example.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile index ba32ead..a547eb1 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", "com.example.todoui.TodouiApplication"] +#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","com.example.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 781505c..b9c1784 100644 --- a/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml +++ b/exercises/manual-instrumentation-java/initial/todoui-thymeleaf/pom.xml @@ -3,7 +3,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 + com.example 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..1e74296 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 com.example.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..43dd542 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 com.example.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 bcc02e7..0ac5ba3 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","com.example.todobackend.TodobackendApplication"] \ No newline at end of file diff --git a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml index 12abece..12c8ef2 100644 --- a/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml +++ b/exercises/manual-instrumentation-java/solution/todobackend-springboot/pom.xml @@ -11,11 +11,11 @@ - io.novatec + com.example todobackend-manual-solution 0.0.1-SNAPSHOT todobackend-manual-solution - Novatec Demo Application + Demo Application 21 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..3151318 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 com.example.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..3c6112f 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 com.example.todobackend; import static io.opentelemetry.api.common.AttributeKey.stringKey; 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..97a63c0 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 com.example.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/exercises/manual-instrumentation-java/steps b/exercises/manual-instrumentation-java/steps index 05f164a..b48a626 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 com.example.todobackend; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/exercises/otel-in-action/docker-compose.yaml b/exercises/otel-in-action/docker-compose.yaml index ed3565b..4b64c0d 100644 --- a/exercises/otel-in-action/docker-compose.yaml +++ b/exercises/otel-in-action/docker-compose.yaml @@ -14,7 +14,7 @@ services: - POSTGRES_DB=mydb todobackend-springboot: - image: maeddes/todobackend-springboot:v2404 + image: ghcr.io/novatecconsulting/openteleemetry-training-todobackend-springboot:v2404 networks: - todonet build: @@ -37,7 +37,7 @@ services: - postgresdb todoui-thymeleaf: - image: maeddes/todoui-thymeleaf:v2404 + image: ghcr.io/novatecconsulting/openteleemetry-training-todoui-thymeleaf:v2404 build: context: ./todoui-thymeleaf dockerfile: Dockerfile #-multistage @@ -56,7 +56,7 @@ services: - OTEL_LOGS_EXPORTER=none todoui-flask: - image: maeddes/todoui-flask:v2404 + image: ghcr.io/novatecconsulting/openteleemetry-training-todoui-flask:v2404 build: context: ./todoui-flask networks: @@ -70,7 +70,7 @@ services: - OTEL_METRICS_EXPORTER=otlp loadgenerator: - image: maeddes/simple-generator:v2404 + image: ghcr.io/novatecconsulting/openteleemetry-training-simple-generator:v2404 build: context: ./loadgenerator networks: diff --git a/exercises/otel-in-action/todobackend-springboot/Dockerfile b/exercises/otel-in-action/todobackend-springboot/Dockerfile index bcc02e7..0ac5ba3 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","com.example.todobackend.TodobackendApplication"] \ 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..d58339f 100644 --- a/exercises/otel-in-action/todobackend-springboot/pom.xml +++ b/exercises/otel-in-action/todobackend-springboot/pom.xml @@ -11,11 +11,11 @@ - io.novatec + com.example todobackend 0.0.1-SNAPSHOT todobackend - Novatec Demo Application + Demo Application 21 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..abc271b 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 com.example.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; } 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..97a63c0 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 com.example.todobackend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/exercises/otel-in-action/todoui-thymeleaf/Dockerfile b/exercises/otel-in-action/todoui-thymeleaf/Dockerfile index ba32ead..a547eb1 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", "com.example.todoui.TodouiApplication"] +#ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","com.example.todobackend.TodobackendApplication"] diff --git a/exercises/otel-in-action/todoui-thymeleaf/pom.xml b/exercises/otel-in-action/todoui-thymeleaf/pom.xml index 3dc4994..da05675 100644 --- a/exercises/otel-in-action/todoui-thymeleaf/pom.xml +++ b/exercises/otel-in-action/todoui-thymeleaf/pom.xml @@ -3,7 +3,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 + com.example todoui 0.0.1-SNAPSHOT jar @@ -50,8 +50,8 @@ opentelemetry-instrumentation-annotations 1.29.0 ---> - +--> + - + 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..16f0082 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 com.example.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..52a72c2 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 - com.example.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=com.example.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=com.example.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..9ebe2c6 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 com.example.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=com.example.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} ``` diff --git a/tutorial/content/exercises/instrumentation/manual_java/metrics/index.md b/tutorial/content/exercises/instrumentation/manual_java/metrics/index.md index 8b57309..1f23cb5 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 com.example.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=com.example.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=com.example.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..9732048 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 com.example.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: com.example.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: com.example.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: com.example.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: com.example.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: com.example.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. - -