Class AWSPropagation<K>

java.lang.Object
brave.propagation.aws.AWSPropagation<K>
All Implemented Interfaces:
brave.propagation.Propagation<K>

public final class AWSPropagation<K>
extends java.lang.Object
implements brave.propagation.Propagation<K>
Utility for working with Amazon Web Services Trace IDs, for example reading from headers or environment variables. x-amzn-trace-id is primarily for Amazon's X-Ray service, but it is also integrated with AWS ALB, API Gateway and Lambda.

For example, if you are in a lambda environment, you can read the incoming context like this:


 span = tracer.nextSpan(AWSPropagation.extractLambda());
 

Details

x-amzn-trace-id (and the lambda equivalent _X_AMZN_TRACE_ID) follows RFC 6265 style syntax (https://tools.ietf.org/html/rfc6265#section-2.2): fields are split on semicolon and optional whitespace.

Description of the Root (or Self) field from AWS CLI help:

A trace_id consists of three numbers separated by hyphens. For example, 1-58406520-a006649127e371903a2de979. This includes:

 
  • The version number, i.e. 1
  • The time of the original request, in Unix epoch time, in 8 hexadecimal digits. For example, 10:00AM December 2nd, 2016 PST in epoch timeis 1480615200 seconds, or 58406520 in hexadecimal.
  • A 96-bit identifier for the trace, globally unique, in 24 hexadecimal digits.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface brave.propagation.Propagation

    brave.propagation.Propagation.Factory, brave.propagation.Propagation.Getter<C extends java.lang.Object,​K extends java.lang.Object>, brave.propagation.Propagation.KeyFactory<K extends java.lang.Object>, brave.propagation.Propagation.Setter<C extends java.lang.Object,​K extends java.lang.Object>
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static brave.propagation.Propagation.Factory FACTORY  
    static int ROOT_LENGTH  

    Fields inherited from interface brave.propagation.Propagation

    B3_SINGLE_STRING, B3_STRING
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String currentTraceId()
    Returns the current traceId(TraceContext) or null if not available
    static brave.propagation.TraceContextOrSamplingFlags extract​(java.lang.String amznTraceId)
    Like TraceContext.Extractor.extract(Object) except reading from a single field.
    static brave.propagation.TraceContextOrSamplingFlags extractLambda()
    This is used for extracting from the AWS lambda environment variable _X_AMZN_TRACE_ID.
    <C> brave.propagation.TraceContext.Extractor<C> extractor​(brave.propagation.Propagation.Getter<C,​K> getter)  
    <C> brave.propagation.TraceContext.Injector<C> injector​(brave.propagation.Propagation.Setter<C,​K> setter)  
    java.util.List<K> keys()
    returns the name of the header field: "x-amzn-trace-id"
    static java.lang.String traceId​(brave.propagation.TraceContext context)
    Used for log correlation or tag values

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • keys

      public java.util.List<K> keys()
      returns the name of the header field: "x-amzn-trace-id"
      Specified by:
      keys in interface brave.propagation.Propagation<K>
    • injector

      public <C> brave.propagation.TraceContext.Injector<C> injector​(brave.propagation.Propagation.Setter<C,​K> setter)
      Specified by:
      injector in interface brave.propagation.Propagation<K>
    • currentTraceId

      @Nullable public static java.lang.String currentTraceId()
      Returns the current traceId(TraceContext) or null if not available
    • traceId

      @Nullable public static java.lang.String traceId​(brave.propagation.TraceContext context)
      Used for log correlation or tag values
      Returns:
      a formatted Root field like "1-58406520-a006649127e371903a2de979" or null if the context was not created from an instance of AWSPropagation.
    • extractor

      public <C> brave.propagation.TraceContext.Extractor<C> extractor​(brave.propagation.Propagation.Getter<C,​K> getter)
      Specified by:
      extractor in interface brave.propagation.Propagation<K>
    • extractLambda

      public static brave.propagation.TraceContextOrSamplingFlags extractLambda()
      This is used for extracting from the AWS lambda environment variable _X_AMZN_TRACE_ID.
      See Also:
      extract(String)
    • extract

      public static brave.propagation.TraceContextOrSamplingFlags extract​(java.lang.String amznTraceId)
      Like TraceContext.Extractor.extract(Object) except reading from a single field.