grafana / grafana/pyroscope-java

The Java Pyroscope agent does not use `pyroscope.application.name ` when profiling Gradle assemblies

Offen
#202 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
126
Forks
48
Ø Merge
4 T. 14 Std.
Gemergte PRs (30 T.)
5

Beschreibung

#### Problem description

When trying to profile a Gradle project build using the Java Pyroscope agent, the application name that is set in the `gradle.properties` file via the system property `-Dpyroscope.application.name `, is not recognized and is not applied. Instead of the custom name specified in the configuration, the automatically generated default name is displayed in the Pyroscope user interface.

#### Expected behavior:

It is expected that after the Gradle build is completed with the java agent configured, an application with the name `my-application` and the corresponding tags `{env=prod,version=1.0}`, as it was specified in `gradle.properties'.

#### Current (actual) behavior:

In the Pyroscope user interface, instead of the expected name `my-application`, an automatically generated name is displayed, in this case `javaspy.WeChRaEsRvWcEjq93mpGGg`. This indicates that the agent is running and sending data, but it cannot correctly determine or apply the application name from the JVM arguments passed to the Gradle daemon.

As you can see in the attached screenshot, there is no `my-application` in the list of applications.

#### Steps to reproduce

To reproduce the problem, follow these steps::

1. **Installing and configuring the Gradle environment:**
* Downloading the Gradle distribution:
```bash
wget https://services.gradle.org/distributions/gradle-8.14.2-bin.zip
```
* Creating a directory and unpacking an archive:
```bash
mkdir /opt/gradle
unzip -d /opt/gradle gradle-8.14.2-bin.zip
```
* Setting up the environment variable `PATH`:
```bash
export PATH=$PATH:/opt/gradle/gradle-8.14.2/bin
```

2. **Creating a Gradle test project:**
```bash
mkdir gradle-profiling-example
cd gradle-profiling-example
gradle init --type java-application --dsl kotlin --test-framework junit-jupiter --project-name simple-app --package com.example
```

3. **Loading the Java Pyroscope agent:**
* The agent is loaded into the Gradle daemon cache directory to be accessible to the daemon JVM.
```bash
wget -O /home/user/.gradle/daemon/8.14.2/pyroscope.jar https://github.com/grafana/pyroscope-java/releases/download/v2.1.2/pyroscope.jar
```
* *Note: The path is `/home/user/.gradle/daemon/8.14.2/` may vary depending on the user and the version of Gradle.*

4. **Launching the Pyroscope server:**
* A `docker-compose' file is created.yml` in the root of the project with the following contents:
```yaml
version: '3.8'
services:
pyroscope:
image: grafana/pyroscope:main-8c89229
ports:
- "4040:4040"
command:
- "server"
```
* The container starts:
```bash
docker-compose up -d
```

5. **Gradle configuration for profiling:**
* The `gradle.properties` file is created or edited in the root of the project with the following content, where the JVM arguments for the Gradle daemon are specified:
```properties
# JVM arguments for Gradle Daemon
org.gradle.jvmargs=-javaagent:pyroscope.jar -Dpyroscope.application.name=my-application{env=prod,version=1.0} -Dpyroscope.server.address=http://localhost:4040 -Dpyroscope.profile=cpu,alloc,lock,network,wall
```
* *Important: `pyroscope.jar` must be in a path accessible by the Gradle daemon. In this case, it was placed in his cache.*

6. **Launching the profiled build:**
* The project is being built. The '--no-daemon` flag is used to ensure that a new Gradle daemon is started that picks up arguments from `gradle.properties'.
```bash
gradle clean build --no-daemon
```

After completing these steps, when going to the Pyroscope web interface (`http://localhost:4040 `) the problem described above is observed.

![Image](https://github.com/user-attachments/assets/4b01eb75-5fd0-4b06-b748-fab6e4b2d6e8)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit der Konfiguration von gradle.properties und dem Verhalten des Java Pyroscope agent, wenn Gradle org.gradle.jvmargs an seinen Daemon übergibt. Reproduziere dies mit gradle clean build --no-daemon und überprüfe die resultierende Anwendung in der Pyroscope UI. Erledigt ist es, wenn der Build my-application mit den Tags env=prod und version=1.0 statt eines automatisch generierten Namens meldet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
build-system, observability
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.