Skip to content

Commit 4fde831

Browse files
committed
Add OpenTelemetry exporter
Signed-off-by: Fabian Stäber <[email protected]>
1 parent c208b81 commit 4fde831

File tree

80 files changed

+4858
-1376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4858
-1376
lines changed

.circleci/config.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ machine: true
33
jobs:
44
build:
55
machine:
6-
image: ubuntu-2204:2023.04.2
6+
image: ubuntu-2204:2023.07.2
77
working_directory: ~/circleci-java
88
steps:
99
- run:
10-
name: Install OpenJDK 11
10+
name: Install OpenJDK 17
1111
command: |
12-
sudo apt-get update && sudo apt-get install openjdk-11-jdk
13-
sudo update-alternatives --set java /usr/lib/jvm/java-11-openjdk-amd64/bin/java
14-
sudo update-alternatives --set javac /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
12+
sudo apt-get update && sudo apt-get install -y openjdk-17-jdk
13+
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
14+
sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
1515
java -version
1616
- checkout
1717
- restore_cache:
1818
key: maven-dependencies-{{ checksum "pom.xml" }}
19-
# - run: cd protobuf-shaded && ../mvnw install && cd ..
19+
- run: cd prometheus-metrics-shaded-dependencies && ../mvnw clean install && cd ..
2020
- run: ./mvnw clean install
2121
- run: ./mvnw javadoc:jar
2222
- save_cache:

