无法查看我的示例Java应用程序的应用程序洞察数据,无法发送,意外异常:连接池关闭

时间:2016-10-29 20:49:14

标签: azure msdn azure-application-insights azure-java-sdk

我正在使用“hello world”类型的java应用程序将一些数据发送给应用程序洞察,但到目前为止还无法看到任何内容。 到目前为止我已按照说明操作了。在azure门户中创建了应用洞察资源,在我的应用程序中使用了该仪器键, 保持正确配置applicationinsight.xml,web.xml和pom.xml。但永远不能发送任何数据。以下是我的pom ......

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>test1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-web</artifactId>
            <!-- or applicationinsights-core for bare API -->
            <version>[1.0,)</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-core</artifactId>
            <!-- or applicationinsights-core for bare API -->
            <version>[1.0,)</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>central</id>
            <name>Central</name>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo>Using env.test.properties</echo>
                                <copy file="${basedir}/src/ApplicationInsights.xml" tofile="${basedir}/target/classes/ApplicationInsights.xml"/>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这是我的applicationinsight.xml ...

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
  <InstrumentationKey>my_key</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>
  <SDKLogger />
</ApplicationInsights>

这是我的示例代码

TelemetryClient tc = new TelemetryClient();
tc.getContext().setInstrumentationKey("my_key");
Map<String, String> properties = new HashMap<String, String>();

properties.put("Game", "GameName");
properties.put("Difficulty", "hard");
Map<String, Double> measurements = new HashMap<String, Double>();
measurements.put("GameScore", 20.0);
measurements.put("Opponents", 1.0);

try{
tc.trackEvent("WinGame", properties, measurements);
        tc.flush();
} catch (Exception e)
{
    e.printStackTrace();
}

以下是我每次运行应用程序时得到的日志,我是否缺少一些配置步骤?

AI: INFO 29-10-2016 13:18, 1: Configuration file has been successfully found as resource
AI: INFO 29-10-2016 13:18, 1: 'MaxTelemetryBufferCapacity': null value is replaced with '500'
AI: INFO 29-10-2016 13:18, 1: 'FlushIntervalInSeconds': null value is replaced with '5'
AI: TRACE 29-10-2016 13:18, 1: Using Http Client version 4.3+
AI: INFO 29-10-2016 13:18, 1: 'Channel.MaxTransmissionStorageCapacityInMB': null value is replaced with '10'
AI: ERROR 29-10-2016 13:18, 1: Failed to create empty class name
AI: TRACE 29-10-2016 13:18, 1: C:\Users\myuser\AppData\Local\Temp\AISDK\native\1.0.6 folder exists
AI: TRACE 29-10-2016 13:18, 1: Java process name is set to 'java#1'
AI: TRACE 29-10-2016 13:18, 1: Successfully loaded library 'applicationinsights-core-native-win64.dll'
AI: ERROR 29-10-2016 13:18, 1: Failed to create DeadLockDetector, exception: null
AI: ERROR 29-10-2016 13:18, 1: Failed to create JvmHeapMemoryUsedPerformanceCounter, exception: null
AI: TRACE 29-10-2016 13:18, 1: Registering PC 'JSDK_ProcessMemoryPerformanceCounter'
AI: TRACE 29-10-2016 13:18, 1: Registering PC 'JSDK_ProcessCpuPerformanceCounter'
AI: TRACE 29-10-2016 13:18, 1: Registering PC 'JSDK_WindowsPerformanceCounterAsPC'
AI: TRACE 29-10-2016 13:18, 1: InProcessTelemetryChannel sending telemetry
AI: ERROR 29-10-2016 13:18, 20: Failed to send, unexpected exception: Connection pool shut down

**** Update1:​​我在代码中的telemetryClient.flush()之前添加了Thread.sleep(7000),套接字异常消失了,但仍然没有应用程序洞察资源中的数据

**** Update2:编写了一个示例C#控制台应用程序来发送应用洞察数据,也没有运气。我正在使用Fiddler来监控流量。如果我看到一些有趣的出站HTTP请求,将会更新

**** Update3:在玩了一点fiddler和java(how to Capture https with fiddler, in java)后,我能够捕获到https://dc.services.visualstudio.com/v2/track的出站流量,但是在应用程序洞察资源中没有出现任何内容天蓝门户

2 个答案:

答案 0 :(得分:0)

您能否检查一下SDK的1.0.5版本是否也发生了这种情况,看看它是否是最新版SDK中的回归或特定于您应用场景的问题?

感谢

答案 1 :(得分:0)

它有效,有一个混乱,我发送自定义事件,但从门户网站我正在寻找请求事件,所以我没有看到任何东西。它对我来说非常好。