Skip to content

Commit 6f612fd

Browse files
johnoliverCopilot
andauthored
Add continuous profiling and update telemetry for Illuminate (#4807)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c25926a commit 6f612fd

28 files changed

Lines changed: 1228 additions & 399 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
## Unreleased
44

5+
### Enhancements
6+
7+
* Add continuous profiling (`enableContinuousProfiling`, `continuousProfilingMaxAgeSeconds`) which
8+
keeps a single JFR recording running in a circular buffer so profile requests dump the most recent
9+
window of data immediately
10+
([#4807](https://github.com/microsoft/ApplicationInsights-Java/pull/4807))
11+
12+
### Breaking changes
13+
14+
* Rename the `MachineStats` JFR diagnostic event to `MachineInfo`. Custom `.jfc` files that enable
15+
`com.microsoft.applicationinsights.diagnostics.jfr.MachineStats` must be updated to the new event
16+
name ([#4807](https://github.com/microsoft/ApplicationInsights-Java/pull/4807))
17+
518
## Version 3.7.9 GA (06/18/2026)
619

720
### Enhancements

‎agent/agent-profiler/agent-diagnostics-api/src/main/java/com/microsoft/applicationinsights/diagnostics/DiagnosticEngine.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,24 @@ public interface DiagnosticEngine {
1717
* alertBreach.alertConfiguration.profileDuration
1818
*/
1919
Future<DiagnosisResult<?>> performDiagnosis(AlertBreach alertBreach);
20+
21+
/**
22+
* Start collecting diagnostics continuously.
23+
*
24+
* <p>Used with continuous profiling, where a circular buffer is dumped on demand rather than a
25+
* forward-looking recording being created per breach. Registering the periodic diagnostic
26+
* emitters up front ensures diagnostic events populate the continuous recording buffer, so they
27+
* are present in any snapshot that is dumped.
28+
*
29+
* @return {@code true} if continuous diagnostics were started successfully; {@code false} if this
30+
* engine does not support continuous diagnostics or startup failed. The default
31+
* implementation returns {@code false} so alternate implementations do not silently appear to
32+
* support continuous diagnostics while doing nothing.
33+
*/
34+
default boolean startContinuousDiagnostics() {
35+
return false;
36+
}
37+
38+
/** Stop collecting diagnostics continuously. Defaults to a no-op. */
39+
default void stopContinuousDiagnostics() {}
2040
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.diagnostics.jfr;
5+
6+
import com.azure.json.JsonReader;
7+
import com.azure.json.JsonSerializable;
8+
import com.azure.json.JsonToken;
9+
import com.azure.json.JsonWriter;
10+
import java.io.IOException;
11+
import jdk.jfr.Category;
12+
import jdk.jfr.Description;
13+
import jdk.jfr.Event;
14+
import jdk.jfr.Label;
15+
import jdk.jfr.Name;
16+
import jdk.jfr.Period;
17+
import jdk.jfr.StackTrace;
18+
19+
/**
20+
* Machine-level diagnostic event.
21+
*
22+
* <p><b>Compatibility contract.</b> The JFR wire event name ({@link #NAME}) is an explicitly
23+
* versioned identifier. It was renamed from {@link #LEGACY_NAME} ("MachineStats") to "MachineInfo".
24+
* Because the event name is the key by which a reader locates the event, changing it is a
25+
* compatibility boundary that {@link #SCHEMA_VERSION} (payload versioning) cannot bridge:
26+
*
27+
* <ul>
28+
* <li><b>Read side (backward compatibility):</b> readers must look up {@link #NAME} and fall back
29+
* to {@link #LEGACY_NAME} so that recordings produced by older agents (which carry a
30+
* "MachineStats" event) can still be discovered and scored.
31+
* <li><b>Write side (forward compatibility):</b> agents at this version and later emit only
32+
* {@link #NAME}. Consumers/backends and any custom JFC files must therefore be updated to
33+
* recognize "MachineInfo"; older consumers that only know "MachineStats" will not find the
34+
* event. This is a deliberate, documented minimum-consumer-version requirement rather than a
35+
* silent change.
36+
* </ul>
37+
*
38+
* <p>Once the write side no longer needs to interoperate with the old name, {@link #LEGACY_NAME}
39+
* and its read-side fallback can be removed.
40+
*/
41+
@SuppressWarnings("Java8ApiChecker") // JFR APIs require Java 11+, but agent targets Java 8 bytecode
42+
@Name("com.microsoft.applicationinsights.diagnostics.jfr.MachineInfo")
43+
@Label("MachineInfo")
44+
@Category("Diagnostic")
45+
@Description("MachineInfo")
46+
@StackTrace(false)
47+
@Period("beginChunk")
48+
public class MachineInfo extends Event implements JsonSerializable<MachineInfo> {
49+
public static final String NAME = "com.microsoft.applicationinsights.diagnostics.jfr.MachineInfo";
50+
51+
/**
52+
* Event name emitted by agents prior to the MachineStats-&gt;MachineInfo rename. Readers fall
53+
* back to this so previously-recorded recordings (which carry a "MachineStats" event) can still
54+
* be located and scored.
55+
*/
56+
public static final String LEGACY_NAME =
57+
"com.microsoft.applicationinsights.diagnostics.jfr.MachineStats";
58+
59+
/**
60+
* Current schema version. Version 2 drops the legacy {@code contextSwitchesPerMs} field;
61+
* recordings produced before the schemaVersion field was added carry schemaVersion 1 (the
62+
* implicit legacy version) and still serialize {@code contextSwitchesPerMs}.
63+
*/
64+
public static final int SCHEMA_VERSION = 2;
65+
66+
private int coreCount;
67+
68+
private int schemaVersion;
69+
70+
public int getCoreCount() {
71+
return coreCount;
72+
}
73+
74+
public MachineInfo setCoreCount(int coreCount) {
75+
this.coreCount = coreCount;
76+
return this;
77+
}
78+
79+
public int getSchemaVersion() {
80+
return schemaVersion;
81+
}
82+
83+
public MachineInfo setSchemaVersion(int schemaVersion) {
84+
this.schemaVersion = schemaVersion;
85+
return this;
86+
}
87+
88+
@Override
89+
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
90+
jsonWriter.writeStartObject();
91+
return jsonWriter
92+
.writeIntField("coreCount", coreCount)
93+
.writeIntField("schemaVersion", schemaVersion)
94+
.writeEndObject();
95+
}
96+
97+
public static MachineInfo fromJson(JsonReader jsonReader) throws IOException {
98+
return jsonReader.readObject(
99+
reader -> {
100+
MachineInfo deserializedValue = new MachineInfo();
101+
102+
while (reader.nextToken() != JsonToken.END_OBJECT) {
103+
String fieldName = reader.getFieldName();
104+
reader.nextToken();
105+
if ("coreCount".equals(fieldName)) {
106+
deserializedValue.setCoreCount(reader.getInt());
107+
} else if ("schemaVersion".equals(fieldName)) {
108+
deserializedValue.setSchemaVersion(reader.getInt());
109+
} else {
110+
reader.skipChildren();
111+
}
112+
}
113+
114+
return deserializedValue;
115+
});
116+
}
117+
}

‎agent/agent-profiler/agent-diagnostics-jfr/src/main/java/com/microsoft/applicationinsights/diagnostics/jfr/MachineStats.java‎

Lines changed: 0 additions & 80 deletions
This file was deleted.

‎agent/agent-profiler/agent-diagnostics/build.gradle.kts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ dependencies {
1818

1919
compileOnly("com.google.auto.service:auto-service")
2020
annotationProcessor("com.google.auto.service:auto-service")
21+
22+
testImplementation("org.assertj:assertj-core")
23+
testImplementation("org.mockito:mockito-core")
24+
testImplementation("org.gradle.jfr.polyfill:jfr-polyfill:1.0.2")
25+
testImplementation("com.azure:azure-json")
2126
}

0 commit comments

Comments
 (0)