You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/app/java-in-process-agent.md
+48-51Lines changed: 48 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Azure Monitor Application Insights Java
3
-
description: Application performance monitoring for Java applications running in any environment without requiring code modification. Distributed tracing and application map.
3
+
description: Application performance monitoring for Java applications running in any environment without requiring code modification. The article also discusses distributed tracing and the application map.
4
4
ms.topic: conceptual
5
5
ms.date: 12/14/2022
6
6
ms.devlang: java
@@ -10,19 +10,21 @@ ms.reviewer: mmcc
10
10
11
11
# Azure Monitor OpenTelemetry-based auto-instrumentation for Java applications
12
12
13
-
This article describes how to enable and configure the OpenTelemetry-based Azure Monitor Java offering. It can be used for any environment, including on-premises. After you finish the instructions in this article, you'll be able to use Azure Monitor Application Insights to monitor your application.
13
+
This article describes how to enable and configure the OpenTelemetry-based Azure Monitor Java offering. It can be used for any environment, including on-premises. After you finish the instructions in this article, you can use Azure Monitor Application Insights to monitor your application.
Java auto-instrumentation is enabled through configuration changes; no code changes are required.
19
+
Java auto-instrumentation is enabled through configuration changes. No code changes are required.
20
20
21
21
### Prerequisites
22
22
23
-
- Java application using Java 8+
24
-
- Azure subscription: [Create an Azure subscription for free](https://azure.microsoft.com/free/)
25
-
- Application Insights resource: [Create an Application Insights resource](create-workspace-resource.md#create-a-workspace-based-resource)
23
+
You need:
24
+
25
+
- A Java application using Java 8+.
26
+
- An Azure subscription: [Create an Azure subscription for free](https://azure.microsoft.com/free/).
27
+
- An Application Insights resource: [Create an Application Insights resource](create-workspace-resource.md#create-a-workspace-based-resource).
26
28
27
29
### Enable Azure Monitor Application Insights
28
30
@@ -34,32 +36,31 @@ Download the [applicationinsights-agent-3.4.7.jar](https://github.com/microsoft/
34
36
35
37
> [!WARNING]
36
38
>
37
-
> If you are upgrading from an earlier 3.x version,
39
+
> If you're upgrading from an earlier 3.x version:
38
40
>
39
41
> Starting from 3.4.0:
40
42
>
41
-
> - Rate-limited sampling is now the default (if you have not configured a fixed percentage previously). By default, it will capture at most around 5 requests per second (along with their dependencies, traces and custom events). See [fixed-percentage sampling](./java-standalone-config.md#fixed-percentage-sampling) if you wish to revert to the previous behavior of capturing 100% of requests.
43
+
> - Rate-limited sampling is now the default, if you haven't configured a fixed percentage previously. By default, it will capture at most around five requests per second, along with their dependencies, traces, and custom events. See [fixed-percentage sampling](./java-standalone-config.md#fixed-percentage-sampling) if you want to revert to the previous behavior of capturing 100% of requests.
42
44
>
43
45
> Starting from 3.3.0:
44
46
>
45
-
> -`LoggingLevel`is not captured by default as part of Traces' custom dimension since that data is already captured in the `SeverityLevel` field. For details on how to re-enable this if needed, please see the [config options](./java-standalone-config.md#logging-level-as-a-custom-dimension)
46
-
> - Exception records are no longer recorded for failed dependencies, they are only recorded for failed requests.
47
+
> -`LoggingLevel`isn't captured by default as part of Traces' custom dimension because that data is already captured in the `SeverityLevel` field. For information on how to reenable it, see the [config options](./java-standalone-config.md#logging-level-as-a-custom-dimension).
48
+
> - Exception records are no longer recorded for failed dependencies. They're only recorded for failed requests.
47
49
>
48
50
> Starting from 3.2.0:
49
-
>
50
-
> - Controller "InProc" dependencies are no longer captured by default. For details on how to re-enable these, please see the [config options](./java-standalone-config.md#autocollect-inproc-dependencies-preview).
51
+
>
52
+
> - Controller `InProc` dependencies are no longer captured by default. For information on how to reenable these dependencies, see the [config options](./java-standalone-config.md#autocollect-inproc-dependencies-preview).
51
53
> - Database dependency names are now more concise with the full (sanitized) query still present in the `data` field. HTTP dependency names are now more descriptive.
52
54
> This change can affect custom dashboards or alerts if they relied on the previous values.
53
-
> For details, see the [3.2.0 release notes](https://github.com/microsoft/ApplicationInsights-Java/releases/tag/3.2.0).
54
-
>
55
+
> For more information, see the [3.2.0 release notes](https://github.com/microsoft/ApplicationInsights-Java/releases/tag/3.2.0).
56
+
>
55
57
> Starting from 3.1.0:
56
-
>
58
+
>
57
59
> - The operation names and request telemetry names are now prefixed by the HTTP method, such as `GET` and `POST`.
58
60
> This change can affect custom dashboards or alerts if they relied on the previous values.
59
-
> For details, see the [3.1.0 release notes](https://github.com/microsoft/ApplicationInsights-Java/releases/tag/3.1.0).
61
+
> For more information, see the [3.1.0 release notes](https://github.com/microsoft/ApplicationInsights-Java/releases/tag/3.1.0).
60
62
>
61
63
62
-
63
64
#### Point the JVM to the jar file
64
65
65
66
Add `-javaagent:"path/to/applicationinsights-agent-3.4.7.jar"` to your application's JVM args.
@@ -68,7 +69,7 @@ Add `-javaagent:"path/to/applicationinsights-agent-3.4.7.jar"` to your applicati
68
69
> For help with configuring your application's JVM args, see [Tips for updating your JVM args](./java-standalone-arguments.md).
69
70
70
71
> [!TIP]
71
-
> If you develop a Spring Boot application, you can replace the JVM argument by a programmatic configuration. More [here](./java-spring-boot.md).
72
+
> If you develop a Spring Boot application, you can replace the JVM argument by a programmatic configuration. For more information, see [Using Azure Monitor Application Insights with Spring Boot](./java-spring-boot.md).
72
73
73
74
#### Set the Application Insights connection string
74
75
@@ -90,8 +91,8 @@ Add `-javaagent:"path/to/applicationinsights-agent-3.4.7.jar"` to your applicati
90
91
91
92
1. Find the connection string on your Application Insights resource.
:::image type="content" source="media/migrate-from-instrumentation-keys-to-connection-strings/migrate-from-instrumentation-keys-to-connection-strings.png" alt-text="Screenshot that shows Application Insights overview and connection string." lightbox="media/migrate-from-instrumentation-keys-to-connection-strings/migrate-from-instrumentation-keys-to-connection-strings.png":::
95
+
95
96
#### Confirm data is flowing
96
97
97
98
Run your application and open your **Application Insights Resource** tab in the Azure portal. It can take a few minutes for data to show up in the portal.
@@ -108,7 +109,7 @@ As part of using Application Insights instrumentation, we collect and send diagn
108
109
109
110
## Configuration options
110
111
111
-
In the `applicationinsights.json` file, you can also configure these settings:
112
+
In the *applicationinsights.json* file, you can also configure these settings:
112
113
113
114
* Cloud role name
114
115
* Cloud role instance
@@ -117,14 +118,14 @@ In the `applicationinsights.json` file, you can also configure these settings:
117
118
* Custom dimensions
118
119
* Telemetry processors (preview)
119
120
* Autocollected logging
120
-
* Autocollected Micrometer metrics, which include Spring Boot Actuator metrics
121
+
* Autocollected Micrometer metrics, including Spring Boot Actuator metrics
121
122
* Heartbeat
122
123
* HTTP proxy
123
124
* Self-diagnostics
124
125
125
126
For more information, see [Configuration options](./java-standalone-config.md).
126
127
127
-
## Auto-Instrumentation
128
+
## Auto-instrumentation
128
129
129
130
Java 3.x includes the following auto-instrumentation.
130
131
@@ -138,8 +139,7 @@ Java 3.x includes the following auto-instrumentation.
138
139
* Spring scheduling
139
140
140
141
> [!NOTE]
141
-
> Servlet and Netty auto-instrumentation covers the majority of Java HTTP services
142
-
> including Java EE, Jakarta EE, Spring Boot, Quarkus, and Micronaut.
142
+
> Servlet and Netty auto-instrumentation covers the majority of Java HTTP services, including Java EE, Jakarta EE, Spring Boot, Quarkus, and Micronaut.
* Micrometer, which includes Spring Boot Actuator metrics
178
+
* Micrometer, including Spring Boot Actuator metrics
179
179
* JMX Metrics
180
180
181
181
### Azure SDKs
@@ -233,9 +233,9 @@ Telemetry emitted by these Azure SDKs is automatically collected by default:
233
233
234
234
This section explains how to modify telemetry.
235
235
236
-
### Add spans using the OpenTelemetry annotation
236
+
### Add spans by using the OpenTelemetry annotation
237
237
238
-
The simplest way to add your own spans is using OpenTelemetry's `@WithSpan` annotation.
238
+
The simplest way to add your own spans is by using OpenTelemetry's `@WithSpan` annotation.
239
239
240
240
Spans populate the `requests` and `dependencies` tables in Application Insights.
241
241
@@ -262,16 +262,15 @@ Spans populate the `requests` and `dependencies` tables in Application Insights.
262
262
}
263
263
```
264
264
265
-
By default the span will end up in the dependencies table with dependency type `InProc`.
265
+
By default, the span will end up in the `dependencies` table with dependency type `InProc`.
266
266
267
-
If your method represents a background job that is not already captured by auto-instrumentation,
268
-
it is recommended to apply the attribute `kind = SpanKind.SERVER` to the `@WithSpan` annotation
267
+
If your method represents a background job that isn't already captured by auto-instrumentation,
268
+
we recommend that you apply the attribute `kind = SpanKind.SERVER` to the `@WithSpan` annotation
269
269
so that it will end up in the Application Insights `requests` table.
270
270
271
-
### Add spans using the OpenTelemetry API
271
+
### Add spans by using the OpenTelemetry API
272
272
273
-
If the OpenTelemetry `@WithSpan` annotation above doesn't meet your needs,
274
-
then you can add your spans using the OpenTelemetry API.
273
+
If the preceding OpenTelemetry `@WithSpan` annotation doesn't meet your needs, you can add your spans by using the OpenTelemetry API.
275
274
276
275
> [!NOTE]
277
276
> This feature is only in 3.2.0 and later.
@@ -286,7 +285,7 @@ then you can add your spans using the OpenTelemetry API.
286
285
</dependency>
287
286
```
288
287
289
-
1. Use the `GlobalOpenTelemetry` class to create a `Tracer`
288
+
1. Use the `GlobalOpenTelemetry` class to create a `Tracer`:
290
289
291
290
```java
292
291
importio.opentelemetry.api.GlobalOpenTelemetry;
@@ -310,7 +309,7 @@ then you can add your spans using the OpenTelemetry API.
310
309
311
310
### Add span events
312
311
313
-
You can use `opentelemetry-api` to create span events, which populate the traces table in Application Insights. The string passed in to `addEvent()` is saved to the _message_ field within the trace.
312
+
You can use `opentelemetry-api` to create span events, which populate the `traces` table in Application Insights. The string passed in to `addEvent()` is saved to the `message` field within the trace.
314
313
315
314
> [!NOTE]
316
315
> This feature is only in 3.2.0 and later.
@@ -337,7 +336,7 @@ You can use `opentelemetry-api` to create span events, which populate the traces
337
336
338
337
You can use `opentelemetry-api` to add attributes to spans. These attributes can include adding a custom business dimension to your telemetry. You can also use attributes to set optional fields in the Application Insights schema, such as User ID or Client IP.
339
338
340
-
Adding one or more span attributes populates the _customDimensions_ field in the requests, dependencies, traces, or exceptions table.
339
+
Adding one or more span attributes populates the `customDimensions` field in the `requests`, `dependencies`, `traces`, or `exceptions` table.
341
340
342
341
> [!NOTE]
343
342
> This feature is only in 3.2.0 and later.
@@ -379,7 +378,7 @@ You can use `opentelemetry-api` to update the status of a span and record except
379
378
</dependency>
380
379
```
381
380
382
-
1. Set status to error and record an exception in your code:
381
+
1. Set status to `error` and record an exception in your code:
383
382
384
383
```java
385
384
importio.opentelemetry.api.trace.Span;
@@ -392,10 +391,9 @@ You can use `opentelemetry-api` to update the status of a span and record except
392
391
393
392
#### Set the user ID
394
393
395
-
Populate the _user ID_ field in the requests, dependencies, or exceptions table.
394
+
Populate the `user ID` field in the `requests`, `dependencies`, or `exceptions` table.
396
395
397
-
> [!IMPORTANT]
398
-
> Consult applicable privacy laws before you set Authenticated User ID.
396
+
Consult applicable privacy laws before you set the Authenticated User ID.
399
397
400
398
> [!NOTE]
401
399
> This feature is only in 3.2.0 and later.
@@ -455,7 +453,7 @@ We currently support Micrometer, popular logging frameworks, and the Application
455
453
456
454
The following table represents currently supported custom telemetry types that you can enable to supplement the Java 3.x agent. To summarize:
457
455
458
-
- Custom metrics are supported through micrometer.
456
+
- Custom metrics are supported through Micrometer.
459
457
- Custom exceptions and traces are supported through logging frameworks.
460
458
- Custom requests, dependencies, metrics, and exceptions are supported through the OpenTelemetry API.
461
459
- The remaining telemetry types are supported through the [Application Insights Classic SDK](#send-custom-telemetry-by-using-the-application-insights-classic-sdk).
@@ -482,32 +480,31 @@ The following table represents currently supported custom telemetry types that y
482
480
</dependency>
483
481
```
484
482
485
-
2. Use the Micrometer [global registry](https://micrometer.io/docs/concepts#_global_registry) to create a meter:
483
+
1. Use the Micrometer [global registry](https://micrometer.io/docs/concepts#_global_registry) to create a meter:
486
484
487
485
```java
488
486
static final Counter counter = Metrics.counter("test.counter");
489
487
```
490
488
491
-
3. Use the counter to record metrics:
489
+
1. Use the counter to record metrics:
492
490
493
491
```java
494
492
counter.increment();
495
493
```
496
494
497
-
4. The metrics will be ingested into the
495
+
1. The metrics will be ingested into the
498
496
[customMetrics](/azure/azure-monitor/reference/tables/custommetrics) table, with tags captured in the
499
497
`customDimensions` column. You can also view the metrics in the
500
-
[Metrics explorer](../essentials/metrics-getting-started.md) under the "Log-based metrics" metric namespace.
498
+
[metrics explorer](../essentials/metrics-getting-started.md) under the `Log-based metrics` metric namespace.
501
499
502
500
> [!NOTE]
503
-
> Application Insights Java replaces all non-alphanumeric characters (except dashes) in the Micrometer metric name
504
-
> with underscores, so the `test.counter` metric above will show up as `test_counter`.
501
+
> Application Insights Java replaces all non-alphanumeric characters (except dashes) in the Micrometer metric name with underscores. As a result, the preceding `test.counter` metric will show up as `test_counter`.
505
502
506
503
### Send custom traces and exceptions by using your favorite logging framework
507
504
508
505
Logback, Log4j, and java.util.logging are auto-instrumented. Logging performed via these logging frameworks is autocollected as trace and exception telemetry.
509
506
510
-
By default, logging is only collected when that logging is performed at the INFO level or above.
507
+
By default, logging is only collected when that logging is performed at the INFO level or higher.
511
508
To change this level, see the [configuration options](./java-standalone-config.md#auto-collected-logging).
512
509
513
510
Structured logging (attaching custom dimensions to your logs) can be accomplished in these ways:
@@ -528,7 +525,7 @@ Structured logging (attaching custom dimensions to your logs) can be accomplishe
528
525
</dependency>
529
526
```
530
527
531
-
1. Create a TelemetryClient:
528
+
1. Create a `TelemetryClient` instance:
532
529
533
530
```java
534
531
static final TelemetryClient telemetryClient = new TelemetryClient();
@@ -605,7 +602,7 @@ To provide feedback:
605
602
606
603
- Fill out the OpenTelemetry community's [customer feedback survey](https://docs.google.com/forms/d/e/1FAIpQLScUt4reClurLi60xyHwGozgM9ZAz8pNAfBHhbTZ4gFWaaXIRQ/viewform).
607
604
- Tell Microsoft about yourself by joining our [OpenTelemetry Early Adopter Community](https://aka.ms/AzMonOTel/).
608
-
- Engage with other Azure Monitor users in the [Microsoft Tech Community](https://techcommunity.microsoft.com/t5/azure-monitor/bd-p/AzureMonitor).
605
+
- Engage with other Azure Monitor users in the [Microsoft Tech Community](https://techcommunity.microsoft.com/t5/azure-monitor/bd-p/AzureMonitor).
609
606
- Make a feature request at the [Azure Feedback Forum](https://feedback.azure.com/d365community/forum/8849e04d-1325-ec11-b6e6-000d3a4f09d0).
0 commit comments