Search in sources :

Example 1 with ServiceHostPropertiesFunction

use of org.apache.camel.component.properties.ServiceHostPropertiesFunction 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);
}
Also used : ServicePortPropertiesFunction(org.apache.camel.component.properties.ServicePortPropertiesFunction) ScribeSpanCollector(com.github.kristofa.brave.scribe.ScribeSpanCollector) ScribeSpanCollector(com.github.kristofa.brave.scribe.ScribeSpanCollector) SpanCollector(com.github.kristofa.brave.SpanCollector) HashMap(java.util.HashMap) Map(java.util.Map) ServiceHostPropertiesFunction(org.apache.camel.component.properties.ServiceHostPropertiesFunction) Endpoint(org.apache.camel.Endpoint)

Aggregations

SpanCollector (com.github.kristofa.brave.SpanCollector)1 ScribeSpanCollector (com.github.kristofa.brave.scribe.ScribeSpanCollector)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Endpoint (org.apache.camel.Endpoint)1 ServiceHostPropertiesFunction (org.apache.camel.component.properties.ServiceHostPropertiesFunction)1 ServicePortPropertiesFunction (org.apache.camel.component.properties.ServicePortPropertiesFunction)1