Skip to content

Commit 078ab1b

Browse files
authored
chore(examples): update java examples (#4091)
1 parent 21e6e66 commit 078ab1b

File tree

16 files changed

+98
-36
lines changed

16 files changed

+98
-36
lines changed

‎docs/sources/configure-client/language-sdks/java.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ First, add the Pyroscope dependency:
5151
<dependency>
5252
<groupId>io.pyroscope</groupId>
5353
<artifactId>agent</artifactId>
54-
<version>0.18.1</version>
54+
<version>2.0.0</version>
5555
</dependency>
5656
```
5757

5858
```gradle
59-
implementation("io.pyroscope:agent:0.18.1")
59+
implementation("io.pyroscope:agent:2.0.0")
6060
```
6161

6262
{{< /code >}}

‎docs/sources/configure-client/trace-span-profiles/java-span-profiles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ EXPOSE 5000
6262

6363
## Add required libararies
6464
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.17.0/opentelemetry-javaagent.jar opentelemetry-javaagent.jar
65-
ADD https://repo1.maven.org/maven2/io/pyroscope/otel/0.11.0/otel-0.11.0.jar pyroscope-otel.jar
65+
ADD https://github.com/grafana/otel-profiling-java/releases/download/v1.0.1/pyroscope-otel.jar pyroscope-otel.jar
6666

6767
ENV PYROSCOPE_APPLICATION_NAME=my-app
6868
ENV PYROSCOPE_FORMAT=jfr

‎examples/language-sdk-instrumentation/java/fib/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /opt/app
44

55
RUN apt-get update && apt-get install ca-certificates -y && update-ca-certificates && apt-get install -y git
66

7-
ADD https://github.com/grafana/pyroscope-java/releases/download/v0.18.1/pyroscope.jar /opt/app/pyroscope.jar
7+
ADD https://github.com/grafana/pyroscope-java/releases/download/v2.0.0/pyroscope.jar /opt/app/pyroscope.jar
88

99
COPY Main.java ./
1010

‎examples/language-sdk-instrumentation/java/rideshare/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ COPY --from=builder /opt/app/build/libs/rideshare-1.0-SNAPSHOT.jar /opt/app/buil
3737

3838
WORKDIR /opt/app
3939

40-
ADD https://github.com/grafana/pyroscope-java/releases/download/v0.18.1/pyroscope.jar /opt/app/pyroscope.jar
40+
ADD https://github.com/grafana/pyroscope-java/releases/download/v2.0.0/pyroscope.jar /opt/app/pyroscope.jar
4141

4242
CMD sh -c "exec java -Dserver.port=${RIDESHARE_LISTEN_PORT} -javaagent:pyroscope.jar -jar ./build/libs/rideshare-1.0-SNAPSHOT.jar"

‎examples/language-sdk-instrumentation/java/rideshare/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ repositories {
1212
}
1313

1414
dependencies {
15-
implementation("io.pyroscope:agent:0.18.1")
15+
implementation("io.pyroscope:agent:2.0.0")
16+
implementation("org.jetbrains:annotations:26.0.2")
1617
implementation("org.springframework.boot:spring-boot-starter-web")
1718
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
1819
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.example.rideshare;
22

3-
import io.pyroscope.labels.Pyroscope;
3+
import io.pyroscope.javaagent.PyroscopeAgent;
4+
import io.pyroscope.javaagent.config.Config;
5+
import io.pyroscope.javaagent.impl.DefaultConfigurationProvider;
6+
import io.pyroscope.labels.v2.Pyroscope;
7+
import org.jetbrains.annotations.NotNull;
48
import org.springframework.boot.SpringApplication;
59
import org.springframework.boot.autoconfigure.SpringBootApplication;
610

@@ -10,8 +14,21 @@
1014
public class Main {
1115
public static void main(String[] args) {
1216
Pyroscope.setStaticLabels(Map.of(
13-
"region", System.getenv("REGION"),
14-
"hostname", System.getenv("HOSTNAME")));
17+
"region", env("REGION", "us-east-1"),
18+
"hostname", env("HOSTNAME", "localhost")));
19+
if (!PyroscopeAgent.isStarted()) {
20+
// If we have not started the sdk with -javaagent (for example running from an IDE)
21+
// allow starting the sdk here for convenience
22+
PyroscopeAgent.start(Config.build(DefaultConfigurationProvider.INSTANCE));
23+
}
1524
SpringApplication.run(Main.class, args);
1625
}
26+
27+
public static @NotNull String env(@NotNull String key, @NotNull String fallback) {
28+
final String env = System.getenv(key);
29+
if (env == null) {
30+
return fallback;
31+
}
32+
return env;
33+
}
1734
}

‎examples/language-sdk-instrumentation/java/rideshare/src/main/java/org/example/rideshare/OrderService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.example.rideshare;
22

3-
import io.pyroscope.labels.LabelsSet;
4-
import io.pyroscope.labels.Pyroscope;
3+
import io.pyroscope.labels.v2.LabelsSet;
4+
import io.pyroscope.labels.v2.Pyroscope;
55
import org.springframework.stereotype.Service;
66

77
import java.time.Duration;

‎examples/language-sdk-instrumentation/java/simple/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM openjdk:11.0.11-jdk
22

33
WORKDIR /opt/app
44

5-
ADD https://github.com/grafana/pyroscope-java/releases/download/v0.18.1/pyroscope.jar /opt/app/pyroscope.jar
5+
ADD https://github.com/grafana/pyroscope-java/releases/download/v2.0.0/pyroscope.jar /opt/app/pyroscope.jar
66

77
COPY Main.java ./Main.java
88
RUN javac Main.java

‎examples/tracing/java/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ COPY --from=builder /opt/app/build/libs/rideshare-1.0-SNAPSHOT.jar /opt/app/buil
4242
WORKDIR /opt/app
4343

4444
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.17.0/opentelemetry-javaagent.jar opentelemetry-javaagent.jar
45-
ADD https://repo1.maven.org/maven2/io/pyroscope/agent/0.16.0/agent-0.16.0.jar pyroscope.jar
46-
ADD https://repo1.maven.org/maven2/io/pyroscope/otel/0.11.0/otel-0.11.0.jar pyroscope-otel.jar
45+
ADD https://github.com/grafana/pyroscope-java/releases/download/v2.0.0/pyroscope.jar pyroscope.jar
46+
ADD https://github.com/grafana/otel-profiling-java/releases/download/v1.0.1/pyroscope-otel.jar pyroscope-otel.jar
4747

4848
EXPOSE 5000
4949

‎examples/tracing/java/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repositories {
1212
}
1313

1414
dependencies {
15-
implementation("io.pyroscope:agent:0.16.0")
15+
implementation("io.pyroscope:agent:2.0.0")
1616

1717
implementation("org.springframework.boot:spring-boot-starter-web")
1818
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")

‎examples/tracing/java/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
pyroscope:
3-
image: grafana/pyroscope
3+
image: korniltsev/pyroscope:update-java-examples-0d5533778 # remove after next release
44
ports:
55
- "4040:4040"
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.example.rideshare;
22

3-
import io.pyroscope.labels.Pyroscope;
3+
import io.pyroscope.labels.v2.Pyroscope;
44
import org.springframework.boot.SpringApplication;
55
import org.springframework.boot.autoconfigure.SpringBootApplication;
66

‎examples/tracing/java/src/main/java/org/example/rideshare/OrderService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.example.rideshare;
22

3-
import io.pyroscope.labels.LabelsSet;
4-
import io.pyroscope.labels.Pyroscope;
3+
import io.pyroscope.labels.v2.LabelsSet;
4+
import io.pyroscope.labels.v2.Pyroscope;
55
import org.springframework.stereotype.Service;
66

77
import java.time.Duration;

‎go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
github.com/gorilla/mux v1.8.0
3131
github.com/grafana/alloy/syntax v0.1.0
3232
github.com/grafana/dskit v0.0.0-20231221015914-de83901bf4d6
33-
github.com/grafana/jfr-parser/pprof v0.0.4
33+
github.com/grafana/jfr-parser/pprof v0.0.5-0.20250410080713-8cde6cbfa5bb
3434
github.com/grafana/pyroscope-go v1.2.0
3535
github.com/grafana/pyroscope-go/godeltaprof v0.1.8
3636
github.com/grafana/pyroscope-go/x/k6 v0.0.0-20241003203156-a917cea171d3
@@ -179,7 +179,7 @@ require (
179179
github.com/google/s2a-go v0.1.7 // indirect
180180
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
181181
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
182-
github.com/grafana/jfr-parser v0.9.3 // indirect
182+
github.com/grafana/jfr-parser v0.9.4-0.20250410080713-8cde6cbfa5bb // indirect
183183
github.com/hashicorp/consul/api v1.28.2 // indirect
184184
github.com/hashicorp/errwrap v1.1.0 // indirect
185185
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

‎go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ github.com/grafana/alloy/syntax v0.1.0 h1:+1xQakvQPH6N0y9+q2Fu5QePyzrve6i1wMNuXd
417417
github.com/grafana/alloy/syntax v0.1.0/go.mod h1:8H9ToCc1M8F6A+je4rIH6saIe1MUCmjSk+Uje+LNLEo=
418418
github.com/grafana/dskit v0.0.0-20231221015914-de83901bf4d6 h1:Z78JZ7pa6InQ5BcMB27M+NMTZ7LV+MXgOd3dZPfEdG4=
419419
github.com/grafana/dskit v0.0.0-20231221015914-de83901bf4d6/go.mod h1:kkWM4WUV230bNG3urVRWPBnSJHs64y/0RmWjftnnn0c=
420-
github.com/grafana/jfr-parser v0.9.3 h1:rMrDfV7U5Ycz12/d57sQrN7UHmt1N6Wi6SSuNKi8hyk=
421-
github.com/grafana/jfr-parser v0.9.3/go.mod h1:KYbwbvXtBoOsYw9b9w8R01dbM5oVfopljq3hA1WDJMQ=
422-
github.com/grafana/jfr-parser/pprof v0.0.4 h1:QIpA0tTgG17m/l2B6X0tqf8dZu+AN/UY6B3aYLfAFtY=
423-
github.com/grafana/jfr-parser/pprof v0.0.4/go.mod h1:7aJk80IjMxc2iaUlliRUgA+bq2ZFTgEQfZgjioL4cvg=
420+
github.com/grafana/jfr-parser v0.9.4-0.20250410080713-8cde6cbfa5bb h1:bXSZxJvyleHch1x8JTLP/0ogx9G+P+dfrXl6UFxq1bc=
421+
github.com/grafana/jfr-parser v0.9.4-0.20250410080713-8cde6cbfa5bb/go.mod h1:qZEYlzD7yp7DfhPWm2QFbskUgTK+mvYFBmS3ibuI2EY=
422+
github.com/grafana/jfr-parser/pprof v0.0.5-0.20250410080713-8cde6cbfa5bb h1:rjXrhQhCCxPgh1D/TO16lcQQsnljR78fupya/CY+n0w=
423+
github.com/grafana/jfr-parser/pprof v0.0.5-0.20250410080713-8cde6cbfa5bb/go.mod h1:7aJk80IjMxc2iaUlliRUgA+bq2ZFTgEQfZgjioL4cvg=
424424
github.com/grafana/memberlist v0.3.1-0.20220708130638-bd88e10a3d91 h1:/NipyHnOmvRsVzj81j2qE0VxsvsqhOB0f4vJIhk2qCQ=
425425
github.com/grafana/memberlist v0.3.1-0.20220708130638-bd88e10a3d91/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
426426
github.com/grafana/pyroscope-go v1.2.0 h1:aILLKjTj8CS8f/24OPMGPewQSYlhmdQMBmol1d3KGj8=

‎tools/update_examples.go

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"encoding/json"
6+
"flag"
67
"fmt"
78
"log"
89
"net/http"
@@ -16,24 +17,56 @@ import (
1617
)
1718

1819
var ghToken string
20+
var all = flag.Bool("all", true, "")
21+
var golang = flag.Bool("go", false, "")
22+
var java = flag.Bool("java", false, "")
23+
var ruby = flag.Bool("ruby", false, "")
24+
var python = flag.Bool("python", false, "")
25+
var dotnet = flag.Bool("dotnet", false, "")
26+
var node = flag.Bool("node", false, "")
27+
var rust = flag.Bool("rust", false, "")
1928

2029
// this program requires ruby, bundle, yarn, go to be installed
2130
func main() {
2231

2332
getGHToken()
33+
flag.Parse()
34+
if *all {
35+
*golang = true
36+
*java = true
37+
*ruby = true
38+
*python = true
39+
*dotnet = true
40+
*node = true
41+
*rust = true
42+
}
2443

25-
updateGolang()
26-
updateGodeltaprof()
27-
updateJfrParser()
28-
s.sh("make go/mod")
29-
30-
updateJava()
31-
updateRuby()
32-
updatePython()
33-
updateDotnet()
34-
updateNodeJS()
35-
updateRust()
44+
if *golang {
45+
updateGolang()
46+
updateGodeltaprof()
47+
updateJfrParser()
48+
s.sh("make go/mod")
49+
}
3650

51+
if *java {
52+
updateJava()
53+
updateOtelProfilingJava()
54+
}
55+
if *ruby {
56+
updateRuby()
57+
}
58+
if *python {
59+
updatePython()
60+
}
61+
if *dotnet {
62+
updateDotnet()
63+
}
64+
if *node {
65+
updateNodeJS()
66+
}
67+
if *rust {
68+
updateRust()
69+
}
3770
}
3871

3972
func getGHToken() {
@@ -144,11 +177,13 @@ func updateJava() {
144177
lastJarURL := "https://github.com/grafana/pyroscope-java/releases/download/" + last.versionV() + "/pyroscope.jar"
145178
replaceInplace(reJarURL, "examples/language-sdk-instrumentation/java/fib/Dockerfile", lastJarURL)
146179
replaceInplace(reJarURL, "examples/language-sdk-instrumentation/java/simple/Dockerfile", lastJarURL)
180+
replaceInplace(reJarURL, "examples/tracing/java/Dockerfile", lastJarURL)
147181
replaceInplace(reJarURL, "examples/language-sdk-instrumentation/java/rideshare/Dockerfile", lastJarURL)
148182

149183
reGradelDep := regexp.MustCompile(`implementation\("io\.pyroscope:agent:\d+\.\d+\.\d+"\)`)
150184
lastGradleDep := fmt.Sprintf("implementation(\"io.pyroscope:agent:%s\")", last.version())
151185
replaceInplace(reGradelDep, "examples/language-sdk-instrumentation/java/rideshare/build.gradle.kts", lastGradleDep)
186+
replaceInplace(reGradelDep, "examples/tracing/java/build.gradle.kts", lastGradleDep)
152187
replaceInplace(reGradelDep, "docs/sources/configure-client/language-sdks/java.md", lastGradleDep)
153188

154189
reMaven := regexp.MustCompile(`<version>\d+\.\d+\.\d+</version>`)
@@ -157,6 +192,15 @@ func updateJava() {
157192

158193
}
159194

195+
func updateOtelProfilingJava() {
196+
tags := getTagsV("grafana/otel-profiling-java", extractGoVersion(""))
197+
last := tags[len(tags)-1]
198+
reJarURL := regexp.MustCompile(`https://github\.com/grafana/otel-profiling-java/releases/download/(v\d+\.\d+\.\d+)/pyroscope-otel\.jar`)
199+
lastJarURL := "https://github.com/grafana/otel-profiling-java/releases/download/" + last.versionV() + "/pyroscope-otel.jar"
200+
replaceInplace(reJarURL, "docs/sources/configure-client/trace-span-profiles/java-span-profiles.md", lastJarURL)
201+
replaceInplace(reJarURL, "examples/tracing/java/Dockerfile", lastJarURL)
202+
}
203+
160204
func replaceInplace(re *regexp.Regexp, file string, replacement string) {
161205
bs, err := os.ReadFile(file)
162206
requireNoError(err, "read file "+file)

0 commit comments

Comments
 (0)