Skip to content

Add start-up diagnostics#2500

Merged
jeanbisutti merged 23 commits into
mainfrom
diags
Sep 13, 2022
Merged

Add start-up diagnostics#2500
jeanbisutti merged 23 commits into
mainfrom
diags

Conversation

@jeanbisutti

@jeanbisutti jeanbisutti commented Sep 6, 2022

Copy link
Copy Markdown
Contributor

Add start-up diagnostics:

  • Disable C2 compiler during start-up
  • JVM flags (removed from this PR)
  • Resident-set size
  • Native memory tracking

jeanbisutti and others added 2 commits September 9, 2022 14:18
…ights/agent/internal/init/StartupDiagnostics.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@jeanbisutti jeanbisutti requested a review from trask September 9, 2022 21:50
Comment on lines +20 to +27
"applicationinsights.debug.rss.enabled";

// Execute with -XX:NativeMemoryTracking=summary
private static final String APPLICATIONINSIGHTS_DEBUG_NATIVE_MEM_TRACKING_ENABLED =
"applicationinsights.debug.native-mem-tracking.enabled";

public static final String APPLICATIONINSIGHTS_DEBUG_DIAG_EXPORT_TO_FILE =
"applicationinsights.debug.diag-export-to-file";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe applicationinsights.debug.* -> applicationinsights.debug.startup.*, or applicationinsights.debug.startup-*?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +104 to +106
byte[] diagReportAsBytes = diagnosticsReport.toString().getBytes(StandardCharsets.UTF_8);
try {
Files.write(diagFile.toPath(), diagReportAsBytes);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
byte[] diagReportAsBytes = diagnosticsReport.toString().getBytes(StandardCharsets.UTF_8);
try {
Files.write(diagFile.toPath(), diagReportAsBytes);
try {
Files.writeString(diagFile.toPath(), diagnosticsReport.toString());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trask Files.writeString is not availlable in Java 8: https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html

}
}

private Optional<File> createTempDirIfNotExists() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically this repo (and upstream otel) uses @Nullable over Optional, though not totally consistently, it's not a problem to introduce here, but let's have broader discussion separately over whether we want to go in that direction generally

}

private static IllegalStateException combineExceptionsIfNecessary(
IllegalStateException exitValueException, Exception e, List<String> command) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IllegalStateException exitValueException, Exception e, List<String> command) {
@Nullable IllegalStateException exitValueException, Exception e, List<String> command) {

Comment on lines +48 to +50
if (e.getSuppressed().length == 1) {
return e.getMessage() + " (Suppressed: " + e.getSuppressed()[0] + ")";
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suppressed message doesn't seem like it would be very interesting typically, and this would allow still getting the full stack trace along with suppressed exception if really needed at debug level.

Suggested change
if (e.getSuppressed().length == 1) {
return e.getMessage() + " (Suppressed: " + e.getSuppressed()[0] + ")";
}
startupLogger.debug(e.getMessage(), e);

// ]
private static final String
APPLICATIONINSIGHTS_EXPERIMENT_CLEAR_COMPILER_DIRECTIVES_AFTER_INITIALIZATION =
"applicationinsights.experiment.clear-compiler-directives-after-initialization";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"applicationinsights.experiment.clear-compiler-directives-after-initialization";
"applicationinsights.experiment.clear_compiler_directives_after_initialization";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we follow the same naming convention? i have seen lost of underline instead of dash. See AiSemanticAttributes.java

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a system property name, and not a semantic attribute name


// Execute with -XX:NativeMemoryTracking=summary
private static final String APPLICATIONINSIGHTS_DEBUG_NATIVE_MEM_TRACKING_ENABLED =
"applicationinsights.debug.native-mem-tracking.enabled";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"applicationinsights.debug.native-mem-tracking.enabled";
"applicationinsights.debug.native_mem_tracking_enabled";


static boolean hasToDisableJvmCompilerDirectives() {
return Boolean.getBoolean(
APPLICATIONINSIGHTS_EXPERIMENT_CLEAR_COMPILER_DIRECTIVES_AFTER_INITIALIZATION);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such a long system property name, should we consider a shorter name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hard one to explain succinctly 😅


class JvmCompiler {

// To disable C2 compiler during Application Insights set-up, for Java >= 9, do the following

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a note how user can use APPLICATIONINSIGHTS_EXPERIMENT_CLEAR_COMPILER_DIRECTIVES_AFTER_INITIALIZATION?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heyamsthis It's an experimental feature that we would like to test with some users. Following the feedbacks, we could properly document this feature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heyams It is necessary to add the JVM option explained from line 11 and set the applicationinsights.experiment.clear-compiler-directives-after-initialization property to true.

jeanbisutti and others added 9 commits September 13, 2022 10:41
…ights/agent/internal/init/StartupDiagnostics.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
…ights/agent/internal/init/StartupDiagnostics.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
…ights/agent/internal/init/StartupDiagnostics.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@jeanbisutti jeanbisutti merged commit b95f119 into main Sep 13, 2022
@jeanbisutti jeanbisutti deleted the diags branch September 13, 2022 10:10
@jeanbisutti jeanbisutti restored the diags branch September 13, 2022 10:27
heyams pushed a commit that referenced this pull request Sep 16, 2022
…and the ability to disable the JVM C2 compiler during start-up (#2500)
heyams pushed a commit that referenced this pull request Sep 16, 2022
…and the ability to disable the JVM C2 compiler during start-up (#2500)
heyams pushed a commit that referenced this pull request Sep 16, 2022
…and the ability to disable the JVM C2 compiler during start-up (#2500)
@trask trask deleted the diags branch September 28, 2022 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants