Class XRayTracer
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.component.aws.xray.XRayTracer
-
- 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
public class XRayTracer extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.RoutePolicyFactory, org.apache.camel.StaticService, org.apache.camel.CamelContextAwareTo use AWS XRay with Camel setup thisXRayTracerin your Camel application. This class uses aRoutePolicyas well as aEventNotifierinternally to manage the creation and termination of AWS XRaySegmentsandSubsegmentsonce an exchange was created, forwarded or closed in order to allow monitoring the lifetime metrics of the exchange. AInterceptStrategyis used in order to track invocations and durations of EIP patterns used in processed routes. If no strategy is passed while configuration viasetTracingStrategy(InterceptStrategy), aNoopTracingStrategywill be used by default which will not monitor any invocations at all. By default every invoked route will be tracked by AWS XRay. If certain routes shell not be trackedaddExcludePattern(String)andsetExcludePatterns(Set)can be used to provide the routeId of the routes to exclude from monitoring.
-
-
Field Summary
Fields Modifier and Type Field Description static StringXRAY_TRACE_ENTITYstatic StringXRAY_TRACE_IDHeader value kept in the message of the exchange
-
Constructor Summary
Constructors Constructor Description XRayTracer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExcludePattern(String pattern)Adds an exclude pattern that will disable tracing for Camel messages that matches the pattern.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()Set<String>getExcludePatterns()Returns the set of currently excluded routes.protected SegmentDecoratorgetSegmentDecorator(org.apache.camel.Endpoint endpoint)protected com.amazonaws.xray.entities.EntitygetTraceEntityFromExchange(org.apache.camel.Exchange exchange)org.apache.camel.spi.InterceptStrategygetTracingStrategy()Returns the currently used tracing strategy which is responsible for tracking invoked EIP or beans.voidinit(org.apache.camel.CamelContext camelContext)Initializes this AWS XRay tracer implementation as service within the Camel environment.static StringsanitizeName(String name)Removes invalid characters from AWS XRay (sub-)segment names and replaces the invalid characters with an underscore character.voidsetCamelContext(org.apache.camel.CamelContext camelContext)voidsetExcludePatterns(Set<String> excludePatterns)Excludes all of the routes matching any of the contained routeIds within the given argument from tracking by this tracer implementation.voidsetTracingStrategy(org.apache.camel.spi.InterceptStrategy tracingStrategy)Specifies the instance responsible for tracking invoked EIP and beans with AWS XRay.-
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
-
-
-
-
Field Detail
-
XRAY_TRACE_ID
public static final String XRAY_TRACE_ID
Header value kept in the message of the exchange- See Also:
- Constant Field Values
-
XRAY_TRACE_ENTITY
public static final String XRAY_TRACE_ENTITY
- See Also:
- Constant Field Values
-
-
Method Detail
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContextin interfaceorg.apache.camel.CamelContextAware
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContextin interfaceorg.apache.camel.CamelContextAware
-
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
-
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
-
init
public void init(org.apache.camel.CamelContext camelContext)
Initializes this AWS XRay tracer implementation as service within the Camel environment.- Parameters:
camelContext- The context to register this tracer as service with
-
getTracingStrategy
public org.apache.camel.spi.InterceptStrategy getTracingStrategy()
Returns the currently used tracing strategy which is responsible for tracking invoked EIP or beans.- Returns:
- The currently used tracing strategy
-
setTracingStrategy
public void setTracingStrategy(org.apache.camel.spi.InterceptStrategy tracingStrategy)
Specifies the instance responsible for tracking invoked EIP and beans with AWS XRay.- Parameters:
tracingStrategy- The instance which tracks invoked EIP and beans
-
getExcludePatterns
public Set<String> getExcludePatterns()
Returns the set of currently excluded routes. Any route ID specified in the returned set will not be monitored by this AWS XRay tracer implementation.- Returns:
- The IDs of the currently excluded routes for which no tracking will be performed
-
setExcludePatterns
public void setExcludePatterns(Set<String> excludePatterns)
Excludes all of the routes matching any of the contained routeIds within the given argument from tracking by this tracer implementation. Excluded routes will not appear within the AWS XRay monitoring.- Parameters:
excludePatterns- A set of routeIds which should not be tracked by this tracer
-
addExcludePattern
public void addExcludePattern(String pattern)
Adds an exclude pattern that will disable tracing for Camel messages that matches the pattern.- Parameters:
pattern- The pattern such as route id, endpoint url
-
getSegmentDecorator
protected SegmentDecorator getSegmentDecorator(org.apache.camel.Endpoint endpoint)
-
getTraceEntityFromExchange
protected com.amazonaws.xray.entities.Entity getTraceEntityFromExchange(org.apache.camel.Exchange exchange)
-
sanitizeName
public static String sanitizeName(String name)
Removes invalid characters from AWS XRay (sub-)segment names and replaces the invalid characters with an underscore character.- Parameters:
name- The name to assign to an AWS XRay (sub-)segment- Returns:
- The sanitized name of the (sub-)segment
-
-