examples/example-exemplars-tail-sampling/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The example is built as part of the `client_java` parent project with
6060
./mvnw package
6161
```
6262

63-
This should generate two Java services `.../example-greeting-service/target/example-greeting-service-[version].jar` and `.../example-hello-world-app/target/example-hello-world-app-[version].jar`.
63+
This should generate two Java services `.../example-greeting-service/target/example-greeting-service.jar` and `.../example-hello-world-app/target/example-hello-world-app.jar`.
6464

6565
## Run the Example
6666

examples/example-exemplars-tail-sampling/docker-compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
ports:
1313
- "8080:8080"
1414
volumes:
15-
- ./example-hello-world-app/target/example-hello-world-app-1.0.0-alpha-2-SNAPSHOT.jar:/hello-world-app.jar
15+
- ./example-hello-world-app/target/example-hello-world-app.jar:/example-hello-world-app.jar
1616
environment:
1717
- OTEL_TRACES_EXPORTER=otlp
1818
- OTEL_METRICS_EXPORTER=none
@@ -21,15 +21,15 @@ services:
2121
- java
2222
- -javaagent:/opentelemetry-javaagent.jar
2323
- -jar
24-
- /hello-world-app.jar
24+
- /example-hello-world-app.jar
2525
greeting-service:
2626
# The opentelemetry-java-agent image is coming from the hello-world-up service above.
2727
image: opentelemetry-java-agent
2828
network_mode: host
2929
ports:
3030
- "8081:8081"
3131
volumes:
32-
- ./example-greeting-service/target/example-greeting-service-1.0.0-alpha-2-SNAPSHOT.jar:/greeting-service.jar
32+
- ./example-greeting-service/target/example-greeting-service.jar:/example-greeting-service.jar
3333
environment:
3434
- OTEL_TRACES_EXPORTER=otlp
3535
- OTEL_METRICS_EXPORTER=none
@@ -38,7 +38,7 @@ services:
3838
- java
3939
- -javaagent:/opentelemetry-javaagent.jar
4040
- -jar
41-
- /greeting-service.jar
41+
- /example-greeting-service.jar
4242
collector:
4343
image: otel/opentelemetry-collector-contrib:0.79.0
4444
network_mode: host

examples/example-exemplars-tail-sampling/example-greeting-service/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
</dependencies>
5151

5252
<build>
53+
<finalName>${project.artifactId}</finalName>
5354
<plugins>
5455
<plugin>
5556
<groupId>org.apache.maven.plugins</groupId>

examples/example-exemplars-tail-sampling/example-hello-world-app/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
</dependencies>
5151

5252
<build>
53+
<finalName>${project.artifactId}</finalName>
5354
<plugins>
5455
<plugin>
5556
<groupId>org.apache.maven.plugins</groupId>

examples/example-httpserver/README.md renamed to examples/example-exporter-httpserver/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ This example is built as part of the `client_java` project.
1010

1111
## Run
1212

13-
The build creates a JAR file with the example application in `./examples/example-httpserver/target/`.
13+
The build creates a JAR file with the example application in `./examples/example-exporter-httpserver/target/`.
1414

1515
```
16-
java -jar ./examples/example-httpserver/target/example-tomcat-servlet-1.0.0-alpha-3-SNAPSHOT.jar
16+
java -jar ./examples/example-exporter-httpserver/target/example-exporter-httpserver.jar
1717
```
1818

1919
## Manually testing the Metrics Endpoint
@@ -31,7 +31,3 @@ The exporter supports a `debug` URL parameter to quickly view other formats in y
3131
* [http://localhost:9400/metrics?debug=text](http://localhost:9400/metrics?debug=text): Prometheus text format, same as without the `debug` option.
3232
* [http://localhost:9400/metrics?debug=openmetrics](http://localhost:9400/metrics?debug=openmetrics): OpenMetrics text format.
3333
* [http://localhost:9400/metrics?debug=prometheus-protobuf](http://localhost:9400/metrics?debug=prometheus-protobuf): Text representation of the Prometheus protobuf format.
34-
35-
## TODO
36-
37-
Implement an example of a histogram and show how to use this with Prometheus, see [../example-tomcat-servlet](../example-tomcat-servlet).

examples/example-httpserver/pom.xml renamed to examples/example-exporter-httpserver/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<version>1.0.0-alpha-3-SNAPSHOT</version>
99
</parent>
1010

11-
<artifactId>example-httpserver</artifactId>
11+
<artifactId>example-exporter-httpserver</artifactId>
1212

13-
<name>Example - HTTPServer</name>
13+
<name>>Example - HTTPServer Exporter</name>
1414
<description>
1515
Prometheus Metrics Example using the HTTPServer for exposing the metrics endpoint
1616
</description>
@@ -45,6 +45,7 @@
4545
</dependencies>
4646

4747
<build>
48+
<finalName>${project.artifactId}</finalName>
4849
<plugins>
4950
<plugin>
5051
<groupId>org.apache.maven.plugins</groupId>

examples/example-httpserver/src/main/java/io/prometheus/metrics/examples/httpserver/Main.java renamed to examples/example-exporter-httpserver/src/main/java/io/prometheus/metrics/examples/httpserver/Main.java

File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# OpenTelemetry Exporter Example
2+
3+
## Build
4+
5+
This example is built as part of the `client_java` project.
6+
7+
```
8+
./mvnw package
9+
```
10+
11+
## Run
12+
13+
Assuming `./examples/example-exporter-opentelemetry/target/example-exporter-opentelemetry.jar` is present, run the demo with:
14+
15+
```bash
16+
cd ./examples/example-exporter-opentelemetry/
17+
docker-compose up
18+
```
19+
20+
This will set up the following scenario:
21+
22+
```mermaid
23+
flowchart LR
24+
A[example app] -->|OTLP|B[OpenTelemetry collector] -->|Prometheus remote write|C[Prometheus server]
25+
```
26+
27+
The OpenTelemetry collector is configured to log incoming metrics to the console.
28+
The Prometheus server is running on [http://localhost:9090](http://localhost:9090).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
http:
6+
7+
processors:
8+
batch:
9+
10+
exporters:
11+
prometheusremotewrite:
12+
endpoint: http://localhost:9090/api/v1/write
13+
logging:
14+
verbosity: detailed
15+
16+
service:
17+
pipelines:
18+
metrics:
19+
receivers: [otlp]
20+
processors: [batch]
21+
exporters: [logging, prometheusremotewrite]

0 commit comments

Comments
 (0)