use of org.apache.camel.component.properties.ServicePortPropertiesFunction in project camel by apache.
the class ZipkinTracer method doStart.
@Override
protected void doStart() throws Exception {
ObjectHelper.notNull(camelContext, "CamelContext", this);
camelContext.getManagementStrategy().addEventNotifier(eventNotifier);
if (!camelContext.getRoutePolicyFactories().contains(this)) {
camelContext.addRoutePolicyFactory(this);
}
if (spanCollector == null) {
if (hostName != null && port > 0) {
LOG.info("Configuring Zipkin ScribeSpanCollector using host: {} and port: {}", hostName, port);
spanCollector = new ScribeSpanCollector(hostName, port);
} else {
// is there a zipkin service setup as ENV variable to auto register a scribe span collector
String host = new ServiceHostPropertiesFunction().apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE);
String port = new ServicePortPropertiesFunction().apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE);
if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
LOG.info("Auto-configuring Zipkin ScribeSpanCollector using host: {} and port: {}", host, port);
int num = camelContext.getTypeConverter().mandatoryConvertTo(Integer.class, port);
spanCollector = new ScribeSpanCollector(host, num);
}
}
}
if (spanCollector == null) {
// Try to lookup the span collector from the registry if only one instance is present
Set<SpanCollector> collectors = camelContext.getRegistry().findByType(SpanCollector.class);
if (collectors.size() == 1) {
spanCollector = collectors.iterator().next();
}
}
ObjectHelper.notNull(spanCollector, "SpanCollector", this);
if (clientServiceMappings.isEmpty() && serverServiceMappings.isEmpty()) {
LOG.warn("No service name(s) has been mapped in clientServiceMappings or serverServiceMappings. Camel will fallback and use endpoint uris as service names.");
useFallbackServiceNames = true;
}
// create braves mapped per service name
for (Map.Entry<String, String> entry : clientServiceMappings.entrySet()) {
String pattern = entry.getKey();
String serviceName = entry.getValue();
createBraveForService(pattern, serviceName);
}
for (Map.Entry<String, String> entry : serverServiceMappings.entrySet()) {
String pattern = entry.getKey();
String serviceName = entry.getValue();
createBraveForService(pattern, serviceName);
}
ServiceHelper.startServices(spanCollector, eventNotifier);
}
Aggregations