Skip to content

Commit e9b80b1

Browse files
authored
chore: add otel-profiling-java example (#2872)
1 parent 9e88e1f commit e9b80b1

File tree

4 files changed

+83
-10
lines changed

4 files changed

+83
-10
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM --platform=$BUILDPLATFORM openjdk:17-slim-bullseye as builder
2+
3+
WORKDIR /opt/app
4+
5+
RUN apt-get update && apt-get install ca-certificates -y && update-ca-certificates
6+
7+
8+
9+
COPY gradlew .
10+
COPY gradle gradle
11+
RUN ./gradlew
12+
13+
COPY build.gradle.kts settings.gradle.kts ./
14+
RUN ./gradlew dependencies --no-daemon
15+
16+
COPY src src
17+
RUN ./gradlew assemble --no-daemon
18+
19+
20+
FROM openjdk:17-slim-bullseye
21+
22+
RUN apt-get update && apt-get install ca-certificates -y && update-ca-certificates
23+
24+
ENV PYROSCOPE_APPLICATION_NAME=rideshare.java.push.app
25+
ENV PYROSCOPE_FORMAT=jfr
26+
ENV PYROSCOPE_PROFILING_INTERVAL=10ms
27+
ENV PYROSCOPE_PROFILER_EVENT=itimer
28+
ENV PYROSCOPE_PROFILER_LOCK=10ms
29+
ENV PYROSCOPE_PROFILER_ALLOC=512k
30+
ENV PYROSCOPE_UPLOAD_INTERVAL=15s
31+
ENV PYROSCOPE_LOG_LEVEL=debug
32+
ENV PYROSCOPE_SERVER_ADDRESS=http://localhost:4040
33+
34+
ENV OTEL_JAVAAGENT_EXTENSIONS=./pyroscope-otel.jar
35+
36+
ENV OTEL_PYROSCOPE_ADD_PROFILE_URL=false
37+
ENV OTEL_PYROSCOPE_ADD_PROFILE_BASELINE_URL=false
38+
ENV OTEL_PYROSCOPE_START_PROFILING=true
39+
40+
COPY --from=builder /opt/app/build/libs/rideshare-1.0-SNAPSHOT.jar /opt/app/build/libs/rideshare-1.0-SNAPSHOT.jar
41+
42+
WORKDIR /opt/app
43+
44+
ADD https://github.com/grafana/pyroscope-java/releases/download/v0.12.2/pyroscope.jar /opt/app/pyroscope.jar
45+
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.17.0/opentelemetry-javaagent.jar opentelemetry-javaagent.jar
46+
ADD https://repo1.maven.org/maven2/io/pyroscope/otel/0.10.1.3/otel-0.10.1.3.jar pyroscope-otel.jar
47+
48+
EXPOSE 5000
49+
50+
CMD ["java", "-Dserver.port=5000", "-javaagent:./opentelemetry-javaagent.jar", "-javaagent:pyroscope.jar", "-jar", "./build/libs/rideshare-1.0-SNAPSHOT.jar" ]

examples/java/rideshare/src/main/java/org/example/rideshare/Main.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
@SpringBootApplication
1010
public class Main {
1111
public static void main(String[] args) {
12-
Pyroscope.setStaticLabels(Map.of("region", System.getenv("REGION")));
12+
Pyroscope.setStaticLabels(Map.of(
13+
"region", System.getenv("REGION"),
14+
"hostname", System.getenv("HOSTNAME")));
1315
SpringApplication.run(Main.class, args);
1416
}
1517
}

examples/tracing/tempo/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Pyroscope and Tempo datasources are provisioned automatically.
1414
The project can be run locally with the following commands:
1515

1616
```shell
17+
GOOS=linux GOARCH=amd64 make build -C ../../..
1718
docker-compose up --build
1819
```
1920

@@ -30,7 +31,9 @@ less than the sample interval (10ms).
3031

3132
### Instrumentation
3233

33-
- `rideshare` demo application instrumented with OpenTelemetry and [Pyroscope SDK](https://github.com/grafana/otel-profiling-go)
34+
- `rideshare` demo application instrumented with OpenTelemetry:
35+
- Go [OTel integration](https://github.com/grafana/otel-profiling-go)
36+
- Java [OTel integration](https://github.com/grafana/otel-profiling-java)
3437
- `pyroscope` itself is instrumented with `opentracing-go` SDK and [`spanprofiler`](../../../pkg/util/spanprofiler) for profiling integration.
3538

3639
### Grafana Tempo configuration

examples/tracing/tempo/docker-compose.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,60 @@
11
version: "3"
22

33
services:
4-
us-east:
4+
rideshare-go-ap-south:
55
ports:
66
- 5000
7+
hostname: rideshare-go-ap-south
78
environment: &env
89
PYROSCOPE_SERVER_ADDRESS: http://pyroscope:4040
910
OTLP_URL: tempo:4318
1011
OTLP_INSECURE: 1
1112
DEBUG_LOGGER: 1
12-
REGION: us-east
13+
REGION: ap-south
1314
build:
1415
context: ../../golang-push/rideshare
1516

16-
eu-north:
17+
rideshare-go-eu-north:
1718
ports:
1819
- 5000
20+
hostname: rideshare-go-eu-north
1921
environment:
2022
<<: *env
2123
REGION: eu-north
2224
build:
2325
context: ../../golang-push/rideshare
2426

25-
ap-south:
27+
rideshare-java-us-east:
2628
ports:
2729
- 5000
30+
hostname: rideshare-java-us-east
2831
environment:
2932
<<: *env
30-
REGION: ap-south
33+
OTEL_TRACES_EXPORTER: otlp
34+
OTEL_EXPORTER_OTLP_ENDPOINT: http://tempo:4317
35+
OTEL_SERVICE_NAME: rideshare.java.push.app
36+
OTEL_METRICS_EXPORTER: none
37+
OTEL_TRACES_SAMPLER: always_on
38+
OTEL_PROPAGATORS: tracecontext
39+
PYROSCOPE_LABELS: hostname=rideshare-java-us-east
40+
REGION: us-east
3141
build:
32-
context: ../../golang-push/rideshare
42+
context: ../../java/rideshare
43+
dockerfile: Dockerfile.otel-instrumentation
3344

3445
load-generator:
3546
environment: *env
3647
build:
3748
context: ../../golang-push/rideshare
3849
dockerfile: Dockerfile.load-generator
50+
command:
51+
- ./loadgen
52+
- rideshare-go-ap-south
53+
- rideshare-go-eu-north
54+
- rideshare-java-us-east
3955

4056
grafana:
41-
image: grafana/grafana-dev:10.3.0-149048
57+
image: grafana/grafana-dev:10.3.0-151740
4258
environment:
4359
- GF_AUTH_ANONYMOUS_ENABLED=true
4460
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
@@ -64,7 +80,6 @@ services:
6480
- "9411:9411" # zipkin
6581

6682
pyroscope:
67-
image: grafana/pyroscope:1.2.0
6883
environment:
6984
JAEGER_AGENT_HOST: tempo
7085
JAEGER_SAMPLER_TYPE: const
@@ -74,3 +89,6 @@ services:
7489
- '4040:4040'
7590
volumes:
7691
- ./pyroscope/pyroscope.yml:/etc/pyroscope.yml
92+
build:
93+
context: '../../../'
94+
dockerfile: cmd/pyroscope/Dockerfile

0 commit comments

Comments
 (0)