This lib will add Azure Application Insights to the spring application.
To set up your local environment for development and testing, follow these steps:
- Clone the repository:
git clone https://github.com/EFS-OpenSource/superb-data-kraken-logging.git cd superb-data-kraken-logging
- Build the project and install the package to your local Maven repository:
./mvnw clean install
For building and releasing, the azure-pipeline.yml
is used. The deployment is triggered on commit. When no git tag is set, a snapshot version will
be build and released to the snapshot repository. When you add a git tag, keep in mind, that the tag will be used as release version.
To receive all information regarding the spring service, the agent needs to get downloaded (azure-pipeline-template.yml
)
and added to the container. Add the following block before the docker build step.
# ...
- task: CmdLine@2
displayName: Download Application Insights
inputs:
script: 'curl -L -o applicationinsights-agent.jar https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.14/applicationinsights-agent-3.4.14.jar'
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
# ...
After the download step in the pipeline, add the applicationinsights-agent.jar
to the container and add the javaagent to the ENTRYPOINT
.
For the application insights configuration to be found, the APPLICATIONINSIGHTS_CONFIGURATION_FILE
environment variable needs to be added to the dockerfile aswell.
# ...
ENV APPLICATIONINSIGHTS_CONFIGURATION_FILE /etc/application/applicationinsights.json
COPY applicationinsights-agent.jar applicationinsights-agent.jar
ENTRYPOINT ["java","-javaagent:/applicationinsights-agent.jar", "-jar","/app.jar","-Xmx=512M"]
For Application Insights to work, the config file needs to be added to the container. Add a applicationinsights.json
to the config-map.yml
.
Adapt the role name to the application name (eg. Organizationmanager Backend). The connectionString
is stored in the pipeline variables.
{
"connectionString": "$(app-insights-con-string)",
"role": {
"name": "TODO: APPLICATION NAME"
},
"instrumentation": {
"logging": {
"level": "OFF"
},
"micrometer": {
"enabled": true
}
},
"heartbeat": {
"intervalSeconds": 60
}
}
For the configuration to be loaded correctly. An additional entry has to be made in the bootstrap.yml
(spring v2) or application-kubernetes.yaml
(spring >v3).
#...
config:
paths:
- /etc/application/application.yml
- /etc/application/applicationinsights.json
enable-api: false
reload:
enabled: false
In order to register the logback configuration for the application, add the following to the application.yaml
section in the config-map.yml
.
The azure.application-insights.instrumentation-key
as well as the logging.config
information needs to be added.
azure:
application-insights:
instrumentation-key: $(app-insights-instrumentation-key)
# ...
logging:
config: classpath:com/efs/sdk/logging/sdk.logback.xml
level:
com.efs.sdk: $(logging-level)
To include this module in your project, simply add the following dependency declaration to the section of your pom.xml:
<dependency>
<groupId>com.efs.sdk</groupId>
<artifactId>sdk-logging</artifactId>
<version>1.0.0</version>
</dependency>
In order to create a audit log in the application, Use the static methods of AuditLogger
.
import com.efs.sdk.logging.AuditLogger;
//... Use either the JwtAuthenticationToken Object or the UserId as String
AuditLogger.info(LOG, "creating space {} in organization {}", token, dto.getName(), orgId);
//...
Links to tools used for building. Example:
- Maven v3.6.3 (see this Link)
See the Contribution Guide.
See the Changelog.