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.HasCamelContext,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.CamelContextAware
To use AWS XRay with Camel setup this
XRayTracer in your Camel application.
This class uses a RoutePolicy as well as a EventNotifier
internally to manage the creation and termination of AWS XRay Segments and Subsegments once an exchange was created, forwarded or closed in order to allow monitoring the lifetime metrics of
the exchange.
A InterceptStrategy is used in order to track invocations and durations of EIP patterns used in processed
routes. If no strategy is passed while configuration via setTracingStrategy(InterceptStrategy), a
NoopTracingStrategy will 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 tracked
addExcludePattern(String) and setExcludePatterns(Set) can be used to provide the routeId
of the routes to exclude from monitoring.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringHeader value kept in the message of the exchangeFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExcludePattern(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 voidorg.apache.camel.CamelContextReturns 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.InterceptStrategyReturns 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, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
XRAY_TRACE_ID
Header value kept in the message of the exchange- See Also:
-
XRAY_TRACE_ENTITY
- See Also:
-
-
Constructor Details
-
XRayTracer
public XRayTracer()
-
-
Method Details
-
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.spi.HasCamelContext
-
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
- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doShutdown
- 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
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
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
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
-
getTraceEntityFromExchange
protected com.amazonaws.xray.entities.Entity getTraceEntityFromExchange(org.apache.camel.Exchange exchange) -
sanitizeName
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
-