-
Notifications
You must be signed in to change notification settings - Fork 867
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
Conversation
@@ -1,9 +1,8 @@ | |||
plugins { | |||
id("otel.library-instrumentation") | |||
id("otel.animalsniffer-conventions") |
There was a problem hiding this comment.
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.
96e9de1
to
780b234
Compare
There was a problem hiding this 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")); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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).
static String[] getProcessArguments() { | ||
return ProcessHandle.current().info().arguments().orElseGet(() -> new String[0]); | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fancy phrasing is fancy. 🎩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧐
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 😁
There was a problem hiding this comment.
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.
780b234
to
5eccd69
Compare
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")); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
?
...library/src/main/java/io/opentelemetry/instrumentation/resources/JarServiceNameProvider.java
Outdated
Show resolved
Hide resolved
String serviceName = config.getString("otel.service.name"); | ||
Map<String, String> resourceAttributes = config.getMap("otel.resource.attributes"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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}ExporterProvider
s. I think it could result in more module / testable code, and potentially have some nice interactions with a future file based configuration scheme.
Co-authored-by: Trask Stalnaker <[email protected]>
Co-authored-by: Trask Stalnaker <[email protected]>
Co-authored-by: Trask Stalnaker <[email protected]>
No description provided.