azure-docs-sdk-java/docs-ref-services/spring-boot-metrics-starter...

3.9 KiB

title keywords author ms.author ms.date ms.topic ms.prod ms.technology ms.devlang ms.service
Azure Metrics Spring Boot Starter client library for Java Azure, java, SDK, API, azure-spring-boot-metrics-starter, springboot maggiepint magpint 09/14/2020 article azure azure java springboot

Azure Metrics Spring Boot Starter client library for Java - Version 2.3.5

With this starter you could easily use Azure Metrics with Spring Boot.

Package (Maven) | API reference documentation

Getting started

Prerequisites

Include the package

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-spring-boot-metrics-starter</artifactId>
    <version>2.3.5</version>
</dependency>

Key concepts

Java agent based monitoring: Azure Application Insights has released one Java agent that can be used to capture metrics inside JVM. Consider use the Java agent based approach.

Refer following document for more details:

https://docs.microsoft.com/azure/azure-monitor/app/java-in-process-agent

Examples

Add the property setting

Open application.properties file and add below properties with your instrumentation key.

management.metrics.export.azuremonitor.instrumentation-key=<your-instrumentation-key-here>

Troubleshooting

If the JDK version you use is greater than 1.8, You may meet this problem:

NoClassDefFoundError: javax/xml/bind/JAXBException

To solve this issue, you need to add the dependency below into your classpath:

<dependency>
   <groupId>javax.xml.bind</groupId>
   <artifactId>jaxb-api</artifactId>
   <version>2.3.0</version>
</dependency>

Enable client logging

Azure SDKs for Java offers a consistent logging story to help aid in troubleshooting application errors and expedite their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help locate the root issue. View the logging wiki for guidance about enabling logging.

Enable Spring logging

Spring allow all the supported logging systems to set logger levels set in the Spring Environment (for example, in application.properties) by using logging.level.<logger-name>=<level> where level is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, or OFF. The root logger can be configured by using logging.level.root.

The following example shows potential logging settings in application.properties:

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

For more information about setting logging in spring, please refer to the official doc.

Next steps

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

Please follow instructions here to build from source or contribute.