2017-10-19 75 views
3

我在Azure中有一个使用Logback进行跟踪日志记录的Java web应用程序。我试图将跟踪日志记录链接到Azure中的Application Insights,并且我遵循了Azure documentation中的所有操作说明。将Logback跟踪日志发送到Azure应用程序洞察 - 错误:无法发送,请求不正确

这里是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: Failed to send, Bad request : {"itemsReceived":1,"itemsAccepted":0,"errors":[{"index":0,"statusCode":400,"message":"SyntaxError: Unexpected token I"}]}

我已经搜索了高和低的解决方案,但我似乎无法解决这个问题。有没有人有任何想法?谢谢!!

更新:

以下是完整的堆栈跟踪:

09:13:59,774 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:13:59,774 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:13:59,774 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/greta/OneDrive/Eclipse%20Water%20Application%20Project%20Files/Test2/target/classes/logback.xml]
09:13:59,888 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:13:59,891 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
09:13:59,911 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:13:59,943 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [com.microsoft.applicationinsights.logback.ApplicationInsightsAppender]
09:13:59,988 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [aiAppender]
AI: INFO 20-10-2017 09:14, 1: Configuration file has been successfully found as resource
AI: INFO 20-10-2017 09:14, 1: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 20-10-2017 09:14, 1: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: TRACE 20-10-2017 09:14, 1: Using Http Client version 4.3+
AI: INFO 20-10-2017 09:14, 1: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
AI: TRACE 20-10-2017 09:14, 1: C:\Users\greta\AppData\Local\Temp\AISDK\native\1.0.10 folder exists
AI: TRACE 20-10-2017 09:14, 1: Java process name is set to 'javaw'
AI: TRACE 20-10-2017 09:14, 1: Successfully loaded library 'applicationinsights-core-native-win64.dll'
AI: INFO 20-10-2017 09:14, 1: Configuration file has been successfully found as resource
AI: INFO 20-10-2017 09:14, 1: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 20-10-2017 09:14, 1: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: INFO 20-10-2017 09:14, 1: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
AI: TRACE 20-10-2017 09:14, 1: C:\Users\greta\AppData\Local\Temp\AISDK\native\1.0.10 folder exists
AI: TRACE 20-10-2017 09:14, 1: Java process name is set to 'javaw'
AI: TRACE 20-10-2017 09:14, 1: Successfully loaded library 'applicationinsights-core-native-win64.dll'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'DeadLockDetector'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JvmHeapMemoryUsedPerformanceCounter'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JSDK_WindowsPerformanceCounterAsPC'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'DeadLockDetector'
AI: TRACE 20-10-2017 09:14, 1: Failed to store performance counter 'DeadLockDetector', since there is already one
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JvmHeapMemoryUsedPerformanceCounter'
AI: TRACE 20-10-2017 09:14, 1: Failed to store performance counter 'JvmHeapMemoryUsedPerformanceCounter', since there is already one
AI: ERROR 20-10-2017 09:14, 1: Failed to create WindowsPerformanceCounterAsPC: 'Failed to register all built-in Windows performance counters.'
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 20-10-2017 09:14, 1: Failed to store performance counter 'JSDK_ProcessMemoryPerformanceCounter', since there is already one
AI: TRACE 20-10-2017 09:14, 1: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 20-10-2017 09:14, 1: Failed to store performance counter 'JSDK_ProcessCpuPerformanceCounter', since there is already one
09:14:01,943 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
09:14:01,943 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
09:14:01,944 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [aiAppender] to Logger[ROOT]
09:14:01,944 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:14:01,945 |-INFO in [email protected] - Registering current configuration as safe fallback point
09:13:59,774 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:13:59,774 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:13:59,774 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/Users/greta/OneDrive/Eclipse%20Water%20Application%20Project%20Files/Test2/target/classes/logback.xml]
09:13:59,888 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:13:59,891 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
09:13:59,911 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:13:59,943 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [com.microsoft.applicationinsights.logback.ApplicationInsightsAppender]
09:13:59,988 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [aiAppender]
09:14:01,943 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
09:14:01,943 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
09:14:01,944 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [aiAppender] to Logger[ROOT]
09:14:01,944 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:14:01,945 |-INFO in [email protected] - Registering current configuration as safe fallback point
09:14:01.948 INFO - Logging is working
AI: TRACE 20-10-2017 09:14, 1: InProcessTelemetryChannel sending telemetry
AI: TRACE 20-10-2017 09:14, 1: InProcessTelemetryChannel sending telemetry
Hello World!
AI: ERROR 20-10-2017 09:14, 19: Failed to send, Bad request : {"itemsReceived":1,"itemsAccepted":0,"errors":[{"index":0,"statusCode":400,"message":"SyntaxError: Unexpected token I"}]}

没有与性能计数器相关的一些错误。我试图找到这些错误的一些信息,但没有太多的运气。也许这是问题的一部分?

+0

我厌倦了重现您的问题。test.class在本地工作正常吗?请您发布完整的跟踪日志吗? –

+0

@JayGong,我添加了堆栈跟踪作为更新。感谢您的帮助! – Greta

回答

1

我在这里可以看到的其中一个问题是AI的内部记录器报告出乎意料的字符。我发现其中一个可能的问题是,在清理逻辑中存在一些问题,并且无法将项目发送到终点,因此您无法在门户网站上看到数据。还有一些已知的logback问题已经在github上提到过: https://github.com/Microsoft/ApplicationInsights-Java/issues/453 这应该回答你的问题。如果您愿意,可以随时在Github上创建另一个问题。希望下一个公开发布应该解决这个问题。

+0

虽然这个链接可能回答这个问题,但最好在这里包含答案的基本部分,并提供参考链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/17697274) – daniele3004

+0

请不要添加“谢谢”作为答案。一旦你有足够的[声誉](https://stackoverflow.com/help/whats-reputation),你就可以[提出问题和答案](https://stackoverflow.com/help/privileges/vote- )你发现有帮助。 - [来自评论](/ review/low-quality-posts/17697274) – user1155120

1

新版本的Application Insights Java SDK 2.0.0-BETA现已发布。请尝试将您的应用程序依赖关系更新到最新版本并尝试。我相信这个问题已经解决了。除此之外,您还可以获得许多最新功能和错误修复!

相关问题