-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds Micrometer Tracing Example #110
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# yamllint --format github .github/workflows/deploy.yml | ||
--- | ||
name: deploy webflux6-micrometer | ||
|
||
on: | ||
# We deploy non-tagged pushes to master relevant for this project. We can't opt out of | ||
# documentation-only commits because GH actions does not permit paths and paths-ignore. | ||
push: | ||
tags: '' | ||
branches: master | ||
paths: | ||
- "build-bin/**" | ||
- "docker/**" | ||
- "webflux6-micrometer/**" | ||
- ".github/workflows/deploy-webflux6-micrometer.yaml" | ||
- "parent-pom.xml" | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-22.04 # newest available distribution, aka jellyfish | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
- name: Cache local Maven repository | ||
uses: actions/cache@v3 | ||
with: | ||
path: ./m2repository # Shared with the Docker build context via .dockerignore | ||
key: ${{ runner.os }}-webflux6-micrometer-maven-${{ hashFiles('parent-pom.xml', 'webflux6-micrometer/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-webflux6-micrometer-maven- | ||
# Don't attempt to cache Docker. Sensitive information can be stolen | ||
# via forks, and login session ends up in ~/.docker. This is ok because | ||
# we publish DOCKER_PARENT_IMAGE to ghcr.io, hence local to the runner. | ||
- name: Deploy webflux6-micrometer | ||
env: | ||
# GH_USER=<user that created GH_TOKEN> | ||
GH_USER: ${{ secrets.GH_USER }} | ||
# GH_TOKEN=<hex token value> | ||
# - pushes Docker images to ghcr.io | ||
# - create via https://github.com/settings/tokens | ||
# - needs repo:status, public_repo, write:packages, delete:packages | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
run: | | ||
build-bin/configure_deploy webflux6-micrometer && | ||
build-bin/deploy webflux6-micrometer |
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 @@ | ||
# yamllint --format github .github/workflows/test.yml | ||
--- | ||
name: test webflux6-micrometer | ||
|
||
on: | ||
# We deploy non-tagged pushes to master relevant for this project. We can't opt out of | ||
# documentation-only commits because GH actions does not permit paths and paths-ignore. | ||
pull_request: | ||
branches: master | ||
paths: | ||
- "build-bin/**" | ||
- "docker/**" | ||
- "webflux6-micrometer/**" | ||
- ".github/workflows/test-webflux6-micrometer.yaml" | ||
- "parent-pom.xml" | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-22.04 # newest available distribution, aka jellyfish | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
- name: Cache local Maven repository | ||
uses: actions/cache@v3 | ||
with: | ||
path: ./m2repository # Shared with the Docker build context via .dockerignore | ||
key: ${{ runner.os }}-webflux6-micrometer-maven-${{ hashFiles('parent-pom.xml', 'webflux6-micrometer/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-webflux6-micrometer-maven- | ||
# Don't attempt to cache Docker. Sensitive information can be stolen | ||
# via forks, and login session ends up in ~/.docker. This is ok because | ||
# we publish DOCKER_PARENT_IMAGE to ghcr.io, hence local to the runner. | ||
- name: Test webflux6-micrometer | ||
run: | | ||
build-bin/configure_test webflux6-micrometer && | ||
build-bin/test webflux6-micrometer |
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 |
---|---|---|
|
@@ -14,30 +14,36 @@ DOCKER_ARCHS="amd64 arm64" | |
|
||
case "${JRE_VERSION}" in | ||
6 ) | ||
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:11.0.22_p7 | ||
DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:1.6.0-119 | ||
# single arch image | ||
DOCKER_ARCHS=amd64 | ||
;; | ||
7 ) | ||
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:11.0.22_p7 | ||
DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:1.7.0_285 | ||
# single arch image | ||
DOCKER_ARCHS=amd64 | ||
;; | ||
8 ) | ||
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:11.0.22_p7 | ||
DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:8.392.08-jre | ||
;; | ||
11 ) | ||
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:11.0.22_p7 | ||
DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:11.0.22_p7-jre | ||
;; | ||
17 ) | ||
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:21.0.2_p13 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to parameterize this as spring boot requires minimal JRE 17.. the first project to require this. |
||
DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:17.0.10_p7-jre | ||
;; | ||
21 ) | ||
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:21.0.2_p13 | ||
DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:21.0.2_p13-jre | ||
;; | ||
* ) | ||
echo "Invalid JRE_VERSION: ${JRE_VERSION}" | ||
exit 1 | ||
esac | ||
|
||
export DOCKER_PARENT_IMAGE DOCKER_ARCHS | ||
export DOCKER_BUILD_IMAGE DOCKER_PARENT_IMAGE DOCKER_ARCHS |
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,15 @@ | ||
## Tracing Example: Spring 6/Reactor Netty/Spring Boot 3/Micrometer/Log4J 2 | ||
|
||
Instead of servlet, this uses Spring Boot 3 to create a self-contained | ||
application that runs Spring WebFlux 6 controllers. | ||
|
||
* brave.example.Frontend and Backend: Rest controllers | ||
* brave.example.AppAutoConfiguration: Sets up the WebClient used in the Frontend. | ||
|
||
Application code doesn't show any tracing configuration because that's handled | ||
by [Micrometer Tracing](https://docs.micrometer.io/tracing/reference/index.html), | ||
configured by [Spring Boot](https://docs.spring.io/spring-boot/docs/3.2.2/reference/htmlsingle/#actuator.micrometer-tracing.tracer-implementations.brave-zipkin). | ||
|
||
Micrometer Tracing has its own Tracer API that can bridge to Brave's with a | ||
plugin. This allows users to mix Micrometer with native Brave instrumentation. | ||
However, this example does not use any native Brave instrumentation. |
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,91 @@ | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.zipkin.brave.example</groupId> | ||
<artifactId>brave-example-parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../parent-pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>brave-example-webflux6-micrometer</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>brave-example-webflux6-micrometer</name> | ||
<description>Tracing Example: Spring 6, Reactor Netty, Spring Boot 3, Micrometer, Log4J 2, JRE 21</description> | ||
|
||
<properties> | ||
<jre.version>21</jre.version> | ||
<maven.compiler.release>17</maven.compiler.release> | ||
|
||
<spring-boot.version>3.2.2</spring-boot.version> | ||
<micrometer.version>1.2.2</micrometer.version> | ||
|
||
<!-- pinned to old brave until this commit is released | ||
https://github.com/micrometer-metrics/tracing/commit/d11d8039c73d901e44197b87103e66c392b6d7a8 --> | ||
<brave.version>5.17.1</brave.version> | ||
<zipkin-reporter.version>2.17.2</zipkin-reporter.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<!-- Configures Spring Boot with WebFlux SLF4J logging --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
<!-- Adds /actuator/health endpoint we re-map to /health used by our Docker HEALTHCHECK --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
<version>${spring-boot.version}</version> | ||
</dependency> | ||
|
||
<!-- micrometer-tracing-bridge-brave configures instrumentation including what's in Brave and their own. --> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-tracing-bridge-brave</artifactId> | ||
<version>${micrometer.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.zipkin.reporter2</groupId> | ||
<artifactId>zipkin-reporter-brave</artifactId> | ||
<version>${zipkin-reporter.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<!-- This can be overridden to brave.example.Frontend also --> | ||
<mainClass>brave.example.Backend</mainClass> | ||
<classifier>exec</classifier> | ||
<executable>true</executable> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
webflux6-micrometer/src/main/java/brave/example/AppAutoConfiguration.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,14 @@ | ||
package brave.example; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
/** The application is simple, it only uses WebFlux. */ | ||
// This type makes support easier as forks can make a diff off a working AutoConfiguration type */ | ||
@Configuration | ||
public class AppAutoConfiguration { | ||
@Bean WebClient.Builder webClientBuilder() { | ||
return WebClient.builder(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
webflux6-micrometer/src/main/java/brave/example/Backend.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,30 @@ | ||
package brave.example; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Mono; | ||
|
||
@EnableAutoConfiguration | ||
@RestController | ||
public class Backend { | ||
|
||
@GetMapping("/api") | ||
public Mono<String> printDate(@RequestHeader("user_name") Optional<String> username) { | ||
return Mono.fromSupplier(() -> { | ||
String date = LocalDate.now().toString(); | ||
return username.map(u -> date + " " + u).orElse(date); | ||
}); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Backend.class, | ||
"--spring.application.name=backend", | ||
"--server.port=9000" | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
webflux6-micrometer/src/main/java/brave/example/Frontend.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,32 @@ | ||
package brave.example; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
@EnableAutoConfiguration | ||
@RestController | ||
public class Frontend { | ||
final WebClient webClient; | ||
|
||
@Autowired Frontend(WebClient.Builder webClientBuilder, | ||
@Value("${backend.endpoint:http://127.0.0.1:9000/api}") String backendEndpoint) { | ||
this.webClient = webClientBuilder.baseUrl(backendEndpoint).build(); | ||
} | ||
|
||
@GetMapping("/") public Mono<String> callBackend() { | ||
return webClient.get().uri("").retrieve().bodyToMono(String.class); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Frontend.class, | ||
"--spring.application.name=frontend", | ||
"--server.port=8081" | ||
); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
webflux6-micrometer/src/main/resources/META-INF/spring.factories
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,2 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
brave.example.AppAutoConfiguration |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normally I add a 'Trace Instrumentation' section with links as you can see above, but this time, I have no idea where they are! Also, I don't see any canonical page on properties in docs, so I'm referencing the java type directly.