Package org.apache.camel.zipkin
Class ZipkinTracer
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.zipkin.ZipkinTracer
-
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.CamelContextAware,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.RoutePolicyFactory,org.apache.camel.StatefulService,org.apache.camel.StaticService,org.apache.camel.SuspendableService
@ManagedResource(description="ZipkinTracer") public class ZipkinTracer extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.RoutePolicyFactory, org.apache.camel.StaticService, org.apache.camel.CamelContextAwareTo use Zipkin with Camel then setup thisZipkinTracerin your Camel application. Events (span) are captured for incoming and outgoing messages being sent to/from Camel. This means you need to configure which which Camel endpoints that maps to zipkin service names. The mapping can be configured using- route id - A Camel route id
- endpoint url - A Camel endpoint url
PatternHelper.matchPattern(String, String)andEndpointHelper.matchEndpoint(CamelContext, String, String)To match all Camel messages you can use * in the pattern and configure that to the same service name.
If no mapping has been configured then Camel will fallback and use endpoint uri's as service names. However its recommended to configure service mappings so you can use human logic names instead of Camel endpoint uris in the names. Camel will auto-configure aspan reporterone hasn't been explicitly configured, and if the hostname and port to a zipkin collector has been configured as environment variables- ZIPKIN_COLLECTOR_HTTP_SERVICE_HOST - The http hostname
- ZIPKIN_COLLECTOR_HTTP_SERVICE_PORT - The port number
- ZIPKIN_COLLECTOR_THRIFT_SERVICE_HOST - The Scribe (Thrift RPC) hostname
- ZIPKIN_COLLECTOR_THRIFT_SERVICE_PORT - The port number
EventNotifierandRoutePolicythat allows to trap when Camel starts/ends anExchangebeing routed using theRoutePolicyand during the routing if theExchangesends messages, then we track them using theEventNotifier.
-
-
Constructor Summary
Constructors Constructor Description ZipkinTracer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClientServiceMapping(String pattern, String serviceName)Adds a client service mapping that matches Camel events to the given zipkin service name.voidaddExcludePattern(String pattern)Adds an exclude pattern that will disable tracing with zipkin for Camel messages that matches the pattern.protected voidaddProducerComponentSpanKind(String component, brave.Span.Kind kind)voidaddServerServiceMapping(String pattern, String serviceName)Adds a server service mapping that matches Camel events to the given zipkin service name.org.apache.camel.spi.RoutePolicycreateRoutePolicy(org.apache.camel.CamelContext camelContext, String routeId, org.apache.camel.NamedNode route)protected voiddoInit()protected voiddoShutdown()org.apache.camel.CamelContextgetCamelContext()Map<String,String>getClientCustomTags()Custom tags that are added for all client requests.Map<String,String>getClientServiceMappings()protected brave.Span.KindgetConsumerComponentSpanKind(org.apache.camel.Endpoint endpoint)StringgetEndpoint()Set<String>getExcludePatterns()StringgetHostName()intgetPort()protected brave.Span.KindgetProducerComponentSpanKind(org.apache.camel.Endpoint endpoint)floatgetRate()Map<String,String>getServerServiceMappings()StringgetServiceName()zipkin2.reporter.Reporter<zipkin2.Span>getSpanReporter()Returns the reporter used to send timing data (spans) to the zipkin server.voidinit(org.apache.camel.CamelContext camelContext)Registers thisZipkinTraceron theCamelContextif not already registered.booleanisIncludeMessageBody()booleanisIncludeMessageBodyStreams()voidsetCamelContext(org.apache.camel.CamelContext camelContext)voidsetClientCustomTags(Map<String,String> clientCustomTags)Custom tags that should be included on all client requests, in addition to the tags specified on the Exchange viacamel.client.customtags.voidsetClientServiceMappings(Map<String,String> clientServiceMappings)voidsetEndpoint(String endpoint)Sets the POST URL for zipkin's v2 api, usually "http://zipkinhost:9411/api/v2/spans"voidsetExcludePatterns(Set<String> excludePatterns)voidsetHostName(String hostName)Sets the hostname for the remote zipkin scribe collector.voidsetIncludeMessageBody(boolean includeMessageBody)Whether to include the Camel message body in the zipkin traces.voidsetIncludeMessageBodyStreams(boolean includeMessageBodyStreams)Whether to include message bodies that are stream based in the zipkin traces.voidsetPort(int port)Sets the port number for the remote zipkin scribe collector.voidsetRate(float rate)Configures a rate that decides how many events should be traced by zipkin.voidsetServerServiceMappings(Map<String,String> serverServiceMappings)voidsetServiceName(String serviceName)To use a global service name that matches all Camel eventsvoidsetSpanReporter(zipkin2.reporter.Reporter<zipkin2.Span> spanReporter)Sets the reporter used to send timing data (spans) to the zipkin server.-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doStart, doStop, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
createRoutePolicy
public org.apache.camel.spi.RoutePolicy createRoutePolicy(org.apache.camel.CamelContext camelContext, String routeId, org.apache.camel.NamedNode route)- Specified by:
createRoutePolicyin interfaceorg.apache.camel.spi.RoutePolicyFactory
-
init
public void init(org.apache.camel.CamelContext camelContext)
Registers thisZipkinTraceron theCamelContextif not already registered.
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContextin interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContextin interfaceorg.apache.camel.CamelContextAware
-
getEndpoint
@ManagedAttribute(description="The POST URL for zipkin\'s v2 api.") public String getEndpoint()
-
setEndpoint
public void setEndpoint(String endpoint)
Sets the POST URL for zipkin's v2 api, usually "http://zipkinhost:9411/api/v2/spans"
-
getHostName
@ManagedAttribute(description="The hostname for the remote zipkin scribe collector.") public String getHostName()
-
setHostName
public void setHostName(String hostName)
Sets the hostname for the remote zipkin scribe collector.
-
getPort
@ManagedAttribute(description="The port number for the remote zipkin scribe collector.") public int getPort()
-
setPort
public void setPort(int port)
Sets the port number for the remote zipkin scribe collector.
-
getRate
@ManagedAttribute(description="Rates how many events should be traced by zipkin. The rate is expressed as a percentage (1.0f = 100%, 0.5f is 50%, 0.1f is 10%).") public float getRate()
-
setRate
public void setRate(float rate)
Configures a rate that decides how many events should be traced by zipkin. The rate is expressed as a percentage (1.0f = 100%, 0.5f is 50%, 0.1f is 10%).- Parameters:
rate- minimum sample rate is 0.0001, or 0.01% of traces
-
setSpanReporter
public void setSpanReporter(zipkin2.reporter.Reporter<zipkin2.Span> spanReporter)
Sets the reporter used to send timing data (spans) to the zipkin server.
-
getSpanReporter
public zipkin2.reporter.Reporter<zipkin2.Span> getSpanReporter()
Returns the reporter used to send timing data (spans) to the zipkin server.
-
getServiceName
public String getServiceName()
-
setServiceName
public void setServiceName(String serviceName)
To use a global service name that matches all Camel events
-
setClientServiceMappings
public void setClientServiceMappings(Map<String,String> clientServiceMappings)
-
addClientServiceMapping
public void addClientServiceMapping(String pattern, String serviceName)
Adds a client service mapping that matches Camel events to the given zipkin service name. See more details at the class javadoc.- Parameters:
pattern- the pattern such as route id, endpoint urlserviceName- the zipkin service name
-
setServerServiceMappings
public void setServerServiceMappings(Map<String,String> serverServiceMappings)
-
addServerServiceMapping
public void addServerServiceMapping(String pattern, String serviceName)
Adds a server service mapping that matches Camel events to the given zipkin service name. See more details at the class javadoc.- Parameters:
pattern- the pattern such as route id, endpoint urlserviceName- the zipkin service name
-
addExcludePattern
public void addExcludePattern(String pattern)
Adds an exclude pattern that will disable tracing with zipkin for Camel messages that matches the pattern.- Parameters:
pattern- the pattern such as route id, endpoint url
-
isIncludeMessageBody
@ManagedAttribute(description="Whether to include the Camel message body in the zipkin traces") public boolean isIncludeMessageBody()
-
setIncludeMessageBody
@ManagedAttribute(description="Whether to include the Camel message body in the zipkin traces") public void setIncludeMessageBody(boolean includeMessageBody)
Whether to include the Camel message body in the zipkin traces. This is not recommended for production usage, or when having big payloads. You can limit the size by configuring the max debug log size. By default message bodies that are stream based are not included. You can use the optionsetIncludeMessageBodyStreams(boolean)to turn that on.
-
isIncludeMessageBodyStreams
@ManagedAttribute(description="Whether to include stream based Camel message bodies in the zipkin traces") public boolean isIncludeMessageBodyStreams()
-
setIncludeMessageBodyStreams
@ManagedAttribute(description="Whether to include stream based Camel message bodies in the zipkin traces") public void setIncludeMessageBodyStreams(boolean includeMessageBodyStreams)
Whether to include message bodies that are stream based in the zipkin traces. This requires enabling stream caching on the routes or globally on the CamelContext. This is not recommended for production usage, or when having big payloads. You can limit the size by configuring the max debug log size.
-
setClientCustomTags
public void setClientCustomTags(Map<String,String> clientCustomTags)
Custom tags that should be included on all client requests, in addition to the tags specified on the Exchange viacamel.client.customtags.- Parameters:
clientCustomTags- custom tags to be added for all client requests- See Also:
ZipkinClientRequestAdapter.onRequest(Exchange, SpanCustomizer)
-
getClientCustomTags
public Map<String,String> getClientCustomTags()
Custom tags that are added for all client requests.- Returns:
- custom tags added for all client requests
- See Also:
ZipkinClientRequestAdapter.onRequest(Exchange, SpanCustomizer)
-
doInit
protected void doInit() throws Exception- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doShutdown
protected void doShutdown() throws Exception- Overrides:
doShutdownin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
getProducerComponentSpanKind
protected brave.Span.Kind getProducerComponentSpanKind(org.apache.camel.Endpoint endpoint)
-
addProducerComponentSpanKind
protected void addProducerComponentSpanKind(String component, brave.Span.Kind kind)
-
getConsumerComponentSpanKind
protected brave.Span.Kind getConsumerComponentSpanKind(org.apache.camel.Endpoint endpoint)
-
-