Skip to content

Runtime attachment feature#2325

Merged
jeanbisutti merged 40 commits into
mainfrom
runtime-attach
Jun 20, 2022
Merged

Runtime attachment feature#2325
jeanbisutti merged 40 commits into
mainfrom
runtime-attach

Conversation

@jeanbisutti

Copy link
Copy Markdown
Contributor

Runtime attachment feature for Application Insights.

The feature delegates attachment to Otel runtime attachment project and allows to manage things specific to Application Insights (applicationinsights.json and version tracking).

A PR was also created to improve the Otel runtime attachment (more checks and logs).

@jeanbisutti jeanbisutti requested review from heyams and trask as code owners June 13, 2022 16:38
@jeanbisutti jeanbisutti marked this pull request as draft June 13, 2022 16:39
RuntimeAttach.attachJavaagentToCurrentJVM();

if (!agentIsAttached()) {
System.setProperty(RUNTIME_ATTACHED_PROPERTY, "false");

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 explain why line 45 and then setting it to false here?

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.

At this step, if the runtime attachment is not done, the agent.runtime.attached property always has a true value. So, for consistency it is set to false. However, since the agent is not attached, the property value won't be used.... So, I will remove this piece of code. The code will be easier to read without apparently any impact.

}
}

private static boolean agentIsAttached() {

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.

I saw you have another pr on opentelemetry. should you wait till that PR is merged and use the upstream to check if agent is attached?

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.

No, we have not to wait until the OTel PR is merged. OTel RuntimeAttach class exposes only one public method, attachJavaagentToCurrentJVM().

@jeanbisutti jeanbisutti marked this pull request as ready for review June 13, 2022 17:21
Comment thread agent/runtime-attach/README.md Outdated
Comment thread agent/runtime-attach/README.md
Comment thread agent/runtime-attach/README.md Outdated
Comment thread agent/runtime-attach/build.gradle.kts Outdated
Comment thread agent/runtime-attach/build.gradle.kts Outdated
Comment thread agent/runtime-attach/build.gradle.kts Outdated
Comment thread agent/runtime-attach/src/test/resources/applicationinsights.json Outdated
jeanbisutti and others added 13 commits June 14, 2022 11:43
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
…ights/agent/internal/init/FirstEntryPoint.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
… not hierarchical when the application is packaged as a war or a jar
…g issue when the application is packaged as a war or jar file (other solution proposed in the Github issue)
Comment on lines +77 to +78
boolean jsonFileNotFound = jsonUrl == null;
if (jsonFileNotFound) {

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
boolean jsonFileNotFound = jsonUrl == null;
if (jsonFileNotFound) {
if (jsonUrl == null) {

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 style choice, I would have chosen to inline this too, but I also don't mind being flexible when it comes to style choices that aren't covered by spotless, errorprone, or https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/style-guideline.md

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.

My intention with the jsonFileNotFound variable was to give meaning to the jsonUrl == null technical check.

@@ -0,0 +1,7 @@
{

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.

without this file, it will return Optional.empty. does the test still work without json config?

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.

The RuntimeAttachTest test will fail if we remove this file because Application Insights needs a connection string provided in the json file. The connection string may also be supplied with a system property or an environment variable, without a json file, and the code execution path will then use the Optional.empty() line.

@trask trask left a comment

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.

👍

Comment thread agent/runtime-attach/build.gradle.kts Outdated
Comment thread agent/runtime-attach/src/test/resources/applicationinsights.json Outdated
@lgtm-com

lgtm-com Bot commented Jun 16, 2022

Copy link
Copy Markdown

This pull request introduces 1 alert when merging aca7ecd into 7eb023e - view on LGTM.com

new alerts:

  • 1 for Potential input resource leak

@jeanbisutti jeanbisutti marked this pull request as draft June 16, 2022 13:35
@jeanbisutti

Copy link
Copy Markdown
Contributor Author

RuntimeAttach and AgentFileProvider classes could be removed once the 2 following OTel PRs will be merged and a new OTel release will be done:

@jeanbisutti jeanbisutti marked this pull request as ready for review June 17, 2022 20:00
@jeanbisutti jeanbisutti requested a review from trask June 17, 2022 20:00

@trask trask left a comment

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.

nice, a couple of suggestions on the internal property names if they make sense

jeanbisutti and others added 7 commits June 17, 2022 22:57
…sights/attach/ApplicationInsights.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
…sights/attach/ApplicationInsights.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@jeanbisutti jeanbisutti merged commit 37f6d4c into main Jun 20, 2022
@jeanbisutti jeanbisutti deleted the runtime-attach branch June 20, 2022 10:25
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