66package io .opentelemetry .instrumentation .spring .resources ;
77
88import static java .util .logging .Level .FINE ;
9+ import static java .util .logging .Level .FINER ;
910
1011import com .google .auto .service .AutoService ;
1112import io .opentelemetry .sdk .autoconfigure .spi .ConfigProperties ;
2425import java .util .Properties ;
2526import java .util .function .Function ;
2627import java .util .function .Supplier ;
27- import java .util .logging .Level ;
2828import java .util .logging .Logger ;
2929import java .util .regex .Matcher ;
3030import java .util .regex .Pattern ;
@@ -73,7 +73,7 @@ public SpringBootServiceNameDetector() {
7373 @ Override
7474 public Resource createResource (ConfigProperties config ) {
7575
76- logger .log (Level . FINER , "Performing Spring Boot service name auto-detection..." );
76+ logger .log (FINER , "Performing Spring Boot service name auto-detection..." );
7777 // Note: The order should be consistent with the order of Spring matching, but noting
7878 // that we have "first one wins" while Spring has "last one wins".
7979 // The docs for Spring are here:
@@ -84,8 +84,10 @@ public Resource createResource(ConfigProperties config) {
8484 this ::findBySystemProperties ,
8585 this ::findByEnvironmentVariable ,
8686 this ::findByCurrentDirectoryApplicationProperties ,
87+ this ::findByCurrentDirectoryApplicationYml ,
8788 this ::findByCurrentDirectoryApplicationYaml ,
8889 this ::findByClasspathApplicationProperties ,
90+ this ::findByClasspathApplicationYml ,
8991 this ::findByClasspathApplicationYaml );
9092 return finders
9193 .map (Supplier ::get )
@@ -119,24 +121,22 @@ public int order() {
119121 @ Nullable
120122 private String findByEnvironmentVariable () {
121123 String result = system .getenv ("SPRING_APPLICATION_NAME" );
122- logger .log (Level . FINER , "Checking for SPRING_APPLICATION_NAME in env: {0}" , result );
124+ logger .log (FINER , "Checking for SPRING_APPLICATION_NAME in env: {0}" , result );
123125 return result ;
124126 }
125127
126128 @ Nullable
127129 private String findBySystemProperties () {
128130 String result = system .getProperty ("spring.application.name" );
129- logger .log (Level . FINER , "Checking for spring.application.name system property: {0}" , result );
131+ logger .log (FINER , "Checking for spring.application.name system property: {0}" , result );
130132 return result ;
131133 }
132134
133135 @ Nullable
134136 private String findByClasspathApplicationProperties () {
135137 String result = readNameFromAppProperties ();
136138 logger .log (
137- Level .FINER ,
138- "Checking for spring.application.name in application.properties file: {0}" ,
139- result );
139+ FINER , "Checking for spring.application.name in application.properties file: {0}" , result );
140140 return result ;
141141 }
142142
@@ -148,27 +148,49 @@ private String findByCurrentDirectoryApplicationProperties() {
148148 } catch (Exception e ) {
149149 // expected to fail sometimes
150150 }
151- logger .log (Level . FINER , "Checking application.properties in current dir: {0}" , result );
151+ logger .log (FINER , "Checking application.properties in current dir: {0}" , result );
152152 return result ;
153153 }
154154
155+ @ Nullable
156+ private String findByClasspathApplicationYml () {
157+ return findByClasspathYamlFile ("application.yml" );
158+ }
159+
155160 @ Nullable
156161 private String findByClasspathApplicationYaml () {
157- String result =
158- loadFromClasspath ("application.yml" , SpringBootServiceNameDetector ::parseNameFromYaml );
159- logger .log (Level .FINER , "Checking application.yml in classpath: {0}" , result );
162+ return findByClasspathYamlFile ("application.yaml" );
163+ }
164+
165+ private String findByClasspathYamlFile (String fileName ) {
166+ String result = loadFromClasspath (fileName , SpringBootServiceNameDetector ::parseNameFromYaml );
167+ if (logger .isLoggable (FINER )) {
168+ logger .log (FINER , "Checking {0} in classpath: {1}" , new Object [] {fileName , result });
169+ }
160170 return result ;
161171 }
162172
173+ @ Nullable
174+ private String findByCurrentDirectoryApplicationYml () {
175+ return findByCurrentDirectoryYamlFile ("application.yml" );
176+ }
177+
163178 @ Nullable
164179 private String findByCurrentDirectoryApplicationYaml () {
180+ return findByCurrentDirectoryYamlFile ("application.yaml" );
181+ }
182+
183+ @ Nullable
184+ private String findByCurrentDirectoryYamlFile (String fileName ) {
165185 String result = null ;
166- try (InputStream in = system .openFile ("application.yml" )) {
186+ try (InputStream in = system .openFile (fileName )) {
167187 result = parseNameFromYaml (in );
168188 } catch (Exception e ) {
169189 // expected to fail sometimes
170190 }
171- logger .log (Level .FINER , "Checking application.yml in current dir: {0}" , result );
191+ if (logger .isLoggable (FINER )) {
192+ logger .log (FINER , "Checking {0} in current dir: {1}" , new Object [] {fileName , result });
193+ }
172194 return result ;
173195 }
174196
@@ -203,7 +225,7 @@ private String findByCommandlineArgument() {
203225 String javaCommand = system .getProperty ("sun.java.command" );
204226 result = parseNameFromCommandLine (javaCommand );
205227 }
206- logger .log (Level . FINER , "Checking application commandline args: {0}" , result );
228+ logger .log (FINER , "Checking application commandline args: {0}" , result );
207229 return result ;
208230 }
209231
@@ -276,7 +298,7 @@ static class SystemHelper {
276298 contextClassLoader != null ? contextClassLoader : ClassLoader .getSystemClassLoader ();
277299 addBootInfPrefix = classLoader .getResource ("BOOT-INF/classes/" ) != null ;
278300 if (addBootInfPrefix ) {
279- logger .log (Level . FINER , "Detected presence of BOOT-INF/classes/" );
301+ logger .log (FINER , "Detected presence of BOOT-INF/classes/" );
280302 }
281303 }
282304
0 commit comments