|
| 1 | +--- |
| 2 | +title: Monitor Java applications anywhere - Azure Monitor Application Insights |
| 3 | +description: Codeless application performance monitoring for Java applications running in any environment without instrumenting the app. Find the root cause of the issues d using distributed tracing and application map. |
| 4 | +ms.topic: conceptual |
| 5 | +ms.date: 04/16/2020 |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +# Configuration options - Java standalone agent for Azure Monitor Application Insights |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Connection string and role name |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "instrumentationSettings": { |
| 18 | + "connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000", |
| 19 | + "preview": { |
| 20 | + "roleName": "my cloud role name" |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +The connection string is required, and the role name is important any time you are sending data from different applications to the same Application Insights resource. |
| 27 | + |
| 28 | +You will find more details and additional configuration options below for more details. |
| 29 | + |
| 30 | +## Configuration file path |
| 31 | + |
| 32 | +By default, Application Insights Java 3.0 Preview expects the configuration file to be named `ApplicationInsights.json`, and to be located in the same directory as `applicationinsights-agent-3.0.0-PREVIEW.jar`. |
| 33 | + |
| 34 | +You can specify your own configuration file path using either |
| 35 | + |
| 36 | +* `APPLICATIONINSIGHTS_CONFIGURATION_FILE` environment variable, or |
| 37 | +* `applicationinsights.configurationFile` Java system property |
| 38 | + |
| 39 | +If you specify a relative path, it will be resolved relative to the directory where `applicationinsights-agent-3.0.0-PREVIEW.jar` is located. |
| 40 | + |
| 41 | +## Connection string |
| 42 | + |
| 43 | +This is required. You can find your connection string in your Application Insights resource: |
| 44 | + |
| 45 | +:::image type="content" source="media/java-ipa/connection-string.png" alt-text="Application Insights Connection String"::: |
| 46 | + |
| 47 | +You can also set the connection string using the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING`. |
| 48 | + |
| 49 | +## Cloud role name |
| 50 | + |
| 51 | +Cloud role name is used to label the component on the application map. |
| 52 | + |
| 53 | +If you want to set the cloud role name: |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "instrumentationSettings": { |
| 58 | + "preview": { |
| 59 | + //Set the cloud role name here: |
| 60 | + "roleName": "my cloud role name" |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +If cloud role name is not set, the Application Insights resource's name will be used to label the component on the application map. |
| 67 | + |
| 68 | +You can also set the cloud role name using the environment variable `APPLICATIONINSIGHTS_ROLE_NAME`. |
| 69 | + |
| 70 | +## Cloud role instance |
| 71 | + |
| 72 | +Cloud role instance defaults to the machine name. |
| 73 | + |
| 74 | +If you want to set the cloud role instance to something different rather than the machine name: |
| 75 | + |
| 76 | +```json |
| 77 | +{ |
| 78 | + "instrumentationSettings": { |
| 79 | + "preview": { |
| 80 | + //Set the cloud instance here: |
| 81 | + "roleInstance": "my cloud role instance" |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +You can also set the cloud role instance using the environment variable `APPLICATIONINSIGHTS_ROLE_INSTANCE`. |
| 88 | + |
| 89 | +## Application log capture |
| 90 | + |
| 91 | +Application Insights Java 3.0 Preview automatically captures application logging via Log4j, Logback, and java.util.logging. |
| 92 | + |
| 93 | +By default it will capture all logging performed at `WARN` level or above. |
| 94 | + |
| 95 | +If you want to change this threshold: |
| 96 | + |
| 97 | +```json |
| 98 | +{ |
| 99 | + "instrumentationSettings": { |
| 100 | + "preview": { |
| 101 | + "instrumentation": { |
| 102 | + //Set logging threshold here |
| 103 | + "logging": { |
| 104 | + "threshold": "error" |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +These are the valid `threshold` values that you can specify in the `ApplicationInsights.json` file, and how they correspond to logging levels across different logging frameworks: |
| 113 | + |
| 114 | +| `threshold` | Log4j | Logback | JUL | |
| 115 | +|--------------|--------|---------|---------| |
| 116 | +| OFF | OFF | OFF | OFF | |
| 117 | +| FATAL | FATAL | ERROR | SEVERE | |
| 118 | +| ERROR/SEVERE | ERROR | ERROR | SEVERE | |
| 119 | +| WARN/WARNING | WARN | WARN | WARNING | |
| 120 | +| INFO | INFO | INFO | INFO | |
| 121 | +| CONFIG | DEBUG | DEBUG | CONFIG | |
| 122 | +| DEBUG/FINE | DEBUG | DEBUG | FINE | |
| 123 | +| FINER | DEBUG | DEBUG | FINER | |
| 124 | +| TRACE/FINEST | TRACE | TRACE | FINEST | |
| 125 | +| ALL | ALL | ALL | ALL | |
| 126 | + |
| 127 | +## JMX metrics |
| 128 | + |
| 129 | +If you have some JMX metrics that you are interested in capturing: |
| 130 | + |
| 131 | +```json |
| 132 | +{ |
| 133 | + "instrumentationSettings": { |
| 134 | + "preview": { |
| 135 | + //Configure the JMX metrics here: |
| 136 | + "jmxMetrics": [ |
| 137 | + { |
| 138 | + "objectName": "java.lang:type=ClassLoading", |
| 139 | + "attribute": "LoadedClassCount", |
| 140 | + "display": "Loaded Class Count" |
| 141 | + }, |
| 142 | + { |
| 143 | + "objectName": "java.lang:type=MemoryPool,name=Code Cache", |
| 144 | + "attribute": "Usage.used", |
| 145 | + "display": "Code Cache Used" |
| 146 | + } |
| 147 | + ] |
| 148 | + } |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +## Micrometer |
| 154 | + |
| 155 | +By default, if your application uses [Micrometer](https://micrometer.io), Application Insights 3.0 (starting with Preview.2) now adds itself to the Micrometer global registry and captures Micrometer metrics. |
| 156 | + |
| 157 | +If you want to disable this feature: |
| 158 | + |
| 159 | +```json |
| 160 | +{ |
| 161 | + "instrumentationSettings": { |
| 162 | + "preview": { |
| 163 | + "instrumentation": { |
| 164 | + //To disable Micrometer: |
| 165 | + "micrometer": { |
| 166 | + "enabled": false |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +## Heartbeat |
| 175 | + |
| 176 | +By default, Application Insights Java 3.0 Preview sends a heartbeat metric once every 15 minutes. If you are using the heartbeat metric to trigger alerts, you can increase the frequency of this heartbeat: |
| 177 | + |
| 178 | +```json |
| 179 | +{ |
| 180 | + "instrumentationSettings": { |
| 181 | + "preview": { |
| 182 | + //Adjust the heartbeat frequency here: |
| 183 | + "heartbeat": { |
| 184 | + "intervalSeconds": 60 |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | +} |
| 189 | +``` |
| 190 | + |
| 191 | +> [!NOTE] |
| 192 | +> Note: You cannot decrease the frequency of this heartbeat, as the heartbeat data is also used to track Application Insights usage. |
| 193 | +
|
| 194 | +## Sampling |
| 195 | + |
| 196 | +Sampling is helpful if you need to reduce cost. |
| 197 | + |
| 198 | +Sampling is performed as a function on the operation id (also known as trace id), so that the same operation id will always result in the same sampling decision. This ensures that you won't get parts of a distributed transaction sampled in while other parts of it are sampled out. |
| 199 | + |
| 200 | +For example, if you set sampling to 10%, you will only see 10% of your transactions, but each one of those 10% will have full end-to-end transaction details. |
| 201 | + |
| 202 | +To enable sampling: |
| 203 | + |
| 204 | +```json |
| 205 | +{ |
| 206 | + "instrumentationSettings": { |
| 207 | + "preview": { |
| 208 | + //Set the sampling rate here. |
| 209 | + //below is an example how to set the sampling to 10% of all trnsactions |
| 210 | + "sampling": { |
| 211 | + "fixedRate": { |
| 212 | + "percentage": 10 |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + } |
| 217 | +} |
| 218 | +``` |
| 219 | + |
| 220 | +## HTTP Proxy |
| 221 | + |
| 222 | +If your application is behind a firewall and cannot connect directly to Application Insights (see [IP addresses used by Application Insights](https://docs.microsoft.com/azure/azure-monitor/app/ip-addresses)), you can configure Application Insights Java 3.0 Preview to use an HTTP Proxy: |
| 223 | + |
| 224 | +```json |
| 225 | +{ |
| 226 | + "instrumentationSettings": { |
| 227 | + "preview": { |
| 228 | + //Set the HTTP proxy: |
| 229 | + "httpProxy": { |
| 230 | + "host": "myproxy", |
| 231 | + "port": 8080 |
| 232 | + } |
| 233 | + } |
| 234 | + } |
| 235 | +} |
| 236 | +``` |
| 237 | + |
| 238 | +## Self-diagnostics |
| 239 | + |
| 240 | +"Self-diagnostics" refers to internal logging from Application Insights Java 3.0 Preview. |
| 241 | + |
| 242 | +This can be helpful for spotting and diagnosing issues with Application Insights itself. |
| 243 | + |
| 244 | +By default, it logs to console with level `warn`, corresponding to this configuration: |
| 245 | + |
| 246 | +```json |
| 247 | +{ |
| 248 | + "instrumentationSettings": { |
| 249 | + "preview": { |
| 250 | + //SelfDiagnostic configuration |
| 251 | + "selfDiagnostics": { |
| 252 | + "destination": "console", |
| 253 | + "level": "WARN" |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | +} |
| 258 | +``` |
| 259 | + |
| 260 | +Valid levels are `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG`, and `TRACE`. |
| 261 | + |
| 262 | +If you want to log to a file instead of logging to console: |
| 263 | + |
| 264 | +```json |
| 265 | +{ |
| 266 | + "instrumentationSettings": { |
| 267 | + "preview": { |
| 268 | + //To log the output from self diagnostics to a file |
| 269 | + "selfDiagnostics": { |
| 270 | + "destination": "file", |
| 271 | + "directory": "/var/log/applicationinsights", |
| 272 | + "level": "WARN", |
| 273 | + "maxSizeMB": 10 |
| 274 | + } |
| 275 | + } |
| 276 | + } |
| 277 | +} |
| 278 | +``` |
| 279 | + |
| 280 | +When using file logging, once the file hits `maxSizeMB`, it will rollover, keeping just the most recently completed log file in addition to the current log file. |
0 commit comments