@@ -8,7 +8,9 @@ import spock.lang.Specification
88import static datadog.trace.api.Config.AGENT_HOST
99import static datadog.trace.api.Config.AGENT_PORT_LEGACY
1010import static datadog.trace.api.Config.AGENT_UNIX_DOMAIN_SOCKET
11+ import static datadog.trace.api.Config.CONFIGURATION_FILE
1112import static datadog.trace.api.Config.DEFAULT_JMX_FETCH_STATSD_PORT
13+ import static datadog.trace.api.Config.DEFAULT_SERVICE_NAME
1214import static datadog.trace.api.Config.GLOBAL_TAGS
1315import static datadog.trace.api.Config.HEADER_TAGS
1416import static datadog.trace.api.Config.HTTP_CLIENT_ERROR_STATUSES
@@ -715,4 +717,50 @@ class ConfigTest extends Specification {
715717 then:
716718 config.localRootSpanTags.get('_dd.hostname') == InetAddress.localHost.hostName
717719 }
720+
721+ def " verify fallback to properties file" () {
722+ setup:
723+ System.setProperty(PREFIX + CONFIGURATION_FILE, " src/ test/ resources/ dd- java- tracer. properties" )
724+
725+ when:
726+ def config = new Config()
727+
728+ then:
729+ config.serviceName == " set- in - properties"
730+ }
731+
732+ def " verify fallback to properties file has lower priority then system property" () {
733+ setup:
734+ System.setProperty(PREFIX + CONFIGURATION_FILE, " src/ test/ resources/ dd- java- tracer. properties" )
735+ System.setProperty(PREFIX + SERVICE_NAME, " set- in - system" )
736+
737+ when:
738+ def config = new Config()
739+
740+ then:
741+ config.serviceName == " set- in - system"
742+ }
743+
744+ def " verify fallback to properties file has lower priority then env var" () {
745+ setup:
746+ System.setProperty(PREFIX + CONFIGURATION_FILE, " src/ test/ resources/ dd- java- tracer. properties" )
747+ environmentVariables.set(" DD_SERVICE_NAME " , " set- in - env" )
748+
749+ when:
750+ def config = new Config()
751+
752+ then:
753+ config.serviceName == " set- in - env"
754+ }
755+
756+ def " verify fallback to properties file that does not exist does not crash app" () {
757+ setup:
758+ System.setProperty(PREFIX + CONFIGURATION_FILE, " src/ test/ resources/ do - not- exist. properties" )
759+
760+ when:
761+ def config = new Config()
762+
763+ then:
764+ config.serviceName == 'unnamed-java-app'
765+ }
718766}
0 commit comments