Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,11 @@ EventHubSamplingOverrides/output.txt
EventHubSamplingOverrides/target/*

target/


application-local.yml
application-local.yaml
application-local.properties
/applicationinsights.log
it-test-local.properties
/docker/**/data/
Binary file not shown.
32 changes: 32 additions & 0 deletions insightCustomDimensions/Docker/applicationinsights.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"selfDiagnostics": {
"destination": "console",
"level": "DEBUG"
},
"instrumentation": {
"logging": {
"enabled": true,
"level": "DEBUG"
},
"jdbc": {
"enabled": true,
"masking": {
"enabled": false
}
},
"springScheduling": {
"enabled": true
}
},
"customDimensions": {
},
"sampling": {
"percentage": 100
},
"preview": {
"captureLogbackMarker": false,
"captureLogbackCodeAttributes": false,
"captureLoggingLevelAsCustomDimension": true
}

}
37 changes: 37 additions & 0 deletions insightCustomDimensions/Docker/applicationinsights_to_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"selfDiagnostics": {
"destination": "file+console",
"level": "DEBUG",
"file": {
"path": "/tmp/applicationinsights.log",
"maxSizeMb": 5,
"maxHistory": 1
}
},
"instrumentation": {
"logging": {
"enabled": true,
"level": "DEBUG"
},
"jdbc": {
"enabled": true,
"masking": {
"enabled": false
}
},
"springScheduling": {
"enabled": true
}
},
"customDimensions": {
},
"sampling": {
"percentage": 100
},
"preview": {
"captureLogbackMarker": false,
"captureLogbackCodeAttributes": false,
"captureLoggingLevelAsCustomDimension": true
}

}
41 changes: 41 additions & 0 deletions insightCustomDimensions/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ---- Builder Stage ----
FROM maven:3.9.6-eclipse-temurin-17 AS builder

WORKDIR /app

# Copy pom.xml and preload dependencies
COPY pom.xml .
RUN mvn dependency:go-offline -B

# Copy sources and build
COPY src ./src
RUN mvn clean package -DskipTests

