Skip to content

Commit

Permalink
Merge pull request #529 from commercetools/oneagent-dynatrace
Browse files Browse the repository at this point in the history
Oneagent dynatrace
  • Loading branch information
lojzatran authored Dec 20, 2023
2 parents 2f7b643 + 7be1b03 commit 4b8101c
Show file tree
Hide file tree
Showing 66 changed files with 40,899 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/spring-dynatrace-oneagent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
**/application.properties

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
1 change: 1 addition & 0 deletions examples/spring-dynatrace-oneagent/.java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0
30 changes: 30 additions & 0 deletions examples/spring-dynatrace-oneagent/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use an official OpenJDK runtime as a base image
FROM openjdk:17-jdk-slim

ENV DT_PAAS_TOKEN="your PAAS token from Dynatrace (https://docs.dynatrace.com/docs/manage/access-control/access-tokens#paas-token)"
ENV DT_ENVIRONMENT_URL="your environment URL from Dynatrace (https://docs.dynatrace.com/docs/setup-and-configuration/setup-on-container-platforms/docker/set-up-oneagent-on-containers-for-application-only-monitoring#cloud-platforms)"
ENV CTP_CLIENT_SECRET="CTP client secret"
ENV CTP_CLIENT_ID="CTP client ID"
ENV CTP_PROJECT_KEY="CTP project key"

# Set the working directory inside the container
WORKDIR /app

# Copy the packaged JAR file into the container at the specified path
COPY build/libs/spring-dynatrace-oneagent-0.0.1-SNAPSHOT.jar /app/spring-dynatrace-oneagent-0.0.1-SNAPSHOT.jar

# Expose the port that your Spring Boot application will run on
EXPOSE 8080

RUN apt-get update && \
apt-get install -y wget unzip && \
rm -rf /var/lib/apt/lists/*

# ARGs for Dynatrace OneAgent

RUN mkdir -p /opt/dynatrace/oneagent && ARCHIVE=$(mktemp) && wget -O $ARCHIVE "https://$DT_ENVIRONMENT_URL.live.dynatrace.com/api/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_PAAS_TOKEN&flavor=default&arch=arm&include=$DT_ONEAGENT_TECHNOLOGY" && unzip -o -d /opt/dynatrace/oneagent $ARCHIVE && rm -f $ARCHIVE

ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so

# Set the entry point to start Dynatrace OneAgent
ENTRYPOINT [ "java", "-jar", "spring-dynatrace-oneagent-0.0.1-SNAPSHOT.jar" ]
40 changes: 40 additions & 0 deletions examples/spring-dynatrace-oneagent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Spring MVC example app

Example to show how Java SDK can be used in a Spring Boot application with Dynatrace OneAgent monitoring.

## Requirements

- A Composable Commerce Project with a configured [API Client](https://docs.commercetools.com/tutorials/getting-started#creating-an-api-client).
Necessary scopes: `view_published_products`, `manage_orders`
- Your Project must have existing products containing variants with SKUs, and at least one customer, the storefront search endpoint must be active.
- If your Project is currently empty, you can install the [SUNRISE sample data](https://docs.commercetools.com/sdk/sunrise-data).

## Installation

1. Clone/Download the example folder.
2. Navigate to the path `spring-dynatrace-oneagent/`.
3. Register the client credentials in environment variables:
`CTP_CLIENT_ID`, `CTP_CLIENT_SECRET` and `CTP_PROJECT_KEY`

## Using the Spring MVC Example app

### Install Dynatrace OneAgent
Follow the instructions on the [Dynatrace OneAgent page](
https://docs.dynatrace.com/docs/setup-and-configuration/dynatrace-oneagent#tabgroup--technology-support--operating-systems) to install the OneAgent on your system.

#### Install Dynatrace OneAgent on Mac
Currently, it is NOT possible to install Dynatrace OneAgent on macOS. For this case a [Dockerfile](./Dockerfile) is provided.
Use this file to build the application with the OneAgent included on Docker.
1. Run `./gradlew bootJar` to build a JAR file. This JAR file is necessary to build the Docker image.
2. Update ENV variables in the [Dockerfile](./Dockerfile) with your Dynatrace and CTP credentials.
3. Run `docker build -t spring-dynatrace-oneagent .` to build the Docker image.
4. Run `docker run -p 8080:8080 spring-dynatrace-oneagent` to start the Docker container.

### Navigate the application

1. Open a new browser window/tab
2. Navigate to [http://localhost:8080/p](http://localhost:8080/p) and a list of products should appear.

## Using Dynatrace with OpenTelemetry

If you want to use Dynatrace with OpenTelemetry, we also provide [an example Spring Boot application](../spring-otel).
42 changes: 42 additions & 0 deletions examples/spring-dynatrace-oneagent/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.4'
id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.commercetools.sdk.examples'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

repositories {
mavenLocal()
mavenCentral()
}

ext {
versions = [
commercetools: "17.3.0",
]
}

dependencies {
implementation "com.commercetools.sdk:commercetools-sdk-java-api:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-apachehttp-client:${versions.commercetools}"
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
developmentOnly "org.springframework.boot:spring-boot-devtools"
}

tasks.named('test') {
useJUnitPlatform()
}
Binary file not shown.
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-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 4b8101c

Please sign in to comment.