简体   繁体   中英

Spring Boot app on Azure cannot connect to Application Insights

I have a number of Azure App Service deployed Java applications using Application Insights. Over the last 72 hours they've started failing to deploy upon restart. Nothing has changed that I'm aware of, though, of course, I would say that.

The only smoking gun I can find is that there is a warning in the default-docker.log

WARN 138 --- [           main] c.m.azure.telemetry.TelemetrySender      : Failed to exchange telemetry request, I/O error on POST request for "https://dc.services.visualstudio.com/v2/track": Connection reset; nested exception is java.net.SocketException: Connection reset.

Some of the applications are using the java agent for application insights, some are not, so I don't think that the agent is the problem.

And google has not seemed to be my friend today, as there are no results on this subject.

  • Here I was able to connect to application insights by adding an applicationsinsights.json which will contain the connection string and with logback-spring.xml which will configure logging in the app.

logback-spring.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<configuration>  
    <appender name="aiAppender" class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender">  
    </appender>
    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">  
         <layout name = "ch.qos.logback.classic.PatternLayout">  
             <Pattern>  %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%c{}): %msg%n%throwable;%n  
             </Pattern>  
         </layout> 
     </appender>  
     <root level ="warn">  
     <appender-ref ref="aiAppender" />  
     <appender-ref ref="Console" />   
     </root>
 </configuration>

applicationsinsights.json

{
    "ConnectionString":""
}

pom.xml (Dependencies)

<dependency>  
    <groupId>org.springframework.boot</groupId>  
     <artifactId>spring-boot-starter-web</artifactId>  
</dependency>  
  
<dependency>  
     <groupId>org.springframework.boot</groupId>  
     <artifactId>spring-boot-starter-test</artifactId>  
     <scope>test</scope>  
</dependency>  
<dependency>  
     <groupId>com.microsoft.azure</groupId>  
     <artifactId>applicationinsights-runtime-attach</artifactId>  
     <version>3.4.3</version>  
</dependency>  
  
<dependency>  
     <groupId>com.microsoft.azure</groupId>  
     <artifactId>applicationinsights-logging-logback</artifactId>  
     <version>[2.0,)</version>  
</dependency>  
<dependency>  
     <groupId>com.microsoft.azure</groupId>  
     <artifactId>applicationinsights-spring-boot-starter</artifactId>  
     <version>2.6.4</version>  
</dependency>

In The main file I also added the following line

ApplicationInsights.attach();

make sure the above file is above everything else in the main function.在此处输入图像描述

  • Now coming back to your error, it maybe because the connection to the application insights is closing before your app could send the logs. Try redeploying the application insight.

Turns out that the actual problem was in the configuration of the firewall between the application instances and the Application Insights service. The firewall is configured by a third party (outsourcing FTW), and they had change the.network MTU from 1500 to 1400, resulting in many, many dropped packets. Some messages were getting through (which made it hard to diagnose), and sometimes even large messages were (eventually) getting through, but the fix was to revert the firewall change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM