@@ -51,7 +51,8 @@ private HypertraceConfig() {}
51
51
// so avoiding for perf reasons
52
52
private static volatile boolean servletCausingException ;
53
53
54
- private static AgentConfig agentConfig ;
54
+ private static final AgentConfigSupplier agentConfigSupplier =
55
+ new AgentConfigSupplier (HypertraceConfig ::load );
55
56
56
57
static final String DEFAULT_SERVICE_NAME = "unknown" ;
57
58
static final String DEFAULT_REPORTING_ENDPOINT = "http://localhost:9411/api/v2/spans" ;
@@ -61,21 +62,7 @@ private HypertraceConfig() {}
61
62
static final int DEFAULT_BODY_MAX_SIZE_BYTES = 128 * 1024 ;
62
63
63
64
public static AgentConfig get () {
64
- if (agentConfig == null ) {
65
- synchronized (HypertraceConfig .class ) {
66
- if (agentConfig == null ) {
67
- try {
68
- agentConfig = load ();
69
- log .info (
70
- "Config loaded: {}" ,
71
- JsonFormat .printer ().omittingInsignificantWhitespace ().print (agentConfig ));
72
- } catch (IOException e ) {
73
- throw new RuntimeException ("Could not load config" , e );
74
- }
75
- }
76
- }
77
- }
78
- return agentConfig ;
65
+ return agentConfigSupplier .get ();
79
66
}
80
67
81
68
public static boolean isInstrumentationEnabled (String primaryName , String [] otherNames ) {
@@ -123,16 +110,20 @@ private static boolean isHypertraceType(String message) {
123
110
/** Reset the config, use only in tests. */
124
111
@ VisibleForTesting
125
112
public static void reset () {
126
- agentConfig = null ;
113
+ agentConfigSupplier . reset () ;
127
114
}
128
115
129
- private static AgentConfig load () throws IOException {
116
+ private static AgentConfig load () {
130
117
String configFile = EnvironmentConfig .getProperty (EnvironmentConfig .CONFIG_FILE_PROPERTY );
131
118
if (configFile == null ) {
132
119
return EnvironmentConfig .applyPropertiesAndEnvVars (applyDefaults (AgentConfig .newBuilder ()))
133
120
.build ();
134
121
}
135
- return load (configFile );
122
+ try {
123
+ return load (configFile );
124
+ } catch (IOException e ) {
125
+ throw new RuntimeException ("Could not load config" , e );
126
+ }
136
127
}
137
128
138
129
@ VisibleForTesting
0 commit comments