Search in sources :

Example 1 with ScribeSpanCollector

use of com.github.kristofa.brave.scribe.ScribeSpanCollector in project camel by apache.

the class ZipkinOneRouteFallbackScribe method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    zipkin = new ZipkinTracer();
    // no service so should use fallback naming style
    // we do not want to trace any direct endpoints
    zipkin.addExcludePattern("direct:*");
    zipkin.setIncludeMessageBody(true);
    zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
    // attaching ourself to CamelContext
    zipkin.init(context);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) ScribeSpanCollector(com.github.kristofa.brave.scribe.ScribeSpanCollector) ZipkinTracer(org.apache.camel.zipkin.ZipkinTracer)

Example 2 with ScribeSpanCollector

use of com.github.kristofa.brave.scribe.ScribeSpanCollector in project camel by apache.

the class ZipkinOneRouteScribe method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    zipkin = new ZipkinTracer();
    // we have one route as service
    zipkin.addClientServiceMapping("seda:cat", "cat");
    zipkin.addServerServiceMapping("seda:cat", "cat");
    zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
    // attaching ourself to CamelContext
    zipkin.init(context);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) ScribeSpanCollector(com.github.kristofa.brave.scribe.ScribeSpanCollector) ZipkinTracer(org.apache.camel.zipkin.ZipkinTracer)

Example 3 with ScribeSpanCollector

use of com.github.kristofa.brave.scribe.ScribeSpanCollector in project camel by apache.

the class ZipkinSimpleRouteScribe method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    zipkin = new ZipkinTracer();
    // we have one route as service
    zipkin.addClientServiceMapping("seda:dude", "dude");
    zipkin.addServerServiceMapping("seda:dude", "dude");
    zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
    // attaching ourself to CamelContext
    zipkin.init(context);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) ScribeSpanCollector(com.github.kristofa.brave.scribe.ScribeSpanCollector) ZipkinTracer(org.apache.camel.zipkin.ZipkinTracer)

Example 4 with ScribeSpanCollector

use of com.github.kristofa.brave.scribe.ScribeSpanCollector in project camel by apache.

the class ZipkinTwoRouteScribe method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext context = super.createCamelContext();
    zipkin = new ZipkinTracer();
    // we have 2 routes as services
    zipkin.addClientServiceMapping("seda:cat", "cat");
    zipkin.addServerServiceMapping("seda:cat", "cat");
    zipkin.addClientServiceMapping("seda:dog", "dog");
    zipkin.addServerServiceMapping("seda:dog", "dog");
    // capture message body as well
    zipkin.setIncludeMessageBody(true);
    zipkin.setSpanCollector(new ScribeSpanCollector(ip, 9410));
    // attaching ourself to CamelContext
    zipkin.init(context);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) ScribeSpanCollector(com.github.kristofa.brave.scribe.ScribeSpanCollector) ZipkinTracer(org.apache.camel.zipkin.ZipkinTracer)

Example 5 with ScribeSpanCollector

use of com.github.kristofa.brave.scribe.ScribeSpanCollector 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

ScribeSpanCollector (com.github.kristofa.brave.scribe.ScribeSpanCollector)8 CamelContext (org.apache.camel.CamelContext)7 ZipkinTracer (org.apache.camel.zipkin.ZipkinTracer)7 SpanCollector (com.github.kristofa.brave.SpanCollector)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