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/hooks/active_record.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.33.0'

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

Returns:

Raises:

  • (Aws::Xray::NotSetError)

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



45
46
47
# File 'lib/aws/xray.rb', line 45

def current_context
  Context.current
end

.disable_trace(id, &block) ⇒ Object

Returns result of given block.

Parameters:

  • id (Symbol)

Returns:

  • (Object)

    result of given block



67
68
69
70
71
72
73
# File 'lib/aws/xray.rb', line 67

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

.overwrite(name:, &block) ⇒ Object

Overwrite under lying tracing name at once. If current context is not set to current thread, do nothing.

Parameters:

  • name (String)

Returns:

  • (Object)

    result of given block



79
80
81
82
83
84
85
# File 'lib/aws/xray.rb', line 79

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

Returns result of given block.

Yields:

Returns:

  • (Object)

    result of given block



57
58
59
60
61
62
63
# File 'lib/aws/xray.rb', line 57

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)

    whether tracing context is started or not.



38
39
40
# File 'lib/aws/xray.rb', line 38

def started?
  Context.started?
end

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

Returns result of given block.

Parameters:

  • name (String) (defaults to: nil)

    a logical name of this tracing context.

Returns:

  • (Object)

    result of given block



28
29
30
31
32
33
34
35
# File 'lib/aws/xray.rb', line 28

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

Returns result of given block.

Parameters:

Returns:

  • (Object)

    result of given block



51
52
53
# File 'lib/aws/xray.rb', line 51

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