-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add a java span profiling example without the Pyroscope sdk (…
…#3698) * examples: add a java span profiling example without the Pyroscope sdk * update java span profiles doc
- Loading branch information
Showing
23 changed files
with
767 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build/ | ||
.idea/ | ||
.gradle | ||
pyroscope.jar | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3.9 | ||
|
||
RUN pip3 install requests | ||
|
||
COPY load-generator.py ./load-generator.py | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
|
||
CMD [ "python", "load-generator.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Span Profiles with Grafana Tempo and Pyroscope | ||
|
||
The docker compose consists of: | ||
- The Java Rideshare App | ||
- Tempo | ||
- Pyroscope | ||
- Grafana | ||
|
||
The `rideshare` app generate traces and profiling data that should be available in Grafana. | ||
Pyroscope and Tempo datasources are provisioned automatically. | ||
|
||
### Build and run | ||
|
||
The project can be run locally with the following commands: | ||
|
||
```shell | ||
# Pull latest pyroscope and grafana images: | ||
docker pull grafana/pyroscope:latest | ||
docker pull grafana/grafana:latest | ||
|
||
docker compose up | ||
``` | ||
|
||
Navigate to the [Explore page](http://localhost:3000/explore?schemaVersion=1&panes=%7B%22yM9%22:%7B%22datasource%22:%22tempo%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22tempo%22,%22uid%22:%22tempo%22%7D,%22queryType%22:%22traceqlSearch%22,%22limit%22:20,%22tableType%22:%22traces%22,%22filters%22:%5B%7B%22id%22:%22e73a615e%22,%22operator%22:%22%3D%22,%22scope%22:%22span%22%7D,%7B%22id%22:%22service-name%22,%22tag%22:%22service.name%22,%22operator%22:%22%3D%22,%22scope%22:%22resource%22,%22value%22:%5B%22ride-sharing-app%22%5D,%22valueType%22:%22string%22%7D%5D%7D%5D,%22range%22:%7B%22from%22:%22now-6h%22,%22to%22:%22now%22%7D%7D%7D&orgId=1), select a trace and click on a span that has a linked profile: | ||
|
||
![image](https://github.com/grafana/otel-profiling-go/assets/12090599/31e33cd1-818b-4116-b952-c9ec7b1fb593) | ||
|
||
By default, only the root span gets labeled (the first span created locally): such spans are marked with the _link_ icon | ||
and have `pyroscope.profile.id` attribute set to the corresponding span ID. | ||
Please note that presence of the attribute does not necessarily | ||
indicate that the span has a profile: stack trace samples might not be collected, if the utilized CPU time is | ||
less than the sample interval (10ms). | ||
|
||
### Instrumentation | ||
|
||
- `rideshare` demo application instrumented with OpenTelemetry: [OTel integration](https://github.com/grafana/otel-profiling-java) | ||
- `pyroscope` itself is instrumented with `opentracing-go` SDK and [`spanprofiler`](https://github.com/grafana/dskit/tree/main/spanprofiler) for profiling integration. | ||
|
||
### Grafana Tempo configuration | ||
|
||
In order to correlate trace spans with profiling data, the Tempo datasource should have the following configured: | ||
- The profiling data source | ||
- Tags to use when making profiling queries | ||
|
||
![image](https://github.com/grafana/pyroscope/assets/12090599/380ac574-a298-440d-acfb-7bc0935a3a7c) | ||
|
||
While tags are optional, configuring them is highly recommended for optimizing query performance. | ||
In our example, we configured the `service.name` tag for use in Pyroscope queries as the `service_name` label. | ||
This configuration restricts the data set for lookup, ensuring that queries remain | ||
consistently fast. Note that the tags you configure must be present in the span attributes or resources | ||
for a trace to profiles span link to appear. | ||
|
||
Please refer to our [documentation](https://grafana.com/docs/grafana/next/datasources/tempo/configure-tempo-data-source/#trace-to-profiles) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id("java") | ||
id("org.springframework.boot") version "2.7.0" | ||
id("io.spring.dependency-management") version "1.0.11.RELEASE" | ||
} | ||
|
||
group = "org.example" | ||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter-web") | ||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2") | ||
} | ||
|
||
tasks.getByName<Test>("test") { | ||
useJUnitPlatform() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
version: '3' | ||
services: | ||
pyroscope: | ||
image: grafana/pyroscope | ||
ports: | ||
- "4040:4040" | ||
|
||
us-east: | ||
ports: | ||
- "5000" | ||
environment: &env | ||
OTLP_URL: tempo:4318 | ||
OTLP_INSECURE: 1 | ||
OTEL_TRACES_EXPORTER: otlp | ||
OTEL_EXPORTER_OTLP_ENDPOINT: http://tempo:4317 | ||
OTEL_SERVICE_NAME: rideshare.java.push.app | ||
OTEL_METRICS_EXPORTER: none | ||
OTEL_TRACES_SAMPLER: always_on | ||
OTEL_PROPAGATORS: tracecontext | ||
REGION: us-east | ||
PYROSCOPE_LABELS: region=us-east | ||
PYROSCOPE_SERVER_ADDRESS: http://pyroscope:4040 | ||
build: | ||
context: . | ||
eu-north: | ||
ports: | ||
- "5000" | ||
environment: | ||
<<: *env | ||
REGION: eu-north | ||
build: | ||
context: . | ||
ap-south: | ||
ports: | ||
- "5000" | ||
environment: | ||
<<: *env | ||
REGION: ap-south | ||
build: | ||
context: . | ||
|
||
load-generator: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.load-generator | ||
|
||
grafana: | ||
image: grafana/grafana:latest | ||
environment: | ||
- GF_INSTALL_PLUGINS=grafana-pyroscope-app | ||
- GF_AUTH_ANONYMOUS_ENABLED=true | ||
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin | ||
- GF_AUTH_DISABLE_LOGIN_FORM=true | ||
- GF_FEATURE_TOGGLES_ENABLE=traceToProfiles tracesEmbeddedFlameGraph | ||
volumes: | ||
- ./grafana-provisioning:/etc/grafana/provisioning | ||
ports: | ||
- "3000:3000" | ||
|
||
tempo: | ||
image: grafana/tempo:latest | ||
command: [ "-config.file=/etc/tempo.yml" ] | ||
volumes: | ||
- ./tempo/tempo.yml:/etc/tempo.yml | ||
ports: | ||
- "14268:14268" # jaeger ingest | ||
- "3200:3200" # tempo | ||
- "9095:9095" # tempo grpc | ||
- "4317:4317" # otlp grpc | ||
- "4318:4318" # otlp http | ||
- "9411:9411" # zipkin |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
examples/tracing/java/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.