我在Azure中有一个Java Web应用程序,它使用Logback进行跟踪日志记录。我正在尝试将跟踪日志记录链接到Azure中的Application Insights,并且我已按照Azure documentation中的所有说明进行操作。
以下是Maven pom.xml
的相关部分:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-web</artifactId>
<version>[1.0,)</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-core</artifactId>
<version>[1.0,)</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-logging-logback</artifactId>
<version>[1.0,)</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<name>Central</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
我的ApplicationInsights.xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE xml>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
<SDKLogger />
<InstrumentationKey>*my key here*</InstrumentationKey>
<ContextInitializers>
</ContextInitializers>
<TelemetryInitializers>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationIdTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebOperationNameTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebSessionTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserTelemetryInitializer"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.initializers.WebUserAgentTelemetryInitializer"/>
</TelemetryInitializers>
<TelemetryModules>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebRequestTrackingTelemetryModule"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebSessionTrackingTelemetryModule"/>
<Add type="com.microsoft.applicationinsights.web.extensibility.modules.WebUserTrackingTelemetryModule"/>
</TelemetryModules>
<Channel>
<!--
Setting DeveloperMode to true will enable immediate transmission of the telemetry events, which can be helpful during the development process.
Make sure to turn this off on production servers due to performance considerations.
-->
<DeveloperMode>true</DeveloperMode>
</Channel>
<DisableTelemetry>false</DisableTelemetry>
</ApplicationInsights>
我的logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<configuration debug = "true">
<appender class="ch.qos.logback.core.ConsoleAppender" name="STDOUT">
<encoder>
<Pattern>%d{HH:mm:ss.SSS} %-5level - %msg%n</Pattern>
</encoder>
</appender>
<appender name="aiAppender" class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender">
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="aiAppender"/>
</root>
</configuration>
我的课程测试记录器和应用程序见解集成:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.microsoft.applicationinsights.TelemetryClient;
/**
* Hello world!
*
*/
public class App
{
private final static Logger LOG = LoggerFactory.getLogger("root");
public static void main( String[] args ) throws InterruptedException
{
LOG.info("Logging is working");
TelemetryClient tc = new TelemetryClient();
tc.trackTrace("Telemetry is working");
System.out.println( "Hello World!" );
}
}
当我运行它时,Logback可以正常使用控制台appender,遥测到应用程序洞察可以正常工作,但跟踪日志不会进入应用程序洞察门户。我收到以下错误:
AI:ERROR 18-10-2017 20:40,19:发送失败,错误请求: {&#34; itemsReceived&#34;:1,&#34; itemsAccepted&#34;:0,&#34;错误&#34;:[{&#34;指数&#34;:0,&#34;的StatusCode& #34; 400&#34;消息&#34;:&#34;语法错误: 意外的令牌I&#34;}]}
我已经搜索了这个问题的解决方案,但我似乎无法解决这个问题。有没有人有任何想法?谢谢!
更新
这是完整的堆栈跟踪:
09:13:59,774 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 无法找到资源[logback.groovy]
09:13:59,774 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 无法找到资源[logback-test.xml]
09:13:59,774 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 在[file:/ C:/ Users / greta / OneDrive / Eclipse%20Water%20Application%20Project]找到资源[logback.xml] %20Files / Test2的/目标/类/ logback.xml]
09:13:59,888 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 即将实例化类型为[ch.qos.logback.core.ConsoleAppender]的appender
09:13:59,891 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 将appender命名为[STDOUT]
09:13:59,911 | -INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - 假设[encoder]属性的默认类型[ch.qos.logback.classic.encoder.PatternLayoutEncoder]
09:13:59,943 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 即将实例化[com.microsoft.applicationinsights.logback.ApplicationInsightsAppender]类型的appender
09:13:59,988 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 将appender命名为[aiAppender]
AI:INFO 20-10-2017 09:14,1:配置文件已成功找到资源
AI:INFO 20-10-2017 09:14,1:&#39; MaxTelemetryBufferCapacity&#39 ;:空值被替换为&#39; 500&#39;
AI:INFO 20-10-2017 09:14,1:&#39; FlushIntervalInSeconds&#39;:空值被替换为&#39; 5&#39;
AI:TRACE 20-10-2017 09:14,1:使用Http Client版本4.3+
AI:INFO 20-10-2017 09:14,1:&#39; Channel.MaxTransmissionStorageCapacityInMB&#39 ;:空值被替换为&#39; 10&#39;
AI:TRACE 20-10-2017 09:14,1:C:\ Users \ greta \ AppData \ Local \ Temp \ AISDK \ native \ 1.0.10文件夹存在
AI:TRACE 20-10-2017 09:14,1:Java进程名称设置为&#39; javaw&#39;
AI:TRACE 20-10-2017 09:14,1:成功加载了库&applicationins -core-native-win64.dll&#39;
AI:INFO 20-10-2017 09:14,1:配置文件已成功找到资源
AI:INFO 20-10-2017 09:14,1:&#39; MaxTelemetryBufferCapacity&#39 ;:空值被替换为&#39; 500&#39;
AI:INFO 20-10-2017 09:14,1:&#39; FlushIntervalInSeconds&#39;:空值被替换为&#39; 5&#39;
AI:INFO 20-10-2017 09:14,1:&#39; Channel.MaxTransmissionStorageCapacityInMB&#39 ;:空值被替换为&#39; 10&#39;
AI:TRACE 20-10-2017 09:14,1:C:\ Users \ greta \ AppData \ Local \ Temp \ AISDK \ native \ 1.0.10文件夹存在
AI:TRACE 20-10-2017 09:14,1:Java进程名称设置为&#39; javaw&#39;
AI:TRACE 20-10-2017 09:14,1:成功加载了库&applicationins -core-native-win64.dll&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; DeadLockDetector&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JvmHeapMemoryUsedPerformanceCounter&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JSDK_ProcessMemoryPerformanceCounter&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JSDK_ProcessCpuPerformanceCounter&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JSDK_WindowsPerformanceCounterAsPC&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; DeadLockDetector&#39;
AI:TRACE 20-10-2017 09:14,1:无法存储性能计数器&#39; DeadLockDetector&#39;,因为已经有一个
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JvmHeapMemoryUsedPerformanceCounter&#39;
AI:TRACE 20-10-2017 09:14,1:无法存储性能计数器&#39; JvmHeapMemoryUsedPerformanceCounter&#39;,因为已经有一个
AI:ERROR 20-10-2017 09:14,1:无法创建WindowsPerformanceCounterAsPC:&#39;无法注册所有内置Windows性能计数器。&#39;
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JSDK_ProcessMemoryPerformanceCounter&#39;
AI:TRACE 20-10-2017 09:14,1:无法存储性能计数器&#39; JSDK_ProcessMemoryPerformanceCounter&#39;,因为已经有一个
AI:TRACE 20-10-2017 09:14,1:注册PC&#39; JSDK_ProcessCpuPerformanceCounter&#39;
AI:TRACE 20-10-2017 09:14,1:无法存储性能计数器&#39; JSDK_ProcessCpuPerformanceCounter&#39;,因为已经有一个
09:14:01,943 | -INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - 将ROOT记录器的级别设置为INFO
09:14:01,943 | -INFO in ch.qos.logback.core.joran.action.AppenderRefAction - 将名为[STDOUT]的appender附加到Logger [ROOT]
09:14:01,944 | -INFO in ch.qos.logback.core.joran.action.AppenderRefAction - 将名为[aiAppender]的appender附加到Logger [ROOT]
09:14:01,944 | -INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - 配置结束。
09:14:01,945 | -INFO in ch.qos.logback.classic.joran.JoranConfigurator@6b415f5f - 将当前配置注册为安全回退点
09:13:59,774 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 无法找到资源[logback.groovy]
09:13:59,774 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 无法找到资源[logback-test.xml]
09:13:59,774 | -INFO in ch.qos.logback.classic.LoggerContext [default] - 在[file:/ C:/ Users / greta / OneDrive / Eclipse%20Water%20Application%20Project]找到资源[logback.xml] %20Files / Test2的/目标/类/ logback.xml]
09:13:59,888 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 即将实例化类型为[ch.qos.logback.core.ConsoleAppender]的appender
09:13:59,891 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 将appender命名为[STDOUT]
09:13:59,911 | -INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - 假设[encoder]属性的默认类型[ch.qos.logback.classic.encoder.PatternLayoutEncoder]
09:13:59,943 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 即将实例化[com.microsoft.applicationinsights.logback.ApplicationInsightsAppender]类型的appender
09:13:59,988 | -INFO in ch.qos.logback.core.joran.action.AppenderAction - 将appender命名为[aiAppender]
09:14:01,943 | -INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - 将ROOT记录器的级别设置为INFO
09:14:01,943 | -INFO in ch.qos.logback.core.joran.action.AppenderRefAction - 将名为[STDOUT]的appender附加到Logger [ROOT]
09:14:01,944 | -INFO in ch.qos.logback.core.joran.action.AppenderRefAction - 将名为[aiAppender]的appender附加到Logger [ROOT]
09:14:01,944 | -INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - 配置结束。
09:14:01,945 | -INFO in ch.qos.logback.classic.joran.JoranConfigurator@6b415f5f - 将当前配置注册为安全回退点
09:14:01.948信息 - 记录正在工作中 AI:TRACE 20-10-2017 09:14,1:InProcessTelemetryChannel发送遥测信号 AI:TRACE 20-10-2017 09:14,1:InProcessTelemetryChannel发送遥测信号 Hello World!
AI:ERROR 20-10-2017 09:14,19:发送失败,错误请求:{&#34; itemsReceived&#34;:1,&#34; itemsAccepted&#34;:0,&#34;错误&# 34;:[{&#34;索引&#34;:0,&#34; statusCode&#34;:400,&#34;消息&#34;:&#34;语法错误:意外的令牌I&#34;}] }
性能计数器存在一些错误。我试着找一些关于这些错误的信息,但没有太多运气。也许这就是问题的一部分?
答案 0 :(得分:1)
我在这里可以看到的一个问题是AI的内部记录器报告了意外的特征。我发现其中一个可能的问题是清理逻辑中存在一些问题,这会阻止项目发送到终点,因此您无法在门户上看到数据。还有一些已知的logback问题已在github上提到: https://github.com/Microsoft/ApplicationInsights-Java/issues/453 这应该回答你的问题。如果您愿意,可以随时在Github上创建另一个问题。希望下一次公开发布应该解决这个问题。
答案 1 :(得分:1)
作为更新,Windows开发人员中心论坛上的某个人在Github上指出了一个条目:https://github.com/Microsoft/ApplicationInsights-Java/issues/436。我降级到版本1.0.9,这解决了我的问题。
答案 2 :(得分:1)
新版Application Insights Java SDK 2.0.0-BETA现已发布。请尝试将您的应用程序依赖项更新为最新版本并尝试。我相信这个问题已经解决了。除此之外,您还可以获得许多最新功能和错误修复!