0

我正在使用“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),并且套接字异常消失了,但application-insight资源中仍然没有数据

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

****Update3:在玩了一点提琴手和java之后(如何在java中使用fiddler捕获https)我能够捕获到https://dc.services.visualstudio.com/v2/track的出站流量,但在 azure 门户中的应用程序洞察资源中尚未显示任何内容

4

2 回答 2

0

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

谢谢

于 2016-10-30T06:14:39.007 回答
0

它有效,有一个混乱,我正在发送自定义事件,但我正在从门户中寻找请求事件,所以我什么也没看到。它对我来说绝对没问题。

于 2016-11-01T00:26:09.797 回答