Skip to content

Commit ed0d60a

Browse files
committed
Allow to set Wavefront service name
Both the application and the service name default to 'spring.application.name'
1 parent 6378b58 commit ed0d60a

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/wavefront/WavefrontTracingAutoConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
3333
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontAutoConfiguration;
3434
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties;
35+
import org.springframework.boot.actuate.autoconfigure.wavefront.WavefrontProperties.Tracing;
3536
import org.springframework.boot.autoconfigure.AutoConfiguration;
3637
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
3738
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -62,8 +63,12 @@ public class WavefrontTracingAutoConfiguration {
6263
@Bean
6364
@ConditionalOnMissingBean
6465
public ApplicationTags applicationTags(Environment environment, WavefrontProperties properties) {
65-
String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
66-
return new ApplicationTags.Builder(applicationName, properties.getTracing().getServiceName()).build();
66+
String springApplicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
67+
Tracing tracing = properties.getTracing();
68+
String applicationName = tracing.getApplicationName() != null ? tracing.getApplicationName()
69+
: springApplicationName;
70+
String serviceName = tracing.getServiceName() != null ? tracing.getServiceName() : springApplicationName;
71+
return new ApplicationTags.Builder(applicationName, serviceName).build();
6772
}
6873

6974
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontProperties.java

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,55 @@ public class WavefrontProperties {
6666
*/
6767
private final Tracing tracing = new Tracing();
6868

69-
/**
70-
* Returns the effective URI of the wavefront instance. This will not be the same URI
71-
* given through {@link #setUri(URI)} when a proxy is used.
72-
* @return the effective URI of the wavefront instance
73-
*/
74-
public URI getEffectiveUri() {
75-
if (usesProxy()) {
76-
// See io.micrometer.wavefront.WavefrontMeterRegistry.getWavefrontReportingUri
77-
return URI.create(this.uri.toString().replace("proxy://", "http://"));
78-
}
69+
public Sender getSender() {
70+
return this.sender;
71+
}
72+
73+
public Metrics getMetrics() {
74+
return this.metrics;
75+
}
76+
77+
public Tracing getTracing() {
78+
return this.tracing;
79+
}
80+
81+
public URI getUri() {
7982
return this.uri;
8083
}
8184

8285
public void setUri(URI uri) {
8386
this.uri = uri;
8487
}
8588

89+
public String getSource() {
90+
return this.source;
91+
}
92+
8693
public void setSource(String source) {
8794
this.source = source;
8895
}
8996

97+
public String getApiToken() {
98+
return this.apiToken;
99+
}
100+
90101
public void setApiToken(String apiToken) {
91102
this.apiToken = apiToken;
92103
}
93104

105+
/**
106+
* Returns the effective URI of the wavefront instance. This will not be the same URI
107+
* given through {@link #setUri(URI)} when a proxy is used.
108+
* @return the effective URI of the wavefront instance
109+
*/
110+
public URI getEffectiveUri() {
111+
if (usesProxy()) {
112+
// See io.micrometer.wavefront.WavefrontMeterRegistry.getWavefrontReportingUri
113+
return URI.create(this.uri.toString().replace("proxy://", "http://"));
114+
}
115+
return this.uri;
116+
}
117+
94118
/**
95119
* Returns the API token or throws an exception if the API token is mandatory. If a
96120
* proxy is used, the API token is optional.
@@ -104,14 +128,6 @@ public String getApiTokenOrThrow() {
104128
return this.apiToken;
105129
}
106130

107-
public Sender getSender() {
108-
return this.sender;
109-
}
110-
111-
public Metrics getMetrics() {
112-
return this.metrics;
113-
}
114-
115131
public String getSourceOrDefault() {
116132
if (this.source != null) {
117133
return this.source;
@@ -132,10 +148,6 @@ private boolean usesProxy() {
132148
return "proxy".equals(this.uri.getScheme());
133149
}
134150

135-
public Tracing getTracing() {
136-
return this.tracing;
137-
}
138-
139151
public static class Sender {
140152

141153
/**
@@ -252,7 +264,12 @@ public void setBatchSize(Integer batchSize) {
252264
public static class Tracing {
253265

254266
/**
255-
* Service name.
267+
* Application name. Defaults to 'spring.application.name'.
268+
*/
269+
private String applicationName;
270+
271+
/**
272+
* Service name. Defaults to 'spring.application.name'.
256273
*/
257274
private String serviceName;
258275

@@ -264,6 +281,14 @@ public void setServiceName(String serviceName) {
264281
this.serviceName = serviceName;
265282
}
266283

284+
public String getApplicationName() {
285+
return this.applicationName;
286+
}
287+
288+
public void setApplicationName(String applicationName) {
289+
this.applicationName = applicationName;
290+
}
291+
267292
}
268293

269294
}

0 commit comments

Comments
 (0)