故障排除指南:适用于 Java 的 Azure Monitor Application InsightsTroubleshooting guide: Azure Monitor Application Insights for Java

本文介绍了使用 Application Insights 的 Java 代理来检测 Java 应用程序时可能会遇到的一些常见问题。In this article, we cover some of the common issues that you might face while instrumenting a Java application by using the Java agent for Application Insights. 本文还介绍了解决这些问题的步骤。We also cover the steps to resolve these issues. Application Insights 是 Azure Monitor 平台服务的一项功能。Application Insights is a feature of the Azure Monitor platform service.

检查自诊断日志文件Check the self-diagnostic log file

默认情况下,Application Insights 的 Java 3.0 代理在 applicationinsights-agent-3.0.2.jar 文件所在的目录中生成名为 applicationinsights.log 的日志文件。By default, the Java 3.0 agent for Application Insights produces a log file named applicationinsights.log in the same directory that holds the applicationinsights-agent-3.0.2.jar file.

针对你可能遇到的问题查找线索时,此日志文件是要检查的第一个位置。This log file is the first place to check for hints to any issues you might be experiencing.

JVM 无法启动JVM fails to start

如果 JVM 无法启动并显示“打开 zip 文件时出错或缺少 JAR 清单”,请尝试重新下载代理 jar 文件,因为它在文件传输过程中可能已损坏。If the JVM fails to start with "Error opening zip file or JAR manifest missing", try re-downloading the agent jar file because it may have been corrupted during file transfer.

从 Application Insights Java 2.x SDK 进行升级Upgrade from the Application Insights Java 2.x SDK

如果你已在应用程序中使用 Application Insights Java 2.x SDK,则可以继续使用它。If you're already using the Application Insights Java 2.x SDK in your application, you can keep using it. Java 3.0 代理会检测到它。The Java 3.0 agent will detect it. 有关详细信息,请参阅从 Java 2.x SDK 进行升级For more information, see Upgrade from the Java 2.x SDK.

从 Application Insights Java 3.0 预览版进行升级Upgrade from Application Insights Java 3.0 Preview

如果要从 Java 3.0 预览版代理进行升级,请仔细检查所有配置选项If you're upgrading from the Java 3.0 Preview agent, review all of the configuration options carefully. JSON 结构在 3.0 正式发布版 (GA) 中已完全更改。The JSON structure has completely changed in the 3.0 general availability (GA) release.

这些更改包括:These changes include:

  • 配置文件名称已从 ApplicationInsights.json 更改为 applicationinsights.jsonThe configuration file name has changed from ApplicationInsights.json to applicationinsights.json.
  • instrumentationSettings 节点不再存在。The instrumentationSettings node is no longer present. instrumentationSettings 中的所有内容已移动到根级别。All content in instrumentationSettings is moved to the root level.
  • samplingjmxMetricsinstrumentationheartbeat 等配置节点已从 preview 移出到根级别。Configuration nodes like sampling, jmxMetrics, instrumentation, and heartbeat are moved out of preview to the root level.

某些日志记录不是自动收集的Some logging is not auto-collected

仅当日志记录首先满足日志记录框架的配置阈值,并且还满足 Application Insights 的配置阈值时,才会捕获日志记录。Logging is only captured if it first meets the logging frameworks' configured threshold, and second also meets the Application Insights configured threshold.

若要了解某个特定的日志记录语句是否满足日志记录框架的已配置阈值,最好的方法是确认它是否显示在正常的应用程序日志(例如文件或控制台)中。The best way to know if a particular logging statement meets the logging frameworks' configured threshold is to confirm that it is showing up in your normal application log (e.g. file or console).

有关更多详细信息,请参阅自动收集的日志记录配置See the auto-collected logging configuration for more details.

导入 SSL 证书Import SSL certificates

如果使用的是默认的 Java 密钥存储,则它已具有所有 CA 根证书。If you're using the default Java keystore, it will already have all of the CA root certificates. 你应当不需要导入更多的 SSL 证书。You shouldn't need to import more SSL certificates.

如果使用的是自定义 Java 密钥存储,则你可能需要将 Application Insights 终结点 SSL 证书导入其中。If you're using a custom Java keystore, you might need to import the Application Insights endpoint SSL certificates into it.

关键术语Key terminology

“密钥存储”是证书、公钥和私钥的存储库。A keystore is a repository of certificates, public keys, and private keys. 通常,Java 开发工具包发行版具有用于管理它们的可执行文件:keytoolUsually, Java Development Kit distributions have an executable to manage them: keytool.

下面的示例是一个简单的命令,用于将 SSL 证书导入到密钥存储:The following example is a simple command to import an SSL certificate to the keystore:

keytool -importcert -alias your_ssl_certificate -file "your downloaded SSL certificate name".cer -keystore "Your KeyStore name" -storepass "Your keystore password" -noprompt

下载和添加 SSL 证书的步骤Steps to download and add an SSL certificate

  1. 打开你习惯使用的浏览器,然后转到用于检测应用程序的连接字符串中存在的 IngestionEndpoint URL。Open your favorite browser and go to the IngestionEndpoint URL present in the connection string that's used to instrument your application.

    屏幕截图显示了 Application Insights 连接字符串。

  2. 选择浏览器中的“查看站点信息”(锁)图标,然后选择“证书”选项。Select the View site information (lock) icon in the browser, and then select the Certificate option.

    屏幕截图显示了站点信息中的“证书”选项。

  3. 转到“详细信息”选项卡,然后选择“复制到文件”。Go to the Details tab and select Copy to file.

  4. 选择“下一步”按钮,选择“Base-64 编码的 X.509 (.CER)”格式,然后再次选择“下一步”。Select the Next button, select Base-64 encoded X.509 (.CER) format, and then select Next again.

    证书导出向导的屏幕截图,其中选择了一种格式。

  5. 指定要在其中保存 SSL 证书的文件。Specify the file where you want to save the SSL certificate. 然后,选择“下一步” > “完成”。 Then select Next > Finish. 应该会看到“导出成功”消息。You should see a "The export was successful" message.

  6. 获得证书后,即可将证书导入到 Java 密钥存储中。After you have the certificate, it's time to import the certificate into a Java keystore. 使用前面的命令来导入证书。Use the preceding command to import certificates.

警告

在当前证书到期之前,你需要重复这些步骤以获取新证书。You'll need to repeat these steps to get the new certificate before the current certificate expires. 可以在“证书”对话框的“详细信息”选项卡上找到到期信息。You can find the expiration information on the Details tab of the Certificate dialog box.

屏幕截图显示了 SSL 证书详细信息。