From e79c99dfce50f33287829cf3a18cbf0ec3ed72bc Mon Sep 17 00:00:00 2001 From: Rees Pozzi Date: Wed, 17 Dec 2025 15:12:31 +0000 Subject: [PATCH] Removes appinsights module from java-logging --- README.md | 22 +- java-logging-appinsights/README.md | 224 ------------------ java-logging-appinsights/build.gradle | 59 ----- .../logging/appinsights/SyntheticHeaders.java | 21 -- .../AppInsightsAutoConfiguration.java | 53 ----- .../ContextVersionInitializer.java | 18 -- .../main/resources/META-INF/spring.factories | 2 - .../main/resources/logback-appinsights.xml | 13 - .../src/test/resources/application.yml | 3 - settings.gradle | 4 +- 10 files changed, 21 insertions(+), 398 deletions(-) delete mode 100644 java-logging-appinsights/README.md delete mode 100644 java-logging-appinsights/build.gradle delete mode 100644 java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders.java delete mode 100644 java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/autoconfiguration/AppInsightsAutoConfiguration.java delete mode 100644 java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/telemetry/initializers/ContextVersionInitializer.java delete mode 100644 java-logging-appinsights/src/main/resources/META-INF/spring.factories delete mode 100644 java-logging-appinsights/src/main/resources/logback-appinsights.xml delete mode 100644 java-logging-appinsights/src/test/resources/application.yml diff --git a/README.md b/README.md index 0d06d312..9be254c7 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,27 @@ repositories { implementation group: 'com.github.hmcts.java-logging', name: 'logging', version: 'LATEST_TAG' ``` -#### java-logging-insights +#### Application Insights -Use for automatic configuration of Azure Application Insights for a Spring Boot project. [Read more](java-logging-appinsights/README.md) +The `java-logging-appinsights` module has been removed in version 7.0.0. If upgrading from 6.x, remove this dependency: +```gradle +// Remove this line: +implementation group: 'com.github.hmcts.java-logging', name: 'logging-appinsights', version: 'x.x.x' +``` + +##### Application Insights Agent Setup + +Teams now add the Application Insights agent directly to their Dockerfile, for example it might look like this: + +```dockerfile +# renovate: datasource=github-releases depName=microsoft/ApplicationInsights-Java +ARG APP_INSIGHTS_AGENT_VERSION=3.4.9 +... + +COPY lib/applicationinsights.json /opt/app/ +... + +``` ### Configuration defaults diff --git a/java-logging-appinsights/README.md b/java-logging-appinsights/README.md deleted file mode 100644 index 2335961c..00000000 --- a/java-logging-appinsights/README.md +++ /dev/null @@ -1,224 +0,0 @@ -# Azure Application Insights - -Logging module to auto configure necessary components for Azure Application Insights app. -It uses [azure-application-insights-spring-boot-starter](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter) and adds some specific initializers as Spring beans. -Module also tracks logback INFO events for `uk.gov.hmcts` loggers - -## User guide - -The module provides all Telemetry modules and initializers available from web artifact. - -### Basic usage - -Gradle: - -```groovy -repositories { - maven { - url 'https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1' - } -} - -dependencies { - implementation group: 'com.github.hmcts.java-logging', name: 'logging-appinsights', version: 'LATEST_TAG' -} -``` - -Note: if you're on an older version of Spring Boot you may need to bring it and the logging-spring libraries in on deprecated versions: -```groovy -dependencies { - implementation group: 'com.github.hmcts', name: 'java-logging', version: '6.1.8' - implementation group: 'com.github.hmcts.java-logging', name: 'logging-spring', version: '5.1.9' - implementation group: 'com.github.hmcts.java-logging', name: 'logging-appinsights', version: '5.1.9' -} -``` - -It will automatically include Request Name interceptor and Request Tracking Filter configurations into spring boot web application. - -Request Tracking Filter needs agent to be configured. By default agent uses built in configuration but you can provide your own. - -Sample of `AI-Agent.xml`: - -```xml - - - INFO - - - - - - - - - -``` - -This file must be placed in a `/lib` directory for applications running on CNP along with the agent jar that matches the current app insights version here -Retrieve the jar from github, i.e. https://github.com/Microsoft/ApplicationInsights-Java/releases - -TelemetryClient can be `autowired` to implement custom telemetry metrics. - -#### Provide App Insights Connection Key -Microsoft ended support for Instrumentation Key Ingestion on March 31, 2025. - -An app-insight-connection-key is provided in the Key Vault Secrets. (Note: It's sometimes spelled app-insights-connection-key.) - -Add to your projects secrets in cnp-flux-config: -``` -- name: app-insight-connection-key - alias: app-insight-connection-key -``` - -On your project: -1. Add a applicationinsights.json file with connection key path in the lib/ directory -``` -{ - "connectionString": "${file:/mnt/secrets/adoption/app-insight-connection-key}", - "role": { - "name": "HMCTS MyProject" - } -} -``` -More information: https://docs.azure.cn/en-us/azure-monitor/app/java-standalone-config - -2. Add a step in your Dockerfile to move the new applicationinsights.json file to the correct location: -``` -COPY lib/applicationinsights.json /opt/app/ -``` - - -### Optional Configuration defaults - -#### Modules configured by spring starter - -- WebRequestTrackingTelemetryModule -- WebSessionTrackingTelemetryModule -- WebUserTrackingTelemetryModule - -#### Initializers configured by spring starter - - -##### Context - -- DeviceInfoContextInitializer -- SdkVersionContextInitializer - -##### Telemetry - -- WebOperationIdTelemetryInitializer -- WebOperationNameTelemetryInitializer -- WebSessionTelemetryInitializer -- WebSyntheticRequestTelemetryInitializer -- WebUserTelemetryInitializer -- WebUserAgentTelemetryInitializer -- CloudInfoContextInitializer -- SpringBootTelemetryInitializer - -#### Initializers configured by logging-appinsights - -##### Context -ContextInitializer ( Custom Initializer to set component version to context) - -##### Telemetry - -- TimestampPropertyInitializer -- SequencePropertyInitializer -- WebSyntheticRequestTelemetryInitializer - - -`WebSyntheticRequestTelemetryInitializer` provides functionality to separate out requests via so called Synthetic Source tag. -All headers are available in helper class [SyntheticHeaders](java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders). -All headers are optional and by default will be assumed `Application Insights Availability Monitoring` as Synthetic source name. -Additionally default setup tries to include `SyntheticTest-RunId` and `SyntheticTest-Location` if present. -For particular requests required to be separated, case can provide additional header `SyntheticTest-Source` which will replace default source name. -Along with custom Source name there are more optional headers to be applied at will: - -- `SyntheticTest-UserId` -- `SyntheticTest-SessionId` -- `SyntheticTest-OperationId` -- `SyntheticTest-TestName` -- `SyntheticTest-RunId` -- `SyntheticTest-Location` - -[SyntheticHeaders](java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders) might be deprecated in future based on Microsoft making the constants public. - -#### To disable Application insights completely - -Refer [Spring Starter disabling App Insights](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter#completely-disable-application-insights-using-applicationproperties) - -#### Developer mode - -By default developer mode is disabled. This is controlled by starter and to turn it on , set the configuration manually (for telemetry client to pick it up): - -```java -TelemetryConfiguration.getActive().getChannel().setDeveloperMode(true); -``` - -or simply turn on by configuration: - -```yaml -azure: - application-insights: - channel: - in-process: - developer-mode: true - -``` - -Dev mode causes significant overhead in CPU and network bandwidth. But sends each telemetry one by one instantly available on Azure. - -Request components stand fo WebRequestNameInterceptor and WebRequestTrackingFilter - automatically configured in library - -Request component, WebRequestTrackingFilter in particular, requires application name to be present: - -```yaml -spring: - application: - name: My Application Insights WebApp -``` - -This configuration entry is also used by [`SpringBootTelemetryInitializer`](https://github.com/Microsoft/ApplicationInsights-Java/blob/v2.3.1/azure-application-insights-spring-boot-starter/src/main/java/com/microsoft/applicationinsights/autoconfigure/initializer/SpringBootTelemetryInitializer.java) to set the `cloud_Role` App Insights tag. This makes distinguishing between services easier in cases where a number of related services uses the same App Insights instance. - - -#### Flags - -For Spring starter configurations , Refer [configure-more-parameters-using-applicationproperties](https://github.com/Microsoft/ApplicationInsights-Java/tree/v2.3.1/azure-application-insights-spring-boot-starter#configure-more-parameters-using-applicationproperties) - -Additional properties : -```properties -application-insights.custom.modules.ContextInitializer.enabled=true -application-insights.default.modules.TimestampPropertyInitializer.enabled=true -application-insights.default.modules.SequencePropertyInitializer.enabled=true -application-insights.default.modules.WebSyntheticRequestTelemetryInitializer.enabled=true - -``` - - -In case service does not need request component, it is recommended to exclude auto-injected library from the project dependencies: - -```groovy -configurations { - runtime.exclude group: 'com.microsoft.azure', module: 'applicationinsights-agent' -} -``` - -#### Product version - -AppInsights uses application version in most if not all metrics. This is now set via MANIFEST property: - -```manifest -Implementation-Version: 0.0.1 -``` - -In spring boot template this will be set by default in jar task where name of the file is defined for CNP deployment. Example: - -```groovy -jar { - archiveName 'spring-boot-template.jar' - - manifest { - attributes('Implementation-Version': project.version.toString()) - } -} -``` diff --git a/java-logging-appinsights/build.gradle b/java-logging-appinsights/build.gradle deleted file mode 100644 index f13d120e..00000000 --- a/java-logging-appinsights/build.gradle +++ /dev/null @@ -1,59 +0,0 @@ -plugins { - id 'io.spring.dependency-management' version '1.1.7' -} - -def versions = [ - springBoot: '4.0.0', - appInsights: '2.6.4' -] - -java { - withJavadocJar() - withSourcesJar() -} - -publishing { - publications { - Insights(MavenPublication) { - from components.java - groupId project.group - artifactId 'logging-appinsights' - version project.version - } - } - - repositories { - maven { - name = "AzureArtifacts" - url = uri("https://pkgs.dev.azure.com/hmcts/Artifacts/_packaging/hmcts-lib/maven/v1") - credentials { - username = System.getenv("AZURE_DEVOPS_ARTIFACT_USERNAME") - password = System.getenv("AZURE_DEVOPS_ARTIFACT_TOKEN") - } - } - } -} - -repositories { - flatDir { - dirs "$projectDir/lib" - } -} - -dependencyManagement { - imports { - mavenBom "org.springframework.boot:spring-boot-dependencies:${versions.springBoot}" - } -} - -dependencies { - api group: 'org.springframework.boot', name: 'spring-boot-autoconfigure' - - api group: 'com.microsoft.azure', name: 'applicationinsights-logging-logback', version: versions.appInsights - api group: 'com.microsoft.azure', name: 'applicationinsights-spring-boot-starter', version: versions.appInsights - - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' - - testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.27.4' -} diff --git a/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders.java b/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders.java deleted file mode 100644 index fbc1a37d..00000000 --- a/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/SyntheticHeaders.java +++ /dev/null @@ -1,21 +0,0 @@ -package uk.gov.hmcts.reform.logging.appinsights; - -/** - * Utility class to provide headers used in WebSyntheticRequestTelemetryInitializer. - * It has package private access to those fields - making it public here for re-usability. - * If https://github.com/Microsoft/ApplicationInsights-Java/pull/813 is accepted we can deprecate / remove this class - */ -public final class SyntheticHeaders { - - public static final String SYNTHETIC_TEST_RUN_ID = "SyntheticTest-RunId"; - public static final String SYNTHETIC_TEST_LOCATION = "SyntheticTest-Location"; - public static final String SYNTHETIC_TEST_SOURCE = "SyntheticTest-Source"; - public static final String SYNTHETIC_TEST_TEST_NAME = "SyntheticTest-TestName"; - public static final String SYNTHETIC_TEST_SESSION_ID = "SyntheticTest-SessionId"; - public static final String SYNTHETIC_TEST_USER_ID = "SyntheticTest-UserId"; - public static final String SYNTHETIC_TEST_OPERATION_ID = "SyntheticTest-OperationId"; - - private SyntheticHeaders() { - // utility class constructor - } -} diff --git a/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/autoconfiguration/AppInsightsAutoConfiguration.java b/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/autoconfiguration/AppInsightsAutoConfiguration.java deleted file mode 100644 index 3f27ca16..00000000 --- a/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/autoconfiguration/AppInsightsAutoConfiguration.java +++ /dev/null @@ -1,53 +0,0 @@ -package uk.gov.hmcts.reform.logging.appinsights.autoconfiguration; - -import com.microsoft.applicationinsights.extensibility.initializer.SequencePropertyInitializer; -import com.microsoft.applicationinsights.extensibility.initializer.TimestampPropertyInitializer; -import com.microsoft.applicationinsights.web.extensibility.initializers.WebSyntheticRequestTelemetryInitializer; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import uk.gov.hmcts.reform.logging.appinsights.telemetry.initializers.ContextVersionInitializer; - -/** - * Core Application Insights Configuration. - * - *

This class provides the custom Configuration for AppInsights. - */ -public class AppInsightsAutoConfiguration { - - public static final String HAVING_VALUE_TRUE = "true"; - - /** - * Bean for ContextVersionInitializer. - * - * @return instance of {@link ContextVersionInitializer} - */ - @Bean - @ConditionalOnProperty(value = "application-insights.custom.modules.ContextVersionInitializer.enabled", - havingValue = HAVING_VALUE_TRUE, matchIfMissing = true) - public ContextVersionInitializer contextVersionInitializer() { - return new ContextVersionInitializer(); - } - - @Bean - @ConditionalOnProperty(value = "application-insights.default.modules.TimestampPropertyInitializer.enabled", - havingValue = HAVING_VALUE_TRUE, matchIfMissing = true) - public TimestampPropertyInitializer timestampPropertyInitializer() { - return new TimestampPropertyInitializer(); - } - - @Bean - @ConditionalOnProperty(value = "application-insights.default.modules.SequencePropertyInitializer.enabled", - havingValue = HAVING_VALUE_TRUE, matchIfMissing = true) - public SequencePropertyInitializer sequencePropertyInitializer() { - return new SequencePropertyInitializer(); - } - - @Bean - @ConditionalOnProperty - (value = "application-insights.default.modules.WebSyntheticRequestTelemetryInitializer.enabled", - havingValue = HAVING_VALUE_TRUE, matchIfMissing = true) - public WebSyntheticRequestTelemetryInitializer webSyntheticRequestTelemetryInitializer() { - return new WebSyntheticRequestTelemetryInitializer(); - } - -} diff --git a/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/telemetry/initializers/ContextVersionInitializer.java b/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/telemetry/initializers/ContextVersionInitializer.java deleted file mode 100644 index f15c4d8d..00000000 --- a/java-logging-appinsights/src/main/java/uk/gov/hmcts/reform/logging/appinsights/telemetry/initializers/ContextVersionInitializer.java +++ /dev/null @@ -1,18 +0,0 @@ -package uk.gov.hmcts.reform.logging.appinsights.telemetry.initializers; - -import com.microsoft.applicationinsights.extensibility.ContextInitializer; -import com.microsoft.applicationinsights.telemetry.TelemetryContext; - -/** - * ContextVersionInitializer to set version to telemetry. - * - *

This Telemetry Initializer is used to auto-configure version field as current spring boot starter for - * app insights is not setting this. - */ -public class ContextVersionInitializer implements ContextInitializer { - @Override - public void initialize(TelemetryContext telemetryContext) { - telemetryContext.getComponent().setVersion(getClass().getPackage().getImplementationVersion()); - } - -} diff --git a/java-logging-appinsights/src/main/resources/META-INF/spring.factories b/java-logging-appinsights/src/main/resources/META-INF/spring.factories deleted file mode 100644 index d4ac7970..00000000 --- a/java-logging-appinsights/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -uk.gov.hmcts.reform.logging.appinsights.autoconfiguration.AppInsightsAutoConfiguration diff --git a/java-logging-appinsights/src/main/resources/logback-appinsights.xml b/java-logging-appinsights/src/main/resources/logback-appinsights.xml deleted file mode 100644 index 118fd159..00000000 --- a/java-logging-appinsights/src/main/resources/logback-appinsights.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/java-logging-appinsights/src/test/resources/application.yml b/java-logging-appinsights/src/test/resources/application.yml deleted file mode 100644 index 1255dcf4..00000000 --- a/java-logging-appinsights/src/test/resources/application.yml +++ /dev/null @@ -1,3 +0,0 @@ -spring: - application: - name: App Insights Test Suite diff --git a/settings.gradle b/settings.gradle index 83a3d54f..e9bc893b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1 @@ -rootProject.name = 'java-logging' - -include 'java-logging-appinsights' +rootProject.name = 'java-logging' \ No newline at end of file