-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from NovatecConsulting/manual-instrumentation-…
…java Manual instrumentation java
- Loading branch information
Showing
61 changed files
with
5,203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
**/__pycache__ | ||
**/.DS_STORE | ||
|
||
*.jar | ||
*.jar | ||
|
||
settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
**target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
*.jar | ||
|
||
__pycache__ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
opentelemetry-javaagent.jar |
23 changes: 23 additions & 0 deletions
23
exercises/manual-instrumentation-java/initial/todobackend-springboot/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM docker.io/maven:3-eclipse-temurin-21 as build | ||
WORKDIR /workspace/app | ||
|
||
COPY pom.xml . | ||
COPY src src | ||
|
||
RUN --mount=type=cache,target=/root/.m2 mvn install -DskipTests | ||
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar) | ||
|
||
FROM docker.io/eclipse-temurin:21-jdk-alpine | ||
RUN mkdir -p /opt/todobackend | ||
WORKDIR /opt/todobackend | ||
#RUN addgroup -S demo && adduser -S demo -G demo | ||
#USER demo | ||
VOLUME /tmp | ||
ARG DEPENDENCY=/workspace/app/target/dependency | ||
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /opt/todobackend/app/lib | ||
COPY --from=build ${DEPENDENCY}/META-INF /opt/todobackend/app/META-INF | ||
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app | ||
|
||
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/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"] |
74 changes: 74 additions & 0 deletions
74
exercises/manual-instrumentation-java/initial/todobackend-springboot/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.2.2</version> | ||
<relativePath /> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<groupId>io.novatec</groupId> | ||
<artifactId>todobackend-manual</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>todobackend-manual</name> | ||
<description>Novatec Demo Application</description> | ||
|
||
<properties> | ||
<java.version>21</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | ||
<version>2.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<scope>runtime</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
149 changes: 149 additions & 0 deletions
149
...l/todobackend-springboot/src/main/java/io/novatec/todobackend/TodobackendApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package io.novatec.todobackend; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
@SpringBootApplication | ||
@RestController | ||
@CrossOrigin(origins = "*") | ||
|
||
public class TodobackendApplication { | ||
|
||
private Logger logger = LoggerFactory.getLogger(TodobackendApplication.class); | ||
|
||
@Value("${HOSTNAME:not_set}") | ||
String hostname; | ||
|
||
@Value("${spring.profiles.active: none}") | ||
String profile; | ||
|
||
@Autowired | ||
TodoRepository todoRepository; | ||
|
||
|
||
private String getInstanceId() { | ||
|
||
if (!hostname.equals("not_set")) | ||
return hostname; | ||
return "probably localhost"; | ||
|
||
} | ||
|
||
@GetMapping("/hello") | ||
String hello() { | ||
|
||
return getInstanceId() + " Hallo, Welt ! "; | ||
|
||
} | ||
|
||
@GetMapping("/fail") | ||
String fail() { | ||
|
||
System.exit(1); | ||
return "fixed!"; | ||
} | ||
|
||
@GetMapping("/todos/") | ||
List<String> getTodos() { | ||
|
||
List<String> todos = new ArrayList<String>(); | ||
|
||
todoRepository.findAll().forEach(todo -> todos.add(todo.getTodo())); | ||
logger.info("GET /todos/ " + todos.toString()); | ||
|
||
return todos; | ||
} | ||
|
||
@PostMapping("/todos/{todo}") | ||
String addTodo(HttpServletRequest request, HttpServletResponse response, @PathVariable String todo){ | ||
|
||
logger.info("POST /todos/ "+todo.toString()); | ||
|
||
this.someInternalMethod(todo); | ||
|
||
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; | ||
|
||
} | ||
|
||
@DeleteMapping("/todos/{todo}") | ||
String removeTodo(@PathVariable String todo) { | ||
|
||
todoRepository.deleteById(todo); | ||
logger.info("DELETE /todos/ " + todo.toString()); | ||
return "removed " + todo; | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TodobackendApplication.class, args); | ||
} | ||
|
||
} | ||
|
||
@Entity | ||
class Todo { | ||
|
||
@Id | ||
String todo; | ||
|
||
public Todo() { | ||
} | ||
|
||
public Todo(String todo) { | ||
this.todo = todo; | ||
} | ||
|
||
public String getTodo() { | ||
return todo; | ||
} | ||
|
||
public void setTodo(String todo) { | ||
this.todo = todo; | ||
} | ||
|
||
} | ||
|
||
interface TodoRepository extends CrudRepository<Todo, String> { | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...ntation-java/initial/todobackend-springboot/src/main/resources/application-dev.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring.h2.console.enabled=true | ||
spring.h2.console.path=/h2 | ||
spring.datasource.url=jdbc:h2:mem:testdb | ||
spring.datasource.username=sa | ||
spring.datasource.password= |
3 changes: 3 additions & 0 deletions
3
...tation-java/initial/todobackend-springboot/src/main/resources/application-prod.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
spring.datasource.url= jdbc:postgresql://${POSTGRES_HOST:postgresdb}:5432/mydb | ||
spring.datasource.username=matthias | ||
spring.datasource.password=password |
13 changes: 13 additions & 0 deletions
13
...rumentation-java/initial/todobackend-springboot/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
server.port=8080 | ||
|
||
server.forward-headers-strategy=native | ||
management.endpoints.web.exposure.include=* | ||
|
||
spring.profiles.active=dev | ||
|
||
spring.jpa.hibernate.ddl-auto=update | ||
spring.jpa.show-sql=true | ||
#spring.jpa.properties.hibernate.format_sql=true | ||
|
||
spring.application.name=springboot-backend | ||
otel.exporter.otlp.endpoint=http://${COLLECTOR_HOST:localhost}:4317 |
12 changes: 12 additions & 0 deletions
12
...ringboot/src/test/java/io/novatec/todobackend/TodobackendApplicationIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.novatec.todobackend; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
public class TodobackendApplicationIntegrationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
exercises/manual-instrumentation-java/initial/todoui-thymeleaf/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM docker.io/maven:3-eclipse-temurin-21 as build | ||
WORKDIR /workspace/app | ||
|
||
COPY pom.xml . | ||
COPY src src | ||
|
||
RUN --mount=type=cache,target=/root/.m2 mvn install -DskipTests | ||
# RUN mvn install -DskipTests | ||
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar) | ||
|
||
FROM docker.io/eclipse-temurin:21-jdk-alpine | ||
RUN mkdir -p /opt/todoui | ||
WORKDIR /opt/todoui | ||
# RUN addgroup -S demo && adduser -S demo -G demo | ||
# USER demo | ||
VOLUME /tmp | ||
ARG DEPENDENCY=/workspace/app/target/dependency | ||
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /opt/todoui/app/lib | ||
COPY --from=build ${DEPENDENCY}/META-INF /opt/todoui/app/META-INF | ||
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todoui/app | ||
|
||
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/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"] | ||
|
Oops, something went wrong.