Skip to content

Commit fa05d6b

Browse files
Update outdated java span profile information (#3339)
* Update outdated java span profile information * Remove first person and uppercase docker * Update docs/sources/configure-client/trace-span-profiles/java-span-profiles.md Co-authored-by: Kim Nylander <[email protected]> --------- Co-authored-by: Kim Nylander <[email protected]>
1 parent a7a0a82 commit fa05d6b

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

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

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,52 @@ Your applications must be instrumented for profiling and tracing before you can
4040

4141
## Configure the otel-profiling-java package
4242

43-
To start collecting Span Profiles for your Java application, you need to include [otel-profiling-java](https://github.com/pyroscope-io/otel-profiling-java) in your code.
43+
To start collecting Span Profiles for your Java application, you need to include [otel-profiling-java](https://github.com/pyroscope-io/otel-profiling-java) as an extension to your application.
4444

45-
This package is a `TracerProvider` implementation, that labels profiling data with span IDs which makes it possible to query for span-specific profiling data in Grafana Tempo UI.
45+
Assuming you have this sample application Docker image:
4646

47-
```shell
48-
java -jar ./build/libs/rideshare-1.0-SNAPSHOT.jar \
49-
-javaagent:./opentelemetry-javaagent.jar \
50-
-Dotel.javaagent.extensions=./pyroscope-otel.jar \
51-
-Dotel.pyroscope.start.profiling=true \
52-
-Dpyroscope.application.name=ride-sharing-app-java-instrumentation \
53-
-Dpyroscope.format=jfr \
54-
-Dpyroscope.profiler.event=itimer \
55-
-Dpyroscope.server.address=$PYROSCOPE_SERVER_ADDRESS \
56-
# rest of your otel-java-instrumentation configuration
47+
```Dockerfile
48+
# [...]
5749

50+
EXPOSE 5000
51+
52+
CMD ["java", "-Dserver.port=5000", "-jar", "./my-app.jar" ]
5853
```
5954

60-
Next, you need to create and configure the tracer provider:
61-
```java
62-
implementation("io.pyroscope:otel:0.10.1.11")
55+
By adding the OTel Java agent and the Pyroscope OTel Java Agent extensions, you can enrich your profiles with span IDs. This makes it possible to query for span-specific profiling data in Grafana Tempo:
6356

64-
// obtain SdkTracerProviderBuilder
65-
SdkTracerProviderBuilder tpBuilder = ...
57+
```Dockerfile
58+
# [...]
6659

67-
// Add PyroscopeOtelSpanProcessor to SdkTracerProviderBuilder
68-
PyroscopeOtelConfiguration pyroscopeTelemetryConfig = new PyroscopeOtelConfiguration.Builder()
69-
.setAddSpanName(true)
70-
.setRootSpanOnly(true)
71-
.build();
72-
tpBuilder.addSpanProcessor(new PyroscopeOtelSpanProcessor(pyroscopeOtelConfig));
60+
EXPOSE 5000
7361

74-
```
62+
## Add required libararies
63+
ADD https://github.com/grafana/pyroscope-java/releases/download/v0.12.2/pyroscope.jar ./pyroscope.jar
64+
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.10.1.11/otel-0.10.1.11.jar pyroscope-otel.jar
66+
67+
ENV PYROSCOPE_APPLICATION_NAME=my-app
68+
ENV PYROSCOPE_FORMAT=jfr
69+
ENV PYROSCOPE_PROFILING_INTERVAL=10ms
70+
ENV PYROSCOPE_PROFILER_EVENT=itimer
71+
ENV PYROSCOPE_PROFILER_LOCK=10ms
72+
ENV PYROSCOPE_PROFILER_ALLOC=512k
73+
ENV PYROSCOPE_UPLOAD_INTERVAL=15s
74+
ENV OTEL_JAVAAGENT_EXTENSIONS=./pyroscope-otel.jar
75+
ENV OTEL_PYROSCOPE_ADD_PROFILE_URL=false
76+
ENV OTEL_PYROSCOPE_ADD_PROFILE_BASELINE_URL=false
77+
ENV OTEL_PYROSCOPE_START_PROFILING=true
78+
79+
## Useful for debugging
80+
# ENV PYROSCOPE_LOG_LEVEL=debug
7581

76-
Now that we set up the tracer, we can create a new trace from anywhere and the profiler will automatically capture profiles for it.
77-
```java
78-
Span span = tracer.spanBuilder("findNearestVehicle").startSpan();
79-
try (Scope s = span.makeCurrent()){
80-
// Your code goes here.
81-
} finally {
82-
span.end();
83-
}
82+
## Those environment variables need to be overwritten at runtime, if you are using Grafana Cloud
83+
ENV PYROSCOPE_SERVER_ADDRESS=http://localhost:4040
84+
# ENV PYROSCOPE_BASIC_AUTH_USER=123 ## Grafana Cloud Username
85+
# ENV PYROSCOPE_BASIC_AUTH_PASSWORD=glc_secret ## Grafana Cloud Password / API Token
8486

85-
// Your code goes here.
87+
## Add the pyroscope and the opentelemetry java-agents
88+
CMD ["java", "-Dserver.port=5000", "-javaagent:./opentelemetry-javaagent.jar", "-javaagent:pyroscope.jar", "-jar", "./my-app.jar" ]
8689
```
8790

8891
## View the span profiles in Grafana Tempo

0 commit comments

Comments
 (0)