diff --git a/.dockerignore b/.dockerignore
index cc56d3d..e71bc56 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -5,6 +5,7 @@
**/target
**/.idea
+**/*.iml
**/*.md
**/Dockerfile
diff --git a/.github/workflows/docker-tests.yml b/.github/workflows/docker-tests.yml
index d52b563..eeaf154 100644
--- a/.github/workflows/docker-tests.yml
+++ b/.github/workflows/docker-tests.yml
@@ -11,7 +11,7 @@ jobs:
build-on-linux:
strategy:
matrix:
- docker-target: [armeria, webmvc25-jetty, webmvc3-jetty, webmvc4-boot, webmvc4-jetty]
+ project: [armeria, webmvc25-jetty, webmvc3-jetty, webmvc4-boot, webmvc4-jetty]
runs-on: ubuntu-latest
name: Build and verify Docker images
steps:
@@ -30,16 +30,12 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 1
- - name: Build Docker image openzipkin/example-brave:${{ matrix.docker-target }}-test
- run: |
- TARGET=${{ matrix.docker-target }}
- DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile \
- -t openzipkin/example-brave:${TARGET}-test \
- --target ${TARGET} --build-arg target=${TARGET} .
- - name: Verify Docker image openzipkin/example-brave:${{ matrix.docker-target }}-test
+ - name: Build Docker image openzipkin/example-brave:${{ matrix.project }}-test
+ run: docker/build_image ${{ matrix.project }} ${{ matrix.project }}-test
+ - name: Verify Docker image openzipkin/example-brave:${{ matrix.project }}-test
run: |
# This just makes sure containers run and the HEALTHCHECK works (for now..)
- IMAGE=openzipkin/example-brave:${{ matrix.docker-target }}-test
+ IMAGE=openzipkin/example-brave:${{ matrix.project }}-test
docker run --rm --name frontend -d ${IMAGE} frontend
docker run --rm --name backend -d ${IMAGE} backend
docker/bin/block-on-health frontend || exit 1
diff --git a/README.md b/README.md
index 486403b..32e9150 100644
--- a/README.md
+++ b/README.md
@@ -1,72 +1,85 @@
-# Basic example showing distributed tracing across servlet applications
-This is an example app where two Servlet (Java) services collaborate on
-an http request. Notably, timing of these requests are recorded into
-[Zipkin](https://zipkin.io/), a distributed tracing system. This allows
-you to see the how long the whole operation took, as well how much time
-was spent in each service.
+# Basic example showing distributed tracing across HTTP applications
+This is an example app where two Java services collaborate on a request.
-Here's an example of what it looks like:
+Notably, these services send data to [Zipkin](https://zipkin.io/), a
+distributed tracing system. Zipkin allows you to see the how long the operation
+took, as well how much time was spent in each service.
-
+Here's an example of what it looks like:
-This example was ported from https://github.com/openzipkin/sleuth-webmvc-example
+
# Implementation Overview
-
-Web requests are served by [Spring MVC](https://spring.io/guides/gs/rest-service/) controllers,
-and tracing is automatically performed for you by [Brave](https://github.com/openzipkin/brave).
-
-This example intentionally avoids advanced topics like async and messaging,
-even though Brave supports that, too. Once you get familiar with things,
-you can play with more interesting [Brave instrumentation](https://github.com/openzipkin/brave/tree/master/instrumentation).
+This example has two services: frontend and backend. Both are [instrumented](https://github.com/openzipkin/brave/tree/master/instrumentation)
+to send tracing data to a third service [Zipkin](https://zipkin.io/). [Brave](https://github.com/openzipkin/brave)
+performs this function.
# Running the example
-This example has two services: frontend and backend. They both report trace data to zipkin. To setup the demo, you need to start Frontend, Backend and Zipkin.
+To setup the demo, you need to start Frontend, Backend and Zipkin. You can do
+this using Java commands or Docker.
Once the services are started, open http://localhost:8081/
-* This will call the backend (http://localhost:9000/api) and show the result, which defaults to a formatted date.
+* This calls the backend (http://localhost:9000/api) and shows its result: a formatted date.
-Next, you can view traces that went through the backend via http://localhost:9411/?serviceName=backend
+Afterwards, you can view traces that went through the backend via http://localhost:9411/?serviceName=backend
* This is a locally run zipkin service which keeps traces in memory
-## Starting the Services
+## Starting the services
-### Servlet Container Option
-In a separate tab or window, start each of [brave.webmvc.Frontend](/webmvc4-jetty/src/main/java/brave/webmvc/Frontend.java)
-and [brave.webmvc.Backend](/webmvc4-jetty/src/main/java/brave/webmvc/Backend.java):
+First, start [Zipkin](https://zipkin.io/). This stores and queries traces
+reported by the example services.
+
+Starting Zipkin with Java:
```bash
-# choose webmvc25 webmvc3 or webmvc4
-$ cd webmvc4
-$ mvn jetty:run -Pfrontend
-$ mvn jetty:run -Pbackend
+curl -sSL https://zipkin.io/quickstart.sh | bash -s
+java -jar zipkin.jar
```
-### Spring Boot Option
-In a separate tab or window, start each of [brave.webmvc.Frontend](/webmvc4-boot/src/main/java/brave/webmvc/Frontend.java)
-and [brave.webmvc.Backend](/webmvc4-boot/src/main/java/brave/webmvc/Backend.java):
+### Armeria
+
+Here are our [Armeria](https://armeria.dev/) examples:
+* [HTTP](armeria) - uses Armeria APIs to serve and invoke HTTP requests
+
+#### Starting Armeria with Java
+In a separate tab or window, start each of [brave.example.Frontend](/armeria/src/main/java/brave/example/Frontend.java)
+and [brave.example.Backend](/armeria/src/main/java/brave/example/Backend.java):
```bash
-$ cd webmvc4-boot
-$ mvn compile exec:java -Dexec.mainClass=brave.webmvc.Backend
-$ mvn compile exec:java -Dexec.mainClass=brave.webmvc.Frontend
+$ cd armeria
+$ mvn compile exec:java -Dexec.mainClass=brave.example.Backend
+$ mvn compile exec:java -Dexec.mainClass=brave.example.Frontend
```
-Next, run [Zipkin](https://zipkin.io/), which stores and queries traces
-reported by the above services.
+### Servlet
+Our Servlet examples use [Jetty](https://www.eclipse.org/jetty/) and
+[Spring MVC](https://spring.io/guides/gs/rest-service/) controllers. These
+examples primarily show how configuration works in XML or Java configuration:
+* [WebMVC 2.5](webmvc25-jetty) - Spring XML on Servlet 2.5 container
+* [WebMVC 3](webmvc3-jetty) - Spring XML on Servlet 3 container
+* [WebMVC 4](webmvc4-jetty) - Spring Java Config on Servlet 3 container
+#### Starting Jetty with Java
+In a separate tab or window, start each of [brave.example.Frontend](/webmvc4-jetty/src/main/java/brave/example/Frontend.java)
+and [brave.example.Backend](/webmvc4-jetty/src/main/java/brave/example/Backend.java):
```bash
-curl -sSL https://zipkin.io/quickstart.sh | bash -s
-java -jar zipkin.jar
+$ cd webmvc4-jetty
+$ mvn jetty:run -Pfrontend
+$ mvn jetty:run -Pbackend
```
-### Docker Option
-You can run any configuration using pre-built Docker images. Look at
-[docker](docker) for examples.
+### Spring Boot
+Here are our Spring Boot examples:
+* [Spring Boot 1.5](webmvc4-boot) - [Spring MVC 4](https://spring.io/guides/gs/rest-service/)
+
+#### Starting Spring Boot with Java
+In a separate tab or window, start each of [brave.example.Frontend](/webmvc4-boot/src/main/java/brave/example/Frontend.java)
+and [brave.example.Backend](/webmvc4-boot/src/main/java/brave/example/Backend.java):
+```bash
+$ cd webmvc4-boot
+$ mvn compile exec:java -Dexec.mainClass=brave.example.Backend
+$ mvn compile exec:java -Dexec.mainClass=brave.example.Frontend
+```
## Configuration tips
-To show how wiring works, we have three copies of the same project
-* [WebMVC 2.5](webmvc25-jetty) - Spring XML on Servlet 2.5 container
-* [WebMVC 3](webmvc3-jetty) - Spring XML on Servlet 3 container
-* [WebMVC 4](webmvc4-jetty) - Spring Java Config on Servlet 3 container
There are some interesting details that apply to both
* If you pass the header `user_name` Brave will automatically propagate it to the backend!
diff --git a/armeria/README.md b/armeria/README.md
index cac1256..b02e767 100644
--- a/armeria/README.md
+++ b/armeria/README.md
@@ -1,36 +1,7 @@
-# Basic example showing distributed tracing across Armeria apps
-This is an example app where two Armeria (Java) services collaborate on an http request. Notably, timing of these requests are recorded into [Zipkin](http://zipkin.io/), a distributed tracing system. This allows you to see the how long the whole operation took, as well how much time was spent in each service.
+## Tracing Example: Armeria
-Here's an example of what it looks like
-
+Instead of servlet, this uses [Armeria](https://armeria.dev/) to serve HTTP
+requests. Both services run as a normal Java application.
-# Implementation Overview
-
-Web requests are served by [Armeria](https://line.github.io/armeria/server-basics.html) services, which trace requests by using the [Zipkin plugin](https://line.github.io/armeria/advanced-zipkin.html).
-
-These traces are sent out of process over http to Zipkin.
-
-This example intentionally avoids advanced topics like async and load balancing, eventhough Armeria supports them.
-
-# Running the example
-This example has two services: frontend and backend. They both report trace data to zipkin. To setup the demo, you need to start Frontend, Backend and Zipkin.
-
-Once the services are started, open http://localhost:8081/
-* This will call the backend (http://localhost:9000/api) and show the result, which defaults to a formatted date.
-
-Next, you can view traces that went through the backend via http://localhost:9411/?serviceName=backend
-* This is a locally run zipkin service which keeps traces in memory
-
-## Starting the Services
-In a separate tab or window, start each of [Frontend](/brave/example/armeria/Frontend.java) and [Backend](/brave/example/armeria/Backend.java):
-```bash
-$ mvn compile exec:java -Dexec.mainClass=brave.example.Frontend
-$ mvn compile exec:java -Dexec.mainClass=brave.example.Backend
-```
-
-Next, run [Zipkin](http://zipkin.io/), which stores and queries traces reported by the above services.
-
-```bash
-curl -sSL https://zipkin.io/quickstart.sh | bash -s
-java -jar zipkin.jar
-```
+* brave.example.Frontend and Backend : HTTP controllers with a trace configuration hook
+* brave.example.HttpTracingFactory : Configures the tracing subsystem
diff --git a/armeria/pom.xml b/armeria/pom.xml
index f624d11..21a6b54 100644
--- a/armeria/pom.xml
+++ b/armeria/pom.xml
@@ -3,24 +3,25 @@
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">
4.0.0
+
+ io.zipkin.brave.example
+ brave-example-parent
+ 1.0-SNAPSHOT
+ ../parent-pom.xml
+
- io.zipkin.brave.example
brave-example-armeria
- 1.0-SNAPSHOT
jar
brave-example-armeria
- Tracing Example: Armeria
+ Tracing Example: Armeria/ Java 15
- UTF-8
-
- 1.8
- 1.8
+ 15
+ 8
1.0.0
- 5.12.6
@@ -60,42 +61,6 @@
pom
import
-
- io.zipkin.brave
- brave-bom
- ${brave.version}
- pom
- import
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 3.1.2
-
-
-
-
-
-
- maven-compiler-plugin
- 3.8.1
-
- true
- true
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 3.0.0
-
-
-
diff --git a/docker/Dockerfile b/docker/Dockerfile
index c342a82..f162b00 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,5 +1,6 @@
# These examples are setup minimally. In order to reduce repetition, these do not setup
# non-root users and such as they are not intended to run in production anyway.
+ARG jre_image
# We copy files from the context into a scratch container first to avoid a problem where docker and
# docker-compose don't share layer hashes https://github.com/docker/compose/issues/883 normally.
@@ -11,113 +12,48 @@ COPY . /code/
## Use JDK 11 to build projects, as that can still compile Java 6
FROM openzipkin/java:11.0.8-11.41.23 as install
-# The final stage to build. Mandatory: ex webmvc4-jetty
-ARG target
-RUN test -z "$target" && \
- echo "'--build-arg target' must be set to same value as '--target'" && exit 1 || true
+ARG project
WORKDIR /code
COPY --from=scratch /code .
-# We copy the result of the build into a target-specific install directory.
-# Each end phase looks for this convention. This strategy enforces a match
-# between --target and the --build-arg target.
-WORKDIR /install/${target}
-
-# invoke the platfom-specific install script and copy the results
-RUN cd /code/$target && mvn -q --batch-mode -DskipTests package && \
- platform=$(echo $target|cut -d- -f2) && \
- if [ "$platform" = "armeria" ]; then platform=java;fi && \
+RUN cd $project && \
+ # Invoke the platform-specific install script
+ platform=$(echo "${project}"|cut -d- -f2) && \
+ if [ "${platform}" = "armeria" ]; then platform=java;fi && \
+ mvn -q --batch-mode -DskipTests package && \
/code/docker/bin/install-${platform}-example && \
- cp -rp install/* /install/${target}/ && \
-# Add start and health check scripts
- mkdir /install/${target}/docker-bin && cd /install/${target}/docker-bin && \
- cp -p /code/docker/bin/docker-healthcheck . && \
- cp -p /code/docker/bin/start-${platform}-example start-brave-example
-
-FROM openzipkin/java:15.0.0-15.27.17-jre as armeria
-LABEL description="Tracing Example: Armeria/Java 15"
+ # Move the completed installation root
+ mv install /install && \
+ # Add scripts used at runtime
+ cd /install/bin && \
+ cp -p /code/docker/bin/start-example-header start-brave-example && \
+ cat /code/docker/bin/start-${platform}-example >> start-brave-example && \
+ cp -p /code/docker/bin/docker-healthcheck .
-WORKDIR /brave-example
-COPY --from=install /install/armeria/ .
-# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
-RUN mv docker-bin/* /usr/local/bin/ && rmdir docker-bin
+# Make the final layer that the example will run in
+FROM $jre_image
-EXPOSE 8081 9000
+# All content including binaries and logs write under WORKDIR
+ARG USER=brave-example
+WORKDIR /${USER}
-ENV JAVA_OPTS="-Xms16m -Xmx16m -XX:+ExitOnOutOfMemoryError"
+# Ensure the process doesn't run as root
+RUN adduser -g '' -h ${PWD} -D ${USER}
-ENTRYPOINT ["start-brave-example"]
+# Copy binaries and config we installed earlier
+COPY --from=install --chown=${USER} /install .
-# We use start period of 30s to avoid marking the container unhealthy on slow or contended CI hosts
-HEALTHCHECK --interval=1s --start-period=30s --timeout=5s CMD ["docker-healthcheck"]
-
-FROM azul/zulu-openjdk-alpine:6u119-6.22.0.3 as webmvc25-jetty
-LABEL description="Tracing Example: Spring WebMVC 2.5/Servlet 2.5/Jetty 7/Java 6"
-# Adding maintainer label as we are using a 3rd party base layer
-LABEL maintainer="OpenZipkin https://zipkin.io/"
-
-WORKDIR /brave-example
-COPY --from=install /install/webmvc25-jetty/ .
# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
-RUN mv docker-bin/* /usr/local/bin/ && rmdir docker-bin
+RUN mv bin/* /usr/local/bin/ && rm -rf bin
-EXPOSE 8081 9000
-
-# When using JRE 1.6, we cannot use -XX:+ExitOnOutOfMemoryError
-ENV JAVA_OPTS="-Xms16m -Xmx16m"
-ENTRYPOINT ["start-brave-example"]
+# Switch to the runtime user
+USER ${USER}
# We use start period of 30s to avoid marking the container unhealthy on slow or contended CI hosts
HEALTHCHECK --interval=1s --start-period=30s --timeout=5s CMD ["docker-healthcheck"]
-FROM openzipkin/java:1.7.0_261-b02-jre as webmvc3-jetty
-LABEL description="Tracing Example: Spring WebMVC 3/Servlet 3.0/Jetty 8/Java 7"
-
-WORKDIR /brave-example
-COPY --from=install /install/webmvc3-jetty/ .
-# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
-RUN mv docker-bin/* /usr/local/bin/ && rmdir docker-bin
-
+# Expose the default ports for the frontend and backend
EXPOSE 8081 9000
-ENV JAVA_OPTS="-Xms16m -Xmx16m -XX:+ExitOnOutOfMemoryError"
-
ENTRYPOINT ["start-brave-example"]
-
-# We use start period of 30s to avoid marking the container unhealthy on slow or contended CI hosts
-HEALTHCHECK --interval=1s --start-period=30s --timeout=5s CMD ["docker-healthcheck"]
-
-FROM openzipkin/java:1.8.0_252-b09-jre as webmvc4-boot
-LABEL description="Tracing Example: Spring WebMVC 4/Spring Boot 1.5/Java 8"
-
-WORKDIR /brave-example
-COPY --from=install /install/webmvc4-boot/ .
-# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
-RUN mv docker-bin/* /usr/local/bin/ && rmdir docker-bin
-
-EXPOSE 8081 9000
-
-ENV JAVA_OPTS="-Xms32m -Xmx64m -XX:+ExitOnOutOfMemoryError"
-
-ENTRYPOINT ["start-brave-example"]
-
-# We use start period of 30s to avoid marking the container unhealthy on slow or contended CI hosts
-HEALTHCHECK --interval=1s --start-period=30s --timeout=5s CMD ["docker-healthcheck"]
-
-FROM openzipkin/java:1.8.0_252-b09-jre as webmvc4-jetty
-LABEL description="Tracing Example: Spring WebMVC 4/Servlet 3.1/Jetty 9/Java 8"
-
-WORKDIR /brave-example
-COPY --from=install /install/webmvc4-jetty/ .
-# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
-RUN mv docker-bin/* /usr/local/bin/ && rmdir docker-bin
-
-EXPOSE 8081 9000
-
-ENV JAVA_OPTS="-Xms16m -Xmx16m -XX:+ExitOnOutOfMemoryError"
-
-ENTRYPOINT ["start-brave-example"]
-
-# We use start period of 30s to avoid marking the container unhealthy on slow or contended CI hosts
-HEALTHCHECK --interval=1s --start-period=30s --timeout=5s CMD ["docker-healthcheck"]
diff --git a/docker/RATIONALE.md b/docker/RATIONALE.md
index 2ed1a6e..c992b94 100644
--- a/docker/RATIONALE.md
+++ b/docker/RATIONALE.md
@@ -1,12 +1,8 @@
# docker rationale
-## Why do we set `--build-arg target` to the same value as `--target`?
+## Why does `build_image` manually parse XML?
-There are very few differences in our docker images from a scripting point of
-view. However, each has different contents, and most have a different base
-layer. We need to know the target stage before we create it, so that we can
-build the right contents. There's no known way to read the value of the
-`--target` parameter. Hence, we duplicate it as a build argument.
-
-One impact of doing this is `DOCKER_BUILDKIT=1` or similar is required to skip
-unused phases present in the process of building the image.
+`build_image` is a script used to build Docker images per project. We need
+some details from the pom file for build arguments. Rather than require
+installing an XML parser or invoking Maven, this uses `sed` which is commonly
+present on developer laptops and CI nodes.
diff --git a/docker/README.md b/docker/README.md
index cfc494c..1a0bb12 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -24,27 +24,9 @@ services:
## Building images
-To build the Armeria/Java 15 example:
-```bash
-$ DOCKER_BUILDKIT=1 docker build -t openzipkin/example-brave:armeria -f docker/Dockerfile --target armeria --build-arg target=armeria .
-```
-
-To build the Spring WebMVC 2.5/Servlet 2.5/Jetty 7/Java 6 example:
-```bash
-$ DOCKER_BUILDKIT=1 docker build -t openzipkin/example-brave:webmvc25-jetty -f docker/Dockerfile --target webmvc25-jetty --build-arg target=webmvc25-jetty .
-```
-
-To build the Spring WebMVC 3/Servlet 3.0/Jetty 8/Java 7 example:
-```bash
-$ DOCKER_BUILDKIT=1 docker build -t openzipkin/example-brave:webmvc3-jetty -f docker/Dockerfile --target webmvc3-jetty --build-arg target=webmvc3-jetty .
-```
-
-To build the Spring WebMVC 4/Spring Boot 1.5/Java 8 example:
-```bash
-$ DOCKER_BUILDKIT=1 docker build -t openzipkin/example-brave:webmvc4-boot -f docker/Dockerfile --target webmvc4-boot --build-arg target=webmvc4-boot .
-```
+To build an example, from the root directory, invoke `docker/build_image YOUR_PROJECT`:
-To build the Spring WebMVC 4/Servlet 3.1/Jetty 9/Java 8 example:
+Ex. To build the Armeria example as the image 'openzipkin/example-brave:test'
```bash
-$ DOCKER_BUILDKIT=1 docker build -t openzipkin/example-brave:webmvc4-jetty -f docker/Dockerfile --target webmvc4-jetty --build-arg target=webmvc4-jetty .
+$ docker/build_image armeria test
```
diff --git a/docker/bin/install-boot-example b/docker/bin/install-boot-example
index 4f5d536..257cf07 100755
--- a/docker/bin/install-boot-example
+++ b/docker/bin/install-boot-example
@@ -1,7 +1,7 @@
#!/bin/sh
set -eu
-mkdir install
+mkdir -p install/bin
# extract the exec jar
cd install && jar xf ../target/*-exec.jar
diff --git a/docker/bin/install-java-example b/docker/bin/install-java-example
index 40e2589..0de988c 100755
--- a/docker/bin/install-java-example
+++ b/docker/bin/install-java-example
@@ -1,6 +1,8 @@
#!/bin/sh
set -eu
+mkdir -p install/bin
+
# Copy dependencies and compiled classes
mvn -q --batch-mode dependency:copy-dependencies -DoutputDirectory=install/lib
cp -r target/classes install/
diff --git a/docker/bin/install-jetty-example b/docker/bin/install-jetty-example
index 9b9dbf7..f7ce384 100755
--- a/docker/bin/install-jetty-example
+++ b/docker/bin/install-jetty-example
@@ -2,7 +2,7 @@
set -eu
-mkdir install
+mkdir -p install/bin
# extract the war under /root
cp -r target/*-SNAPSHOT install/root
diff --git a/docker/bin/start-boot-example b/docker/bin/start-boot-example
index 49d05b1..1b849bd 100755
--- a/docker/bin/start-boot-example
+++ b/docker/bin/start-boot-example
@@ -1,28 +1,7 @@
-#!/bin/sh
+JAVA_OPTS=${JAVA_OPTS:-"-Xms32m -Xmx64m -XX:+ExitOnOutOfMemoryError"}
-set -eu
-
-case "$1" in
- f|frontend|Frontend )
- CLASS_NAME=Frontend
- PORT=8081
- ;;
- b|backend|Backend )
- CLASS_NAME=Backend
- PORT=9000
- ;;
- * )
- echo "Invalid argument: specify frontend or backend"
- exit 1
-esac
-
-# write the docker-healthcheck url to a file
-IP="$(hostname -i || echo '127.0.0.1')"
-echo http://${IP}:${PORT}/health > health_url
-
-exec java ${JAVA_OPTS} -cp . \
+exec java ${JAVA_OPTS} -cp '.:BOOT-INF/lib/*:BOOT-INF/classes' \
-Dzipkin.endpoint=${ZIPKIN_ENDPOINT:=http://zipkin:9411/api/v2/spans} \
-Dzipkin.supportsJoin=${ZIPKIN_SUPPORTS_JOIN:=true} \
-Dbackend.endpoint=${BACKEND_ENDPOINT:=http://backend:9000/api} \
- -Dloader.main=brave.webmvc.${CLASS_NAME} org.springframework.boot.loader.PropertiesLauncher \
- --server.port=${PORT}
+ ${MAIN_CLASS}
diff --git a/docker/bin/start-example-header b/docker/bin/start-example-header
new file mode 100755
index 0000000..99af52a
--- /dev/null
+++ b/docker/bin/start-example-header
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -eu
+
+case "$1" in
+ frontend )
+ ZIPKIN_SERVICE=frontend
+ MAIN_CLASS=brave.example.Frontend
+ PORT=8081
+ ;;
+ backend )
+ ZIPKIN_SERVICE=backend
+ MAIN_CLASS=brave.example.Backend
+ PORT=9000
+ ;;
+ * )
+ echo "Invalid argument: specify frontend or backend"
+ exit 1
+esac
+
+# write the docker-healthcheck url to a file
+IP="$(hostname -i || echo '127.0.0.1')"
+echo http://${IP}:${PORT}/health > health_url
diff --git a/docker/bin/start-java-example b/docker/bin/start-java-example
index 8bfbb83..5743ad6 100755
--- a/docker/bin/start-java-example
+++ b/docker/bin/start-java-example
@@ -1,27 +1,7 @@
-#!/bin/sh
-
-set -eu
-
-case "$1" in
- f|frontend|Frontend )
- CLASS_NAME=Frontend
- PORT=8081
- ;;
- b|backend|Backend )
- CLASS_NAME=Backend
- PORT=9000
- ;;
- * )
- echo "Invalid argument: specify frontend or backend"
- exit 1
-esac
-
-# write the docker-healthcheck url to a file
-IP="$(hostname -i || echo '127.0.0.1')"
-echo http://${IP}:${PORT}/health > health_url
+JAVA_OPTS=${JAVA_OPTS:-"-Xms16m -Xmx16m -XX:+ExitOnOutOfMemoryError"}
exec java ${JAVA_OPTS} -cp 'classes:lib/*' \
-Dzipkin.endpoint=${ZIPKIN_ENDPOINT:=http://zipkin:9411/api/v2/spans} \
-Dzipkin.supportsJoin=${ZIPKIN_SUPPORTS_JOIN:=true} \
-Dbackend.endpoint=${BACKEND_ENDPOINT:=http://backend:9000/api} \
- brave.example.${CLASS_NAME}
+ ${MAIN_CLASS}
diff --git a/docker/bin/start-jetty-example b/docker/bin/start-jetty-example
index 179abff..573af7b 100755
--- a/docker/bin/start-jetty-example
+++ b/docker/bin/start-jetty-example
@@ -1,28 +1,9 @@
-#!/bin/sh
-
-set -eu
-
-case "$1" in
- f|frontend|Frontend )
- ZIPKIN_SERVICE=frontend
- PORT=8081
- ;;
- b|backend|Backend )
- ZIPKIN_SERVICE=backend
- PORT=9000
- ;;
- * )
- echo "Invalid argument: specify frontend or backend"
- exit 1
-esac
-
-# write the docker-healthcheck url to a file
-IP="$(hostname -i || echo '127.0.0.1')"
-echo http://${IP}:${PORT}/health > health_url
-
# Handle the org switch between Jetty 8 and 9
ORG=$(test -f jetty/org/eclipse/jetty/runner/Runner.class && echo eclipse || echo mortbay)
+# No ' -XX:+ExitOnOutOfMemoryError' in case running Java 1.6
+JAVA_OPTS=${JAVA_OPTS:-"-Xms16m -Xmx16m"}
+
exec java ${JAVA_OPTS} -cp jetty \
-Dzipkin.endpoint=${ZIPKIN_ENDPOINT:=http://zipkin:9411/api/v2/spans} \
-Dzipkin.supportsJoin=${ZIPKIN_SUPPORTS_JOIN:=true} \
diff --git a/docker/build_image b/docker/build_image
new file mode 100755
index 0000000..a2ce1f0
--- /dev/null
+++ b/docker/build_image
@@ -0,0 +1,47 @@
+#!/bin/sh
+# This script is only a convenience as the build environment is controlled in
+# the Dockerfile. That said, it uses only basic shell commands to help it work
+# on developer laptops as well as CI nodes. Mainly, this centralizes the base
+# Java image mappings and ensures all metadata needed is taken from pom.xml.
+set -ue
+
+PROJECT=$1
+POM="${PROJECT}/pom.xml"
+
+if [ -f "${POM}" ]
+then
+ DESCRIPTION=$(sed -n 's/.*\(.*\)<\/description>.*/\1/p' "${POM}")
+ JRE_VERSION=$(sed -n 's/.*\(.*\)<\/jre.version>.*/\1/p' "${POM}")
+else
+ echo "Expected ${POM} to exist"
+ exit 1
+fi
+
+TAG=${2:-${PROJECT}}
+
+case "${JRE_VERSION}" in
+ 6 )
+ JRE_IMAGE=azul/zulu-openjdk-alpine:6u119-6.22.0.3
+ ;;
+ 7 )
+ JRE_IMAGE=openzipkin/java:1.7.0_261-b02-jre
+ ;;
+ 8 )
+ JRE_IMAGE=openzipkin/java:1.8.0_252-b09-jre
+ ;;
+ 11 )
+ JRE_IMAGE=openzipkin/java:11.0.8-11.41.23-jre
+ ;;
+ 15 )
+ JRE_IMAGE=openzipkin/java:15.0.0-15.27.17-jre
+ ;;
+ * )
+ echo "Invalid JRE_VERSION: ${JRE_VERSION}"
+ exit 1
+esac
+
+# Build the project
+docker build -f docker/Dockerfile -t openzipkin/example-brave:${TAG} \
+ --build-arg jre_image=${JRE_IMAGE} --build-arg project=${PROJECT} \
+ --label "description=${DESCRIPTION}" .
+
diff --git a/docker/hooks/build b/docker/hooks/build
index 49ec9e2..9fb6551 100755
--- a/docker/hooks/build
+++ b/docker/hooks/build
@@ -4,8 +4,7 @@
# to top level.
cd ..
-ALL_EXAMPLES=$(ls */pom.xml|sed 's~/pom.xml~~g')
-for target in ${ALL_EXAMPLES}; do
- DOCKER_BUILDKIT=1 docker build -f "$DOCKERFILE_PATH" -t "openzipkin/example-brave:${target}" \
- --target ${target} --build-arg target=${target} .
+ALL_PROJECTS=$(ls */pom.xml|sed 's~/pom.xml~~g')
+for PROJECT in ${ALL_PROJECTS}; do
+ docker/build_image "${PROJECT}"
done
diff --git a/docker/hooks/push b/docker/hooks/push
index 599ebdf..a31ac83 100755
--- a/docker/hooks/push
+++ b/docker/hooks/push
@@ -2,9 +2,9 @@
# Override push to avoid pushing a latest tag. We use tags for each example.
if [ "$DOCKER_REPO" = "index.docker.io/openzipkin/example-brave" ]; then
- ALL_EXAMPLES=$(cd ../; ls */pom.xml|sed 's~/pom.xml~~g')
+ ALL_PROJECTS=$(cd ../; ls */pom.xml |sed 's~/pom.xml~~g')
- for target in ${ALL_EXAMPLES}; do
- docker push "openzipkin/example-brave:${target}"
+ for PROJECT in ${ALL_PROJECTS}; do
+ docker push "openzipkin/example-brave:${PROJECT}"
done
fi
diff --git a/parent-pom.xml b/parent-pom.xml
new file mode 100644
index 0000000..5e44cae
--- /dev/null
+++ b/parent-pom.xml
@@ -0,0 +1,110 @@
+
+
+ 4.0.0
+
+ io.zipkin.brave.example
+ brave-example-parent
+ 1.0-SNAPSHOT
+ pom
+
+ Tracing Example (parent)
+ Common properties and project configuration for all examples
+ https://github.com/openzipkin/brave-example
+ 2013
+
+
+ OpenZipkin
+ https://zipkin.io/
+
+
+
+
+ The Apache Software License, Version 2.0
+ https://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
+
+
+ UTF-8
+ UTF-8
+ UTF-8
+ UTF-8
+
+ 5.12.6
+
+
+ SET MANUALLY IN PROJECTS
+
+ ${jre.version}
+
+ 3.0.0
+ 3.8.1
+ 3.1.2
+ 3.2.0
+ 3.2.3
+
+
+
+
+
+
+ io.zipkin.brave
+ brave-bom
+ ${brave.version}
+ pom
+ import
+
+
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ ${maven-dependency-plugin.version}
+
+
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ true
+ true
+ true
+
+
+
+ maven-jar-plugin
+ ${maven-jar-plugin.version}
+
+
+
+ false
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ ${exec-maven-plugin.version}
+
+
+ maven-war-plugin
+ ${maven-war-plugin.version}
+
+ false
+ WEB-INF/lib/servlet-api-*.jar,WEB-INF/lib/javax.servlet-api-*.jar
+
+
+
+
+
+
+
diff --git a/webmvc25-jetty/README.md b/webmvc25-jetty/README.md
index dd8f1d9..5737a41 100644
--- a/webmvc25-jetty/README.md
+++ b/webmvc25-jetty/README.md
@@ -5,7 +5,7 @@
`spring-webmvc-servlet.xml` is indirectly read due to spring references
in web.xml. This setups the app and tracing of it.
-* brave.webmvc.Frontend and Backend : Rest controllers with no tracing configuration
+* brave.example.Frontend and Backend : Rest controllers with no tracing configuration
* brave.spring.beans.TracingFactoryBean : This helps configure tracing, notably Log4J 1.2 integration
diff --git a/webmvc25-jetty/pom.xml b/webmvc25-jetty/pom.xml
index d84ec61..ca211e5 100755
--- a/webmvc25-jetty/pom.xml
+++ b/webmvc25-jetty/pom.xml
@@ -2,39 +2,28 @@
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">
4.0.0
+
+ io.zipkin.brave.example
+ brave-example-parent
+ 1.0-SNAPSHOT
+ ../parent-pom.xml
+
- io.zipkin.brave.example
brave-example-webmvc25
- 1.0-SNAPSHOT
war
brave-example-webmvc25-jetty
- Tracing Example: Spring WebMVC 2.5/Servlet 2.5/Jetty 7
+ Tracing Example: Spring WebMVC 2.5/Servlet 2.5/Jetty 7/JRE 6
- UTF-8
- 1.6
- 1.6
+ 6
2.5.6
- 5.12.6
org.mortbay.jetty
7.6.16.v20140903
-
-
-
- io.zipkin.brave
- brave-bom
- ${brave.version}
- pom
- import
-
-
-
-
javax.servlet
@@ -96,40 +85,8 @@
-
- maven-compiler-plugin
- 3.8.1
-
-
-
- maven-enforcer-plugin
- 3.0.0-M3
-
-
- enforce-java
-
- enforce
-
-
-
-
-
- [1.7.0_80,12)
-
-
-
-
-
-
-
maven-war-plugin
- 3.2.3
-
- false
- WEB-INF/lib/servlet-api-*.jar
-
diff --git a/webmvc25-jetty/src/main/java/brave/webmvc/Backend.java b/webmvc25-jetty/src/main/java/brave/example/Backend.java
similarity index 96%
rename from webmvc25-jetty/src/main/java/brave/webmvc/Backend.java
rename to webmvc25-jetty/src/main/java/brave/example/Backend.java
index 8af75a3..cb0c17d 100644
--- a/webmvc25-jetty/src/main/java/brave/webmvc/Backend.java
+++ b/webmvc25-jetty/src/main/java/brave/example/Backend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import java.io.IOException;
import java.util.Date;
diff --git a/webmvc25-jetty/src/main/java/brave/webmvc/Frontend.java b/webmvc25-jetty/src/main/java/brave/example/Frontend.java
similarity index 97%
rename from webmvc25-jetty/src/main/java/brave/webmvc/Frontend.java
rename to webmvc25-jetty/src/main/java/brave/example/Frontend.java
index 5780c0a..6348b79 100644
--- a/webmvc25-jetty/src/main/java/brave/webmvc/Frontend.java
+++ b/webmvc25-jetty/src/main/java/brave/example/Frontend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
diff --git a/webmvc25-jetty/src/main/java/brave/servlet/HealthServlet.java b/webmvc25-jetty/src/main/java/brave/example/HealthServlet.java
similarity index 95%
rename from webmvc25-jetty/src/main/java/brave/servlet/HealthServlet.java
rename to webmvc25-jetty/src/main/java/brave/example/HealthServlet.java
index 92d2530..21c7cc8 100644
--- a/webmvc25-jetty/src/main/java/brave/servlet/HealthServlet.java
+++ b/webmvc25-jetty/src/main/java/brave/example/HealthServlet.java
@@ -1,4 +1,4 @@
-package brave.servlet;
+package brave.example;
import java.io.IOException;
import java.io.PrintWriter;
diff --git a/webmvc25-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml b/webmvc25-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml
index 18f1988..c6371fd 100644
--- a/webmvc25-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml
+++ b/webmvc25-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml
@@ -36,9 +36,9 @@
-
+
-
+
diff --git a/webmvc25-jetty/src/main/webapp/WEB-INF/web.xml b/webmvc25-jetty/src/main/webapp/WEB-INF/web.xml
index fa13f1b..24fe6e3 100644
--- a/webmvc25-jetty/src/main/webapp/WEB-INF/web.xml
+++ b/webmvc25-jetty/src/main/webapp/WEB-INF/web.xml
@@ -9,7 +9,7 @@
health
- brave.servlet.HealthServlet
+ brave.example.HealthServlet
diff --git a/webmvc3-jetty/README.md b/webmvc3-jetty/README.md
index 2f1afd1..5f82d65 100644
--- a/webmvc3-jetty/README.md
+++ b/webmvc3-jetty/README.md
@@ -5,7 +5,7 @@
`spring-webmvc-servlet.xml` is indirectly read due to spring references
in web.xml. This setups the app and tracing of it.
-* brave.webmvc.Frontend and Backend : Rest controllers with no tracing configuration
+* brave.example.Frontend and Backend : Rest controllers with no tracing configuration
* brave.spring.beans.TracingFactoryBean : This helps configure tracing, notably Log4J 1.2 integration
diff --git a/webmvc3-jetty/pom.xml b/webmvc3-jetty/pom.xml
index 02f73a2..26f54d4 100755
--- a/webmvc3-jetty/pom.xml
+++ b/webmvc3-jetty/pom.xml
@@ -2,39 +2,28 @@
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">
4.0.0
+
+ io.zipkin.brave.example
+ brave-example-parent
+ 1.0-SNAPSHOT
+ ../parent-pom.xml
+
- io.zipkin.brave.example
brave-example-webmvc3-jetty
- 1.0-SNAPSHOT
war
brave-example-webmvc3-jetty
- Tracing Example: Spring WebMVC 3/Servlet 3.0/Jetty 8
+ Tracing Example: Spring WebMVC 3/Servlet 3.0/Jetty 8/JRE 7
- UTF-8
- 1.6
- 1.6
+ 7
3.2.18.RELEASE
- 5.12.6
org.mortbay.jetty
8.1.16.v20140903
-
-
-
- io.zipkin.brave
- brave-bom
- ${brave.version}
- pom
- import
-
-
-
-
javax.servlet
@@ -101,7 +90,7 @@
com.squareup.okhttp3
okhttp
- 3.12.12
+ 3.12.12
@@ -118,40 +107,7 @@
- maven-compiler-plugin
- 3.8.1
-
-
-
- maven-enforcer-plugin
- 3.0.0-M3
-
-
- enforce-java
-
- enforce
-
-
-
-
-
- [1.7.0_80,12)
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
maven-war-plugin
- 3.2.3
-
- false
- WEB-INF/lib/servlet-api-*.jar
-
diff --git a/webmvc3-jetty/src/main/java/brave/webmvc/Backend.java b/webmvc3-jetty/src/main/java/brave/example/Backend.java
similarity index 96%
rename from webmvc3-jetty/src/main/java/brave/webmvc/Backend.java
rename to webmvc3-jetty/src/main/java/brave/example/Backend.java
index 13d35ce..8c3a64b 100644
--- a/webmvc3-jetty/src/main/java/brave/webmvc/Backend.java
+++ b/webmvc3-jetty/src/main/java/brave/example/Backend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import java.util.Date;
import org.springframework.http.HttpStatus;
diff --git a/webmvc3-jetty/src/main/java/brave/webmvc/Frontend.java b/webmvc3-jetty/src/main/java/brave/example/Frontend.java
similarity index 97%
rename from webmvc3-jetty/src/main/java/brave/webmvc/Frontend.java
rename to webmvc3-jetty/src/main/java/brave/example/Frontend.java
index 3f5a908..d11c17b 100644
--- a/webmvc3-jetty/src/main/java/brave/webmvc/Frontend.java
+++ b/webmvc3-jetty/src/main/java/brave/example/Frontend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
diff --git a/webmvc4-jetty/src/main/java/brave/servlet/HealthServlet.java b/webmvc3-jetty/src/main/java/brave/example/HealthServlet.java
similarity index 96%
rename from webmvc4-jetty/src/main/java/brave/servlet/HealthServlet.java
rename to webmvc3-jetty/src/main/java/brave/example/HealthServlet.java
index 81d1542..a084ad3 100644
--- a/webmvc4-jetty/src/main/java/brave/servlet/HealthServlet.java
+++ b/webmvc3-jetty/src/main/java/brave/example/HealthServlet.java
@@ -1,4 +1,4 @@
-package brave.servlet;
+package brave.example;
import java.io.IOException;
import java.io.PrintWriter;
diff --git a/webmvc3-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml b/webmvc3-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml
index 8c36cf3..c0224f3 100644
--- a/webmvc3-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml
+++ b/webmvc3-jetty/src/main/webapp/WEB-INF/spring-webmvc-servlet.xml
@@ -28,11 +28,11 @@
-
+
-
+
diff --git a/webmvc4-boot/README.md b/webmvc4-boot/README.md
index bd550b9..c99376b 100644
--- a/webmvc4-boot/README.md
+++ b/webmvc4-boot/README.md
@@ -3,8 +3,8 @@
Instead of servlet, this uses Spring Boot 1.5 to create a self-contained
application that runs Spring WebMVC 4 controllers.
-* brave.webmvc.Frontend and Backend : Rest controllers with no tracing configuration
-* brave.webmvc.TracingConfiguration : This adds tracing by configuring the tracer, server and client tracing interceptors.
+* brave.example.Frontend and Backend : Rest controllers with no tracing configuration
+* brave.example.TracingConfiguration : This adds tracing by configuring the tracer, server and client tracing interceptors.
`TracingConfiguration` is automatically loaded due to `META-INF/spring.factories`
This allows the `Frontend` and `Backend` controllers to have no tracing
diff --git a/webmvc4-boot/pom.xml b/webmvc4-boot/pom.xml
index dbdd298..30f213f 100644
--- a/webmvc4-boot/pom.xml
+++ b/webmvc4-boot/pom.xml
@@ -2,22 +2,23 @@
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">
4.0.0
+
+ io.zipkin.brave.example
+ brave-example-parent
+ 1.0-SNAPSHOT
+ ../parent-pom.xml
+
- io.zipkin.brave.example
brave-example-webmvc4-boot
- 1.0-SNAPSHOT
jar
brave-example-webmvc4-boot
- Tracing Example: Spring WebMVC 4/Spring Boot 1.5
+ Tracing Example: Spring WebMVC 4/Spring Boot 1.5/JRE 8
- UTF-8
- 1.8
- 1.8
+ 8
1.5.22.RELEASE
- 5.12.6
@@ -29,13 +30,6 @@
pom
import
-
- io.zipkin.brave
- brave-bom
- ${brave.version}
- pom
- import
-
@@ -117,17 +111,6 @@
-
- maven-compiler-plugin
- 3.8.1
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 3.0.0
-
-
org.springframework.boot
spring-boot-maven-plugin
@@ -140,33 +123,12 @@
-
- brave.webmvc.Backend
+
+ brave.example.Backend
exec
true
-
-
- maven-enforcer-plugin
- 3.0.0-M3
-
-
- enforce-java
-
- enforce
-
-
-
-
-
- [1.8,)
-
-
-
-
-
-
diff --git a/webmvc4-boot/src/main/java/brave/webmvc/Backend.java b/webmvc4-boot/src/main/java/brave/example/Backend.java
similarity index 97%
rename from webmvc4-boot/src/main/java/brave/webmvc/Backend.java
rename to webmvc4-boot/src/main/java/brave/example/Backend.java
index 655362a..fb0d7b0 100644
--- a/webmvc4-boot/src/main/java/brave/webmvc/Backend.java
+++ b/webmvc4-boot/src/main/java/brave/example/Backend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import java.util.Date;
import org.springframework.boot.SpringApplication;
diff --git a/webmvc4-boot/src/main/java/brave/webmvc/Frontend.java b/webmvc4-boot/src/main/java/brave/example/Frontend.java
similarity index 98%
rename from webmvc4-boot/src/main/java/brave/webmvc/Frontend.java
rename to webmvc4-boot/src/main/java/brave/example/Frontend.java
index ccaf2d8..d09bce1 100644
--- a/webmvc4-boot/src/main/java/brave/webmvc/Frontend.java
+++ b/webmvc4-boot/src/main/java/brave/example/Frontend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
diff --git a/webmvc4-boot/src/main/java/brave/webmvc/TracingConfiguration.java b/webmvc4-boot/src/main/java/brave/example/TracingConfiguration.java
similarity index 99%
rename from webmvc4-boot/src/main/java/brave/webmvc/TracingConfiguration.java
rename to webmvc4-boot/src/main/java/brave/example/TracingConfiguration.java
index 20bcaf9..5da804d 100644
--- a/webmvc4-boot/src/main/java/brave/webmvc/TracingConfiguration.java
+++ b/webmvc4-boot/src/main/java/brave/example/TracingConfiguration.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import brave.CurrentSpanCustomizer;
import brave.SpanCustomizer;
diff --git a/webmvc4-boot/src/main/resources/META-INF/spring.factories b/webmvc4-boot/src/main/resources/META-INF/spring.factories
index 248137f..aa7bb3a 100644
--- a/webmvc4-boot/src/main/resources/META-INF/spring.factories
+++ b/webmvc4-boot/src/main/resources/META-INF/spring.factories
@@ -1,2 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-brave.webmvc.TracingConfiguration
+brave.example.TracingConfiguration
diff --git a/webmvc4-jetty/README.md b/webmvc4-jetty/README.md
index b792e72..be2b1e2 100644
--- a/webmvc4-jetty/README.md
+++ b/webmvc4-jetty/README.md
@@ -8,7 +8,7 @@ Instead of a web.xml file, this uses a Servlet 3.1
`Initializer` is indirectly invoked by `SpringServletContainerInitializer`,
which is in the classpath. This sets up the following:
-* brave.webmvc.Frontend and Backend : Rest controllers with no tracing configuration
-* brave.webmvc.TracingConfiguration : This adds tracing by configuring the tracer, server and client tracing interceptors.
+* brave.example.Frontend and Backend : Rest controllers with no tracing configuration
+* brave.example.TracingConfiguration : This adds tracing by configuring the tracer, server and client tracing interceptors.
diff --git a/webmvc4-jetty/pom.xml b/webmvc4-jetty/pom.xml
index 106c97e..7d0989b 100755
--- a/webmvc4-jetty/pom.xml
+++ b/webmvc4-jetty/pom.xml
@@ -2,41 +2,31 @@
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">
4.0.0
+
+ io.zipkin.brave.example
+ brave-example-parent
+ 1.0-SNAPSHOT
+ ../parent-pom.xml
+
- io.zipkin.brave.example
brave-example-webmvc4-jetty
- 1.0-SNAPSHOT
war
brave-example-webmvc4-jetty
- Tracing Example: Spring WebMVC 4/Servlet 3.1/Jetty 9
+ Tracing Example: Spring WebMVC 4/Servlet 3.1/Jetty 9/JRE 8
- UTF-8
- 1.7
- 1.7
+ 8
+ 7
4.3.28.RELEASE
1.7.30
- 5.12.6
org.eclipse.jetty
9.2.29.v20191105
-
-
-
- io.zipkin.brave
- brave-bom
- ${brave.version}
- pom
- import
-
-
-
-
javax.servlet
@@ -114,40 +104,8 @@
-
- maven-compiler-plugin
- 3.8.1
-
-
-
- maven-enforcer-plugin
- 3.0.0-M3
-
-
- enforce-java
-
- enforce
-
-
-
-
-
- [1.7.0_80,12)
-
-
-
-
-
-
-
maven-war-plugin
- 3.2.3
-
- false
- WEB-INF/lib/servlet-api-*.jar
-
diff --git a/webmvc4-jetty/src/main/java/brave/webmvc/AppConfiguration.java b/webmvc4-jetty/src/main/java/brave/example/AppConfiguration.java
similarity index 97%
rename from webmvc4-jetty/src/main/java/brave/webmvc/AppConfiguration.java
rename to webmvc4-jetty/src/main/java/brave/example/AppConfiguration.java
index a69d961..af83dab 100644
--- a/webmvc4-jetty/src/main/java/brave/webmvc/AppConfiguration.java
+++ b/webmvc4-jetty/src/main/java/brave/example/AppConfiguration.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/webmvc4-jetty/src/main/java/brave/webmvc/Backend.java b/webmvc4-jetty/src/main/java/brave/example/Backend.java
similarity index 96%
rename from webmvc4-jetty/src/main/java/brave/webmvc/Backend.java
rename to webmvc4-jetty/src/main/java/brave/example/Backend.java
index d8ef65e..13c56df 100644
--- a/webmvc4-jetty/src/main/java/brave/webmvc/Backend.java
+++ b/webmvc4-jetty/src/main/java/brave/example/Backend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestHeader;
diff --git a/webmvc4-jetty/src/main/java/brave/webmvc/Frontend.java b/webmvc4-jetty/src/main/java/brave/example/Frontend.java
similarity index 97%
rename from webmvc4-jetty/src/main/java/brave/webmvc/Frontend.java
rename to webmvc4-jetty/src/main/java/brave/example/Frontend.java
index c83fd0b..a9c1c30 100644
--- a/webmvc4-jetty/src/main/java/brave/webmvc/Frontend.java
+++ b/webmvc4-jetty/src/main/java/brave/example/Frontend.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
diff --git a/webmvc3-jetty/src/main/java/brave/servlet/HealthServlet.java b/webmvc4-jetty/src/main/java/brave/example/HealthServlet.java
similarity index 96%
rename from webmvc3-jetty/src/main/java/brave/servlet/HealthServlet.java
rename to webmvc4-jetty/src/main/java/brave/example/HealthServlet.java
index 81d1542..a084ad3 100644
--- a/webmvc3-jetty/src/main/java/brave/servlet/HealthServlet.java
+++ b/webmvc4-jetty/src/main/java/brave/example/HealthServlet.java
@@ -1,4 +1,4 @@
-package brave.servlet;
+package brave.example;
import java.io.IOException;
import java.io.PrintWriter;
diff --git a/webmvc4-jetty/src/main/java/brave/webmvc/Initializer.java b/webmvc4-jetty/src/main/java/brave/example/Initializer.java
similarity index 97%
rename from webmvc4-jetty/src/main/java/brave/webmvc/Initializer.java
rename to webmvc4-jetty/src/main/java/brave/example/Initializer.java
index ff55108..f20ff13 100644
--- a/webmvc4-jetty/src/main/java/brave/webmvc/Initializer.java
+++ b/webmvc4-jetty/src/main/java/brave/example/Initializer.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import brave.spring.webmvc.DelegatingTracingFilter;
import javax.servlet.Filter;
diff --git a/webmvc4-jetty/src/main/java/brave/webmvc/TracingConfiguration.java b/webmvc4-jetty/src/main/java/brave/example/TracingConfiguration.java
similarity index 62%
rename from webmvc4-jetty/src/main/java/brave/webmvc/TracingConfiguration.java
rename to webmvc4-jetty/src/main/java/brave/example/TracingConfiguration.java
index 808a176..ed445ce 100644
--- a/webmvc4-jetty/src/main/java/brave/webmvc/TracingConfiguration.java
+++ b/webmvc4-jetty/src/main/java/brave/example/TracingConfiguration.java
@@ -1,4 +1,4 @@
-package brave.webmvc;
+package brave.example;
import brave.CurrentSpanCustomizer;
import brave.SpanCustomizer;
@@ -11,18 +11,21 @@
import brave.http.HttpTracing;
import brave.okhttp3.TracingInterceptor;
import brave.propagation.B3Propagation;
+import brave.propagation.CurrentTraceContext;
import brave.propagation.CurrentTraceContext.ScopeDecorator;
import brave.propagation.Propagation;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.spring.webmvc.DelegatingTracingFilter;
import brave.spring.webmvc.SpanCustomizingAsyncHandlerInterceptor;
+import okhttp3.Call;
import okhttp3.OkHttpClient;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
+import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import zipkin2.reporter.Sender;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
@@ -38,7 +41,7 @@
@Configuration
// Importing this class is effectively the same as declaring bean methods
@Import(SpanCustomizingAsyncHandlerInterceptor.class)
-public class TracingConfiguration extends WebMvcConfigurerAdapter {
+public class TracingConfiguration {
static final BaggageField USER_NAME = BaggageField.create("userName");
/** Allows log patterns to use {@code %{traceId}} {@code %{spanId}} and {@code %{userName}} */
@@ -47,6 +50,13 @@ public class TracingConfiguration extends WebMvcConfigurerAdapter {
.add(SingleCorrelationField.create(USER_NAME)).build();
}
+ /** Propagates trace context between threads. */
+ @Bean CurrentTraceContext currentTraceContext(ScopeDecorator correlationScopeDecorator) {
+ return ThreadLocalCurrentTraceContext.newBuilder()
+ .addScopeDecorator(correlationScopeDecorator)
+ .build();
+ }
+
/** Configures propagation for {@link #USER_NAME}, using the remote header "user_name" */
@Bean Propagation.Factory propagationFactory() {
return BaggagePropagation.newFactoryBuilder(B3Propagation.FACTORY)
@@ -55,25 +65,29 @@ public class TracingConfiguration extends WebMvcConfigurerAdapter {
}
/** Configuration for how to send spans to Zipkin */
- @Bean Sender sender() {
- return OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
+ @Bean Sender sender(
+ @Value("${zipkin.endpoint:http://127.0.0.1:9411/api/v2/spans}") String zipkinEndpoint) {
+ return OkHttpSender.create(zipkinEndpoint);
}
/** Configuration for how to buffer spans into messages for Zipkin */
- @Bean AsyncZipkinSpanHandler zipkinSpanHandler() {
- return AsyncZipkinSpanHandler.create(sender());
+ @Bean AsyncZipkinSpanHandler zipkinSpanHandler(Sender sender) {
+ return AsyncZipkinSpanHandler.create(sender);
}
/** Controls aspects of tracing such as the service name that shows up in the UI */
- @Bean Tracing tracing(@Value("${zipkin.service:brave-webmvc-example}") String serviceName) {
+ @Bean Tracing tracing(
+ @Value("${zipkin.service:${spring.application.name}}") String serviceName,
+ @Value("${zipkin.supportsJoin:true}") boolean supportsJoin,
+ Propagation.Factory propagationFactory,
+ CurrentTraceContext currentTraceContext,
+ AsyncZipkinSpanHandler zipkinSpanHandler) {
return Tracing.newBuilder()
.localServiceName(serviceName)
- .propagationFactory(propagationFactory())
- .currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
- .addScopeDecorator(correlationScopeDecorator())
- .build()
- )
- .addSpanHandler(zipkinSpanHandler()).build();
+ .supportsJoin(supportsJoin)
+ .propagationFactory(propagationFactory)
+ .currentTraceContext(currentTraceContext)
+ .addSpanHandler(zipkinSpanHandler).build();
}
/** Allows someone to add tags to a span if a trace is in progress. */
@@ -86,17 +100,23 @@ public class TracingConfiguration extends WebMvcConfigurerAdapter {
return HttpTracing.create(tracing);
}
- /** Adds tracing to any underlying HTTP client calls */
- @Bean OkHttpClient httpClient(HttpTracing httpTracing) {
+ /**
+ * Trace {@link OkHttpClient} because {@link OkHttp3ClientHttpRequestFactory} doesn't take a
+ * {@link Call.Factory}
+ */
+ @Bean OkHttpClient tracedOkHttpClient(HttpTracing httpTracing) {
return new OkHttpClient.Builder()
.addNetworkInterceptor(TracingInterceptor.create(httpTracing))
.build();
}
- @Autowired SpanCustomizingAsyncHandlerInterceptor serverInterceptor;
-
- /** Adds application-defined web controller details to HTTP server spans */
- @Override public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(serverInterceptor);
+ @Bean WebMvcConfigurer tracingWebMvcConfigurer(
+ final SpanCustomizingAsyncHandlerInterceptor webMvcTracingCustomizer) {
+ return new WebMvcConfigurerAdapter() {
+ /** Adds application-defined web controller details to HTTP server spans */
+ @Override public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(webMvcTracingCustomizer);
+ }
+ };
}
}