Added OpenTelemetry Java Agent JAR to container image (#391)
Closes #387
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
FROM maven:3.8-openjdk-17-slim as build-hapi
|
||||
WORKDIR /tmp/hapi-fhir-jpaserver-starter
|
||||
|
||||
ARG OPENTELEMETRY_JAVA_AGENT_VERSION=1.15.0
|
||||
RUN curl -LSsO https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v${OPENTELEMETRY_JAVA_AGENT_VERSION}/opentelemetry-javaagent.jar
|
||||
|
||||
COPY pom.xml .
|
||||
COPY server.xml .
|
||||
RUN mvn -ntp dependency:go-offline
|
||||
@@ -29,15 +32,19 @@ USER 1001
|
||||
COPY --chown=1001:1001 catalina.properties /opt/bitnami/tomcat/conf/catalina.properties
|
||||
COPY --chown=1001:1001 server.xml /opt/bitnami/tomcat/conf/server.xml
|
||||
COPY --from=build-hapi --chown=1001:1001 /tmp/hapi-fhir-jpaserver-starter/target/ROOT.war /opt/bitnami/tomcat/webapps_default/ROOT.war
|
||||
COPY --from=build-hapi --chown=1001:1001 /tmp/hapi-fhir-jpaserver-starter/opentelemetry-javaagent.jar /app
|
||||
|
||||
ENV ALLOW_EMPTY_PASSWORD=yes
|
||||
|
||||
########### distroless brings focus on security and runs on plain spring boot - this is the default image
|
||||
FROM gcr.io/distroless/java17:nonroot as default
|
||||
COPY --chown=nonroot:nonroot --from=build-distroless /app /app
|
||||
# 65532 is the nonroot user's uid
|
||||
# used here instead of the name to allow Kubernetes to easily detect that the container
|
||||
# is running as a non-root (uid != 0) user.
|
||||
USER 65532:65532
|
||||
WORKDIR /app
|
||||
|
||||
COPY --chown=nonroot:nonroot --from=build-distroless /app /app
|
||||
COPY --chown=nonroot:nonroot --from=build-hapi /tmp/hapi-fhir-jpaserver-starter/opentelemetry-javaagent.jar /app
|
||||
|
||||
CMD ["/app/main.war"]
|
||||
|
||||
17
README.md
17
README.md
@@ -409,3 +409,20 @@ see the `-distroless` suffix in the image tags.
|
||||
To add a custom operation, refer to the documentation in the core hapi-fhir libraries [here](https://hapifhir.io/hapi-fhir/docs/server_plain/rest_operations_operations.html).
|
||||
|
||||
Within `hapi-fhir-jpaserver-starter`, create a generic class (that does not extend or implement any classes or interfaces), add the `@Operation` as a method within the generic class, and then register the class as a provider using `RestfulServer.registerProvider()`.
|
||||
|
||||
## Enable OpenTelemetry auto-instrumentation
|
||||
|
||||
The container image includes the [OpenTelemetry Java auto-instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation)
|
||||
Java agent JAR which can be used to export telemetry data for the HAPI FHIR JPA Server. You can enable it by specifying the `-javaagent` flag,
|
||||
for example by overriding the `JAVA_TOOL_OPTIONS` environment variable:
|
||||
|
||||
```sh
|
||||
docker run --rm -it -p 8080:8080 \
|
||||
-e JAVA_TOOL_OPTIONS="-javaagent:/app/opentelemetry-javaagent.jar" \
|
||||
-e OTEL_TRACES_EXPORTER="jaeger" \
|
||||
-e OTEL_SERVICE_NAME="hapi-fhir-server" \
|
||||
-e OTEL_EXPORTER_JAEGER_ENDPOINT="http://jaeger:14250" \
|
||||
docker.io/hapiproject/hapi:latest
|
||||
```
|
||||
|
||||
You can configure the agent using environment variables or Java system properties, see <https://opentelemetry.io/docs/instrumentation/java/automatic/agent-config/> for details.
|
||||
|
||||
Reference in New Issue
Block a user