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

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
    Header value kept in the message of the exchange

    Fields 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds an exclude pattern that will disable tracing for Camel messages that matches the pattern.
    org.apache.camel.spi.RoutePolicy
    createRoutePolicy(org.apache.camel.CamelContext camelContext, String routeId, org.apache.camel.NamedNode route)
     
    protected void
     
    protected void
     
    org.apache.camel.CamelContext
     
    Returns the set of currently excluded routes.
    getSegmentDecorator(org.apache.camel.Endpoint endpoint)
     
    protected com.amazonaws.xray.entities.Entity
    getTraceEntityFromExchange(org.apache.camel.Exchange exchange)
     
    org.apache.camel.spi.InterceptStrategy
    Returns the currently used tracing strategy which is responsible for tracking invoked EIP or beans.
    void
    init(org.apache.camel.CamelContext camelContext)
    Initializes this AWS XRay tracer implementation as service within the Camel environment.
    static String
    Removes invalid characters from AWS XRay (sub-)segment names and replaces the invalid characters with an underscore character.
    void
    setCamelContext(org.apache.camel.CamelContext camelContext)
     
    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.
    void
    setTracingStrategy(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, suspend

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.camel.Service

    build, close, init, start, stop

    Methods inherited from interface org.apache.camel.ShutdownableService

    shutdown

    Methods inherited from interface org.apache.camel.StatefulService

    getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending

    Methods inherited from interface org.apache.camel.SuspendableService

    isSuspended, resume, suspend
  • Field Details

  • Constructor Details

    • XRayTracer

      public XRayTracer()
  • Method Details

    • setCamelContext

      public void setCamelContext(org.apache.camel.CamelContext camelContext)
      Specified by:
      setCamelContext in interface org.apache.camel.CamelContextAware
    • getCamelContext

      public org.apache.camel.CamelContext getCamelContext()
      Specified by:
      getCamelContext in interface org.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:
      createRoutePolicy in interface org.apache.camel.spi.RoutePolicyFactory
    • doInit

      protected void doInit() throws Exception
      Overrides:
      doInit in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doShutdown

      protected void doShutdown() throws Exception
      Overrides:
      doShutdown in class org.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