# Extract layers
RUN java -Djarmode=layertools -jar /app/target/*.jar extract


# the second stage of our build will copy the extracted layers
FROM eclipse-temurin:17-jre-alpine

WORKDIR /application

COPY --from=builder /app/dependencies/ ./dependencies/
COPY --from=builder /app/snapshot-dependencies/ ./snapshot-dependencies/
COPY --from=builder /app/spring-boot-loader/ ./spring-boot-loader/
COPY --from=builder /app/application/ ./application/

# Copy Application Insights agent + config
COPY ./Docker/applicationinsights-agent-3.7.4.jar /application/insight/
COPY ./Docker/applicationinsights.json /application/insight/

# Set AI config
ENV APPLICATIONINSIGHTS_CONFIGURATION_FILE=/application/insight/applicationinsights.json
# Create a group and user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Tell docker that all future commands should run as the appuser user
USER appuser

EXPOSE 8080
# Run Spring Boot via JarLauncher with AI agent
ENTRYPOINT ["java", "-javaagent:/application/insight/applicationinsights-agent-3.7.4.jar","org.springframework.boot.loader.launch.JarLauncher"]
66 changes: 66 additions & 0 deletions insightCustomDimensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
* A single controller that receives HTTP requests
* A request filter similar to the one you have in your code using the @Order tag.
* Inside the filter, create your custom span and apply the filter as you currently do in your code.
* Collect a dummy custom property that is expected to be added to your request.
* Enable App Insights Java Agent 3.7.2
* Use the same applicationinsights.json file that you have on your current Application.
* Even if this dummy code does not reproduce the issue, it will help our engineering team to
understand this scenario.

To Reproduce
Submitting a PR with an example reproducing the issue
in [this repository](https://github.com/microsoft/ApplicationInsights-Java-Repros) would make it
easier for the Application Insight maintainers to help you. Before doing this, you have to fork this
repository.

## Sample Test App

* 5 Filter added
* `SpanInitializationFilter`: init the span
* `OidLoggingFilter`: read the OID from JWT Baerer if exists
* `CountryLoggingFilter`: read the dbName from URL like /api/v1/{dbName}/company
* `HttpQueryLoggingFilter`: read the Query-Parameter
* `RawBodyLoggingFilter`: read the body of POST and PUT
* Endpoints:
* GET /api/v1/:dbName/company (i.e. :dbName=germany)
* Response:
```
{
"id": 1758202622283,
"name": "germany-Name",
"street": "germany-Street",
"postalCode": "germany-PostalCode",
"city": "germany-City"
},
{
"id": 1758202622283,
"name": "germany-Name",
"street": "germany-Street",
"postalCode": "germany-PostalCode",
"city": "germany-City"
}
]
```
* GET /api/v1/:dbName/company/:id (i.e :dbName=germany, id=123)
* Response:
```
{
"id": 111,
"name": "germany-Name",
"street": "germany-Street",
"postalCode": "germany-PostalCode",
"city": "germany-City"
}
```

* POST/PUT /api/v1/:dbName/company (i.e :dbName=germany)
* Request/Response (sample)
```
{
"id": 111,
"name": "germany-Name",
"street": "germany-Street",
"postalCode": "germany-PostalCode",
"city": "germany-City"
}
```
69 changes: 69 additions & 0 deletions insightCustomDimensions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.peri.psd</groupId>
<artifactId>testapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testapp</name>
<description>Test App</description>

<properties>

</properties>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>

<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>10.4.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal> <!-- builds executable fat jar -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.peri.psd.testapp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@SpringBootApplication(scanBasePackages = {"com.peri.psd.testapp"})
@EnableConfigurationProperties
public class PsdTestApplication {
public static void main(String[] args) {
SpringApplication.run(PsdTestApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.peri.psd.testapp.playground.api;

import com.peri.psd.testapp.playground.dto.CompanyMasterDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1")
@Slf4j
@RequiredArgsConstructor
public class PsdTestController {


@GetMapping("/{dbName}/company/{id}")
public ResponseEntity<CompanyMasterDto> getCompanyById(
@PathVariable String dbName,
@PathVariable Long id) {

log.debug("GET: /{}/company/{}", dbName, id);

return ResponseEntity.ok(CompanyMasterDto.builder()
.id(id)
.name(dbName + "-Name")
.city(dbName + "-City")
.street(dbName + "-Street")
.postalCode(dbName + "-PostalCode")
.build());
}

@GetMapping("/{dbName}/company")
public ResponseEntity<List<CompanyMasterDto>> getAllCompanies(@PathVariable String dbName) {

log.debug("GET: /{}/company", dbName);
return ResponseEntity.ok(List.of(CompanyMasterDto.builder()
.id(System.currentTimeMillis())
.name(dbName + "-Name")
.city(dbName + "-City")
.street(dbName + "-Street")
.postalCode(dbName + "-PostalCode")
.build(),
CompanyMasterDto.builder()
.id(System.currentTimeMillis())
.name(dbName + "-Name")
.city(dbName + "-City")
.street(dbName + "-Street")
.postalCode(dbName + "-PostalCode")
.build()));
}

@PostMapping("/{dbName}/company")
public ResponseEntity<CompanyMasterDto> createCompany(@PathVariable String dbName,
@RequestBody CompanyMasterDto companyMasterDto) {

log.debug("POST: /{}/company - {}", dbName, companyMasterDto);
return ResponseEntity.status(HttpStatus.CREATED)
.body(companyMasterDto);
}

@PutMapping("/{dbName}/company")
public ResponseEntity<CompanyMasterDto> updateCompany(@PathVariable String dbName,
@RequestBody CompanyMasterDto companyMasterDto) {

log.debug("PUT: /{}/company - {}", dbName, companyMasterDto);
return ResponseEntity.status(HttpStatus.ACCEPTED)
.body(companyMasterDto);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.peri.psd.testapp.playground.dto;

import lombok.*;

@Builder
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class CompanyMasterDto {

private Long id;
private String name;
private String street;
private String postalCode;
private String city;

}
Loading