Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-detect service name based on the jar name #6817

Merged
merged 4 commits into from
Oct 23, 2022

Conversation

mateuszrzeszutek
Copy link
Member

No description provided.

@mateuszrzeszutek mateuszrzeszutek requested a review from a team October 6, 2022 15:01
@@ -1,9 +1,8 @@
plugins {
id("otel.library-instrumentation")
id("otel.animalsniffer-conventions")
Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK SPI doesn't work on android anyway, so we can get rid of this plugin.

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Looks good. A couple of small nits but otherwise lovely. I think users will appreciate this!

"/path to app/with spaces/my-service.jar 1 2 3",
"/path to app/with spaces/my-service.jar"),
arguments(
"/path to app/with spaces/my-service 1 2 3", "/path to app/with spaces/my-service"));
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is a little surprising to me because it doesn't actually have .jar in any argument names. Since we're not looking for .jar, how are we able to confidently assume that the file is my-service and not my-service 1 2 3?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what the second arg is for - the service detector checks whether a particular path (a substring of the sun.java.command) is a regular file (not a directory; a leaf in the file system graph).

Comment on lines +10 to +12
static String[] getProcessArguments() {
return ProcessHandle.current().info().arguments().orElseGet(() -> new String[0]);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Leveraging the module system here is sooooooo much nicer than the reflection in the original version. ❤️

String[] args =
new String[] {"-Dtest=42", "-Xmx666m", "-jar", "/path/to/app/my-service.jar", "abc", "def"};
JarServiceNameProvider serviceNameProvider =
new JarServiceNameProvider(() -> args, prop -> null, file -> false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This gave me a little bit of pause because the "does the file exist" check is returning false here....and the test passes because it's not used. Definitely prefer passing null for tests where the argument is not used (there are a few others too I believe).

Copy link
Member Author

Choose a reason for hiding this comment

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

How about () -> throw new AssertionError() instead? Passing null results in null warnings

Copy link
Contributor

Choose a reason for hiding this comment

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

We should allow passing null in tests!! I think that suggestion is an improvement, though.

@@ -90,7 +92,7 @@ public Resource createResource(ConfigProperties config) {
.findFirst()
.map(
serviceName -> {
logger.log(Level.FINER, "Guessed Spring Boot service name: {0}", serviceName);
logger.log(FINE, "Auto-detected Spring Boot service name: {0}", serviceName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Fancy phrasing is fancy. 🎩

Copy link
Member Author

Choose a reason for hiding this comment

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

🧐

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted the message to be very similar in all of these service.name auto-detectors -- thus this change.

Copy link
Member

Choose a reason for hiding this comment

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

👍 I like auto-detected > guessed 😄

EDIT: rename class SpringBootServiceNameDetector?

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed both classes to ...Detector

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I like auto-detected > guessed 😄

I mean, it's more official-sounding for sure. But let's be real, it's only a heuristic, and it's guessing. 😁

Copy link
Member

Choose a reason for hiding this comment

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

oh "Heuristic" is another good fancy word 😂. Guess sounds like it's sorta random.

instrumentation/resources/library/build.gradle.kts Outdated Show resolved Hide resolved
Comment on lines 104 to 109
arguments("/path/to/my-service.jar", "/path/to/my-service.jar"),
arguments(
"/path to app/with spaces/my-service.jar 1 2 3",
"/path to app/with spaces/my-service.jar"),
arguments(
"/path to app/with spaces/my-service 1 2 3", "/path to app/with spaces/my-service"));
Copy link
Member

Choose a reason for hiding this comment

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

I was trying this out, and these tests fail on Windows, because later on the Path gets normalized with \, it's ok to merge as-is though (I need to try again to get the github actions running on windows)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I completely didn't think of this. Great point, I've changed this test to use Path instead, hope that helps 🤞

@@ -90,7 +92,7 @@ public Resource createResource(ConfigProperties config) {
.findFirst()
.map(
serviceName -> {
logger.log(Level.FINER, "Guessed Spring Boot service name: {0}", serviceName);
logger.log(FINE, "Auto-detected Spring Boot service name: {0}", serviceName);
Copy link
Member

Choose a reason for hiding this comment

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

👍 I like auto-detected > guessed 😄

EDIT: rename class SpringBootServiceNameDetector?

Comment on lines 68 to 69
String serviceName = config.getString("otel.service.name");
Map<String, String> resourceAttributes = config.getMap("otel.resource.attributes");
Copy link
Member

Choose a reason for hiding this comment

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

are these needed b/c this resource provider can't run after the built-in resource provider?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes -- the EnvironmentResource always runs last, as it's not a ResourceProvider, it's just called after all of the providers.

Copy link
Member

Choose a reason for hiding this comment

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

do you think this is changeable, to make otel.service.name and otel.resource.attributes be real resource detectors, so that they can be leveraged as part of shouldApply (cc @jack-berg)

(I think this is a perfectly good workaround tho, and hopefully it's not a common use case)

Copy link
Member

Choose a reason for hiding this comment

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

do you think this is changeable, to make otel.service.name and otel.resource.attributes be real resource detectors, so that they can be leveraged as part of shouldApply

This idea has definitely cross my mine. I've also considered taking the idea further and modeling all the exporter configuration as Configurable{Signal}ExporterProviders. I think it could result in more module / testable code, and potentially have some nice interactions with a future file based configuration scheme.

Mateusz Rzeszutek and others added 2 commits October 20, 2022 16:05
@trask trask merged commit 33b0688 into open-telemetry:main Oct 23, 2022
@mateuszrzeszutek mateuszrzeszutek deleted the jar-service-name branch October 23, 2022 21:43
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Oct 31, 2022
LironKS pushed a commit to helios/opentelemetry-java-instrumentation that referenced this pull request Dec 4, 2022
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.

4 participants