I just did what the documentation says.
https://docs.microsoft.com/ja-jp/azure/azure-monitor/app/java-agent
I feel like this.
This black-painted image is from a mysterious request that took 5 minutes to complete. You can see that the SQL query is executed 4 times and there are about 2 fucking queries. Clicking on any of the queries will bring up the SQL in the command on the right.
The content of SQL is Prepared SQL probably because it uses PreparedStatement, and it seems that you can not see it until the parameter is "?". (On the contrary, even if it is buried, confidential information may be visible, so I think this is fine) I don't even know the location of the called code. But if you are an implementer, it will be useful enough.
Of course, since the DB query information is sent to Application Insights, it takes a lot of transfer, so please be careful about that point.
--Java app --Application Insights has been installed
It seems that JavaAgent is used to modify the class file when reading the class with the class loader and write the telemetry.
All you have to do is embed the JavaAgent, so you can use it without modifying the running code.
--Download javaagent file
--Create AI-Agent.xml in the same location
--Add -javaagent: ...
to the JVM argument
--Application restart
The installation procedure is assumed to be on Azure Web App, but Java Web applications are not limited to Azure Web App and can be installed by just reading a little.
Since it is published at https://github.com/microsoft/ApplicationInsights-Java/releases/, insert the agent ** that matches the installed ** Application Insights version.
With Azure WebApp, operate like this on kudu. I think that it will not get in the way around D: \ home \ data
, but please change it as appropriate.
cd D:\home\data
curl -LO https://github.com/microsoft/ApplicationInsights-Java/releases/download/2.1.1/applicationinsights-agent-2.1.1.jar
ʻCreate a file called AI-Agent.xml` in the same location as the ** jar file you downloaded earlier **.
You can copy and paste the following contents.
AI-Agent.xml
<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsightsAgent>
<Instrumentation>
<BuiltIn enabled="true"> <!--Don't forget to look at the enabled attribute here as well.-->
<JDBC enabled="true" /> <!--Send query execution time and prepared SQL telemetry when querying with JDBC-->
</BuiltIn>
</Instrumentation>
</ApplicationInsightsAgent>
This time it is only JDBC, but it seems that you can trace some HTTP calls etc. in the settings.
-javaagent: ...
to the JVM argumentAdd the following to the JVM arguments: Replace the file path as appropriate.
-javaagent:D:/home/data/applicationinsights-agent-2.1.1.jar
For apps that run on Tomcat, the environment variables JAVA_OPTS
and CATALINA_OPTS
are fine.
For Azure Web App, use application settings or web.config from kudu. However, ** application settings take precedence **, so please take that into consideration.
A reboot is required for the javaagent to load.
that's all.
At present, it seems that it is not possible to send only when it takes time.
For example, a query that is known to be fast enough, or if you are using connection pooling, telemetry will be sent even with SELECT 1
when checking for rotting when taken out of the pool.
If you want to prevent it, you need to write a filter. The following issue has an implementation example of Telemetry Processor.
Reference: https://github.com/microsoft/ApplicationInsights-Java/issues/837#issuecomment-471610584
Recommended Posts