java – 将Logback跟踪日志发送到Azure应用程序洞察 – 错误:发送失败,请求错误

我在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: 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 ch.qos.logback.classic.joran.JoranConfigurator@6b415f5f – 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 ch.qos.logback.classic.joran.JoranConfigurator@6b415f5f – 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”}]}

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

解决方法:

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

原文地址:https://codeday.me/bug/20190627/1305910.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Microsoft云包括了Azure、PowerPlatform、Microsoft365、GitHub、Dynamics365等,虽然许多企业应用程序开发领导者了解在Azure上创建应用程序的价值,但事实是您可以将整个Microsoft云作为应用程序平台.有一篇文章:在Microsoft云上构建应用程序从应用程序开发角度介绍了M
《WindowsAzurePlatform系列文章目录》 我们在使用AzureAPIManagement(APIM)实现服务网关的时候,一般都是面向互联网的。比如场景一:AzureAPIManagement保护AzureVM上部署的ApacheWebService,客户端是来自于Internet的用户。整体的数据流是:用户->I
微软免费使用一年的Azure虚拟机,默认提供了一个64G的磁盘,但是系统却只给分配了32个G,尝试了几次扩大分区,最终都导致系统崩溃了,只能重新开虚拟机,无奈,只好网上找来现成的脚本,自动调整分区大小,只需要输入想调整为多少G即可,终于成功把系统分区扩大了。更改分区大小的脚本:if[[$#-eq
2022年5月25日,Meta公司选择Azure作为战略云供应商,推进人工智能创新,深化PyTorch合作https://azure.microsoft.com/en-us/blog/meta-selects-azure-as-strategic-cloud-provider-to-advance-ai-innovation-and-deepen-pytorch-collaboration/微软致力于负责任地推进人工智能的
上篇请访问这里做一个能对标阿里云的前端APM工具(上)样本多样性问题上一小节中的实施方案是微观的,即单次性的、具体的。但是从宏观上看,我需要保证性能测试是公允的,符合大众预期的。为了达到这种效果,最简单的方式就是保证测试的多样性,让足够多人访问产生足够多的样本来,但这对于一个
一年一度的MicrosoftBuild终于来了,带来了非常非常多的新技术和功能更新。不知道各位小伙伴有没有和我一样熬夜看了开幕式和五个核心主题的全过程呢?接下来我和大家来谈一下作为开发者最应关注的七大方向技术更新。AI能力的提升1.AzureOpenAIService终于来了开发人员可
问题描述使用AzureStorageAccount的共享访问签名(ShareAccessSignature)生成的终结点,连接时遇见  TheAzureStorageendpointurlismalformed(Azure存储终结点URL格式不正确)StorageAccountSDKinpom.xml:<dependency><groupId>com.azure</groupI
Azure提供的负载均衡服务叫LoadBalancer,它工作在ISO七层模型的第四层,通过分析IP层及传输层(TCP/UDP)的流量实现基于"IP+端口"的负载均衡。AzureLoadBalancer的主要功能负载均衡基于ISO四层的负载均衡,请参考下图(此图来自互联网):端口转发通过创建入站NAT规则,
各位好,今天继续来讨论关于Azure平台的技术问题,这次我们来讨论关于监控的话题,各个云平台都会为用户预留获取监控数据的接口,Azure也不例外,拿最基础用法来说,用户可以从AzurePortal中获取所需要的监控信息,比如Azure虚拟机的磁盘IO,CPU百分比,内存等,除此之外,还可以通过定义各种action,针对
在以往我们创建高可用Web应用程序时,负载均衡器是必不可少的组件。我们都使用传统内部服务器的负载均衡器,其中我们的应用程序在N个实例上运行,负载均衡器位于这些服务器的前面,并根据某些预定义的算法和设置向后端服务器分配负载。迁移到云中,我们需要了解如何使用Azure组件实现相同的
AzureEventGrid是一个托管事件路由平台,使我们能够实时响应Azure中托管的应用程序或拥有的任何Azure资源中发生的更改。EventGrid处理来自Azure服务的内置Azure事件以及来自应用程序的自定义事件,并实时发布它们。它可以每秒动态扩展和处理数百万个事件,Azure为生产工作负载提供99.
今天来谈一谈automation中另外一个很关键的内容,也就是updatemanagement,不同于configurationmanagement,updatemanagement主要用于管理windows以及LinuxVM中的补丁内容,当然和configurationmanagement一样,updatemanagement不仅仅可以管理Windows中VM的补丁,也可以管理non-Azure
下边来谈一谈Azure中Alert更多的应用,正常来说,云厂商都会有自己的SLA保证,比如目前来说,在可用性集里的虚拟机,SLA是99.95%,这点可以从商务角度保护客户的一部分利益。但是,从技术上来说,任何云都不可能保证100%的可用性,所以有些时候也会出现一些service的outage,对用户来说,第一时间知晓这
MicrosoftAzure中提供了多种类型和大小的虚拟机,我们将通过本来来了解下微软具体提供了哪些类型和大小的虚拟机,以方便在项目过程中进行评估。类型大小说明常规用途B,Dsv3,Dv3, DSv2,Dv2,Av2, DCCPU 与内存之比平衡。适用于测试和开发、小到中型数据库和低到中等流量Web
假定我们正在运行某个应用程序,此应用程序需要用户在应用程序中提交大量图片文件,那么对于系统管理员来说手动审核这些图片是很消耗时间的,并且对于图片的审核也许并不是即时的。为了解决这一问题,这篇文章将向大家演示如何使用AzureFunction和CognitiveServices来对上传到应用程序的
中国-北京[2018.12.10]2018年12月7日,历时60余天,在超过150+的面试中,21家企业经三轮筛选晋级终审,最终14家企业在激烈的角逐中成功入选微软加速器·北京13期创新企业名单。颉一软件有幸拔得头筹,很快将与MicrosoftAzure开展深度合作,开启全面加速企业级用户数字化转型之路!微软加速器·
假定我们有某个应用程序会将文件存储到AzureBlob中,存储在Blob中的数据保存七天,七天以后需要对其进行删除。这需求可以使用AzurePowerShellRunbook来完成,但是我想看看是否可以用很少甚至没有代码来完成。经过一番探索我发现AzureLogicApp非常适合这种情况。你可以用LogicApp创
接下来继续之前给各位介绍的内容,我们接着来谈下Azureautomation中关于configurationmanagement的内容,上一篇中介绍了关于inventory的应用,通过inventory,可以快速收集Azure与非Azure服务器中的资产信息。除此之外,configurationmanagement中changetracking也是个非常实用的功能,通
安全分层方法 数据几乎所有情况下,攻击者都会攻击以下数据:存储在数据库中的数据存储在虚拟机磁盘上的数据存储在Office365等SaaS应用程序上的数据存储在云存储中的数据存储数据和控制数据访问权限的人员有责任确保数据得到恰当保护。通常情况下,存在相应法规要
生成云应用程序时需要应对的常见挑战是,如何管理代码中用于云服务身份验证的凭据。保护这些凭据是一项重要任务。理想情况下,这些凭据永远不会出现在开发者工作站上,也不会被签入源代码管理系统中。虽然AzureKeyVault可用于安全存储凭据、机密以及其他密钥,但代码需要通过KeyVa