Skip to content

Commit

Permalink
Added docker build and download of agents
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz committed Jun 11, 2024
1 parent 344aa40 commit 79590e6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM maven:3.9.7-eclipse-temurin-21-alpine as build

WORKDIR /build

# Copy the local code to the container
COPY . .

# Build /build/target/cpu-burner.jar
RUN ./mvnw package

# Download /build/elastic-otel-javaagent.jar
ARG ELASTIC_OTEL_JAVAAGENT_VERSION=0.3.2
RUN wget --tries=5 -qO- https://repo1.maven.org/maven2/co/elastic/otel/elastic-otel-javaagent/${ELASTIC_OTEL_JAVAAGENT_VERSION}/elastic-otel-javaagent-${ELASTIC_OTEL_JAVAAGENT_VERSION}.jar > ./elastic-otel-javaagent.jar

FROM eclipse-temurin:21-jre-ubi9-minimal

COPY --from=build /build/target/cpu-burner.jar /
COPY --from=build /build/elastic-otel-javaagent.jar /

ENV OTEL_SERVICE_NAME=cpu-burner-otel
ENV ELASTIC_OTEL_UNIVERSAL_PROFILING_INTEGRATION_ENABLED=true

CMD ["java","-javaagent:./elastic-otel-javaagent.jar", "-jar", "./cpu-burner.jar"]
26 changes: 19 additions & 7 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
This project is a CPU-bound demo application for showcasing the elastic profiling capabilities.

To build, run `./mvnw package`.
To build the application, run `./mvnw package`.

Running with the [Elastic OpenTelemetry distribution](https://github.com/elastic/elastic-otel-java):
Running with the latest [Elastic OpenTelemetry distribution](https://github.com/elastic/elastic-otel-java):
```
java -javaagent:./elastic-otel-javaagent-<version>.jar \
curl -o 'elastic-otel-javaagent.jar' -L 'https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=co.elastic.otel&a=elastic-otel-javaagent&v=LATEST'
java -javaagent:./elastic-otel-javaagent.jar \
-Dotel.exporter.otlp.endpoint=<elastic-cloud-OTLP-endpoint> \
"-Dotel.exporter.otlp.headers=Authorization=Bearer XXXX" \
-Dotel.service.name=cpu-burner-otel \
-Delastic.otel.universal.profiling.integration.enabled=true \
-jar ./target/cpu-burner.jar
```

Running with the [classic Elastic APM Agent](https://github.com/elastic/apm-agent-java):
Running with the latest [classic Elastic APM Agent](https://github.com/elastic/apm-agent-java):
```
java -javaagent:elastic-apm-agent-<version>.jar \
curl -o 'elastic-apm-agent.jar' -L 'https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=co.elastic.apm&a=elastic-apm-agent&v=LATEST'
java -javaagent:elastic-apm-agent.jar \
-Delastic.apm.service_name=cpu-burner-elastic \
-Delastic.apm.secret_token=XXXXX \
-Delastic.apm.server_url=<elastic-apm-server-enndpoint> \
-Delastic.apm.server_url=<elastic-apm-server-endpoint> \
-Delastic.apm.application_packages=co.elastic.demo \
-Delastic.apm.universal_profiling_integration_enabled=true \
-jar ./target/cpu-burner.jar
```
```

Note that at the time of writing, universal profiling is only supported on Linux.
On macOS, you can use [colima](https://github.com/abiosoft/colima) and docker containers to avoid having to setup a full Linux VM yourself.

Use the following commands to build and run the cpu-burner app in Docker with the OpenTelemetry agent:
```
docker build -t cpu-burner .
docker run --rm -e OTEL_EXPORTER_OTLP_ENDPOINT=<elastic-cloud-OTLP-endpoint> -e OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer XXXX" cpu-burner
```

0 comments on commit 79590e6

Please sign in to comment.