Module: Aws::Xray

Defined in:
lib/aws/xray.rb,
lib/aws/xray/sql.rb,
lib/aws/xray/rack.rb,
lib/aws/xray/cause.rb,
lib/aws/xray/error.rb,
lib/aws/xray/rails.rb,
lib/aws/xray/trace.rb,
lib/aws/xray/client.rb,
lib/aws/xray/errors.rb,
lib/aws/xray/worker.rb,
lib/aws/xray/context.rb,
lib/aws/xray/faraday.rb,
lib/aws/xray/request.rb,
lib/aws/xray/segment.rb,
lib/aws/xray/sockets.rb,
lib/aws/xray/version.rb,
lib/aws/xray/response.rb,
lib/aws/xray/subsegment.rb,
lib/aws/xray/hooks/rsolr.rb,
lib/aws/xray/configuration.rb,
lib/aws/xray/header_parser.rb,
lib/aws/xray/caller_builder.rb,
lib/aws/xray/error_handlers.rb,
lib/aws/xray/hooks/net_http.rb,
lib/aws/xray/version_detector.rb,
lib/aws/xray/annotation_normalizer.rb

Defined Under Namespace

Modules: AnnotationNormalizer, CallerBuilder, HeaderParser, Hooks Classes: BaseError, CanNotSendAllByteError, Cause, Client, Configuration, Context, DefaultErrorHandler, Error, ErrorHandlerWithSentry, Faraday, IoSocket, MissingNameError, NotSetError, NullSocket, QueueIsFullError, Rack, Railtie, Request, Response, Segment, SegmentDidNotStartError, Sql, Subsegment, TestSocket, Trace, VersionDetector, Worker

Constant Summary collapse

TRACE_HEADER =
'X-Amzn-Trace-Id'.freeze
VERSION =
'0.39.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



21
22
23
# File 'lib/aws/xray.rb', line 21

def config
  @config
end

Class Method Details

.current_contextAws::Xray::Context

Return current tracing context set to current thread.

Returns:

Raises:

  • (Aws::Xray::NotSetError)

    when the current context is not yet set. Call this method after start tracing with ‘Aws::Xray.trace`.



67
68
69
# File 'lib/aws/xray.rb', line 67

def current_context
  Context.current
end

.disable_trace(id, &block) ⇒ Object

Temporary disabling tracing for given id in given block. CAUTION: the disabling will NOT be propagated between threads!!

Parameters:

  • id (Symbol)

Returns:

  • (Object)

    result of given block



84
85
86
87
88
89
90
# File 'lib/aws/xray.rb', line 84

def disable_trace(id, &block)
  if started?
    current_context.disable_trace(id, &block)
  else
    block.call
  end
end

.disabled?(id) ⇒ Boolean

Returns whether tracing is disabled with ‘.disable_trace` for given `id`.

Parameters:

  • id (Symbol)

Returns:

  • (Boolean)


95
96
97
# File 'lib/aws/xray.rb', line 95

def disabled?(id)
  started? && current_context.disabled?(id)
end

.overwrite(name:, &block) ⇒ Object

Temporary overwrite subsegment with the name in the block. The overwriting will be occured only one time. If current context is not set to current thread, do nothing. CAUTION: the injection will NOT be propagated between threads!!

Parameters:

  • name (String)

Returns:

  • (Object)

    result of given block



106
107
108
109
110
111
112
# File 'lib/aws/xray.rb', line 106

def overwrite(name:, &block)
  if started?
    current_context.overwrite(name: name, &block)
  else
    block.call
  end
end

.start_subsegment(name:, remote:) {|Aws::Xray::Subsegment| ... } ⇒ Object

Start subsegment if current thread has tracing context then send the subsegment to X-Ray daemon. Rescue all exceptions and record the exception to the subsegment. Then re-raise the exception.

Yields:

Returns:

  • (Object)

    result of given block



48
49
50
51
52
53
54
# File 'lib/aws/xray.rb', line 48

def start_subsegment(name:, remote:, &block)
  if started?
    current_context.start_subsegment(name: name, remote: remote, &block)
  else
    block.call(Subsegment.build_null)
  end
end

.started?Boolean

Returns whether tracing context is started or not.

Returns:

  • (Boolean)


58
59
60
# File 'lib/aws/xray.rb', line 58

def started?
  Context.started?
end

.trace(name: nil, trace: Trace.generate) ⇒ Object

Start new tracing context and segment. If ‘trace` is given it start tracing context following given `trace`. If `name` is omitted, it uses global application name. Rescue all exceptions and record the exception to the segment. Then re-raise the exception.

Parameters:

  • name (String) (defaults to: nil)

    a logical name of this tracing context.

Returns:

  • (Object)

    result of given block



33
34
35
36
37
38
39
40
# File 'lib/aws/xray.rb', line 33

def trace(name: nil, trace: Trace.generate)
  name = name || config.name || raise(MissingNameError)
  Context.with_new_context(name, trace) do
    Context.current.start_segment do |seg|
      yield seg
    end
  end
end

.with_given_context(context, &block) ⇒ Object

Set tracing context to current thread with given context object.

Parameters:

Returns:

  • (Object)

    result of given block



75
76
77
# File 'lib/aws/xray.rb', line 75

def with_given_context(context, &block)
  Context.with_given_context(context, &block)
end