You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::XRay::Client

Inherits:
Seahorse::Client::Base show all
Defined in:
(unknown)

Overview

An API client for AWS X-Ray. To construct a client, you need to configure a :region and :credentials.

xray = Aws::XRay::Client.new(
  region: region_name,
  credentials: credentials,
  # ...
)

See #initialize for a full list of supported configuration options.

Region

You can configure a default region in the following locations:

  • ENV['AWS_REGION']
  • Aws.config[:region]

Go here for a list of supported regions.

Credentials

Default credentials are loaded automatically from the following locations:

  • ENV['AWS_ACCESS_KEY_ID'] and ENV['AWS_SECRET_ACCESS_KEY']
  • Aws.config[:credentials]
  • The shared credentials ini file at ~/.aws/credentials (more information)
  • From an instance profile when running on EC2

You can also construct a credentials object from one of the following classes:

Alternatively, you configure credentials with :access_key_id and :secret_access_key:

# load credentials from disk
creds = YAML.load(File.read('/path/to/secrets'))

Aws::XRay::Client.new(
  access_key_id: creds['access_key_id'],
  secret_access_key: creds['secret_access_key']
)

Always load your credentials from outside your application. Avoid configuring credentials statically and never commit them to source control.

Instance Attribute Summary

Attributes inherited from Seahorse::Client::Base

#config, #handlers

Constructor collapse

API Operations collapse

Instance Method Summary collapse

Methods inherited from Seahorse::Client::Base

add_plugin, api, #build_request, clear_plugins, define, new, #operation, #operation_names, plugins, remove_plugin, set_api, set_plugins

Methods included from Seahorse::Client::HandlerBuilder

#handle, #handle_request, #handle_response

Constructor Details

#initialize(options = {}) ⇒ Aws::XRay::Client

Constructs an API client.

Options Hash (options):

  • :access_key_id (String)

    Used to set credentials statically. See Plugins::RequestSigner for more details.

  • :convert_params (Boolean) — default: true

    When true, an attempt is made to coerce request parameters into the required types. See Plugins::ParamConverter for more details.

  • :credentials (required, Credentials)

    Your AWS credentials. The following locations will be searched in order for credentials:

    • :access_key_id, :secret_access_key, and :session_token options
    • ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']
    • HOME/.aws/credentials shared credentials file
    • EC2 instance profile credentials See Plugins::RequestSigner for more details.
  • :endpoint (String)

    A default endpoint is constructed from the :region. See Plugins::RegionalEndpoint for more details.

  • :http_continue_timeout (Float) — default: 1

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_idle_timeout (Integer) — default: 5

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_open_timeout (Integer) — default: 15

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_proxy (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_read_timeout (Integer) — default: 60

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :http_wire_trace (Boolean) — default: false

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :log_level (Symbol) — default: :info

    The log level to send messages to the logger at. See Plugins::Logging for more details.

  • :log_formatter (Logging::LogFormatter)

    The log formatter. Defaults to Seahorse::Client::Logging::Formatter.default. See Plugins::Logging for more details.

  • :logger (Logger) — default: nil

    The Logger instance to send log messages to. If this option is not set, logging will be disabled. See Plugins::Logging for more details.

  • :profile (String)

    Used when loading credentials from the shared credentials file at HOME/.aws/credentials. When not specified, 'default' is used. See Plugins::RequestSigner for more details.

  • :raise_response_errors (Boolean) — default: true

    When true, response errors are raised. See Seahorse::Client::Plugins::RaiseResponseErrors for more details.

  • :region (required, String)

    The AWS region to connect to. The region is used to construct the client endpoint. Defaults to ENV['AWS_REGION']. Also checks AMAZON_REGION and AWS_DEFAULT_REGION. See Plugins::RegionalEndpoint for more details.

  • :retry_limit (Integer) — default: 3

    The maximum number of times to retry failed requests. Only ~ 500 level server errors and certain ~ 400 level client errors are retried. Generally, these are throttling errors, data checksum errors, networking errors, timeout errors and auth errors from expired credentials. See Plugins::RetryErrors for more details.

  • :secret_access_key (String)

    Used to set credentials statically. See Plugins::RequestSigner for more details.

  • :session_token (String)

    Used to set credentials statically. See Plugins::RequestSigner for more details.

  • :ssl_ca_bundle (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :ssl_ca_directory (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :ssl_ca_store (String)

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :ssl_verify_peer (Boolean) — default: true

    See Seahorse::Client::Plugins::NetHttp for more details.

  • :stub_responses (Boolean) — default: false

    Causes the client to return stubbed responses. By default fake responses are generated and returned. You can specify the response data to return or errors to raise by calling ClientStubs#stub_responses. See ClientStubs for more information.

    Please note When response stubbing is enabled, no HTTP requests are made, and retries are disabled. See Plugins::StubResponses for more details.

  • :validate_params (Boolean) — default: true

    When true, request parameters are validated before sending the request. See Plugins::ParamValidator for more details.

Instance Method Details

#batch_get_traces(options = {}) ⇒ Types::BatchGetTracesResult

Retrieves a list of traces specified by ID. Each trace is a collection of segment documents that originates from a single request. Use GetTraceSummaries to get a list of trace IDs.

Examples:

Request syntax with placeholder values


resp = client.batch_get_traces({
  trace_ids: ["TraceId"], # required
  next_token: "String",
})

Response structure


resp.traces #=> Array
resp.traces[0].id #=> String
resp.traces[0].duration #=> Float
resp.traces[0].segments #=> Array
resp.traces[0].segments[0].id #=> String
resp.traces[0].segments[0].document #=> String
resp.unprocessed_trace_ids #=> Array
resp.unprocessed_trace_ids[0] #=> String
resp.next_token #=> String

Options Hash (options):

  • :trace_ids (required, Array<String>)

    Specify the trace IDs of requests for which to retrieve segments.

  • :next_token (String)

    Pagination token. Not used.

Returns:

See Also:

#get_service_graph(options = {}) ⇒ Types::GetServiceGraphResult

Retrieves a document that describes services that process incoming requests, and downstream services that they call as a result. Root services process incoming requests and make calls to downstream services. Root services are applications that use the AWS X-Ray SDK. Downstream services can be other applications, AWS resources, HTTP web APIs, or SQL databases.

Examples:

Request syntax with placeholder values


resp = client.get_service_graph({
  start_time: Time.now, # required
  end_time: Time.now, # required
  next_token: "String",
})

Response structure


resp.start_time #=> Time
resp.end_time #=> Time
resp.services #=> Array
resp.services[0].reference_id #=> Integer
resp.services[0].name #=> String
resp.services[0].names #=> Array
resp.services[0].names[0] #=> String
resp.services[0].root #=> true/false
resp.services[0]. #=> String
resp.services[0].type #=> String
resp.services[0].state #=> String
resp.services[0].start_time #=> Time
resp.services[0].end_time #=> Time
resp.services[0].edges #=> Array
resp.services[0].edges[0].reference_id #=> Integer
resp.services[0].edges[0].start_time #=> Time
resp.services[0].edges[0].end_time #=> Time
resp.services[0].edges[0].summary_statistics.ok_count #=> Integer
resp.services[0].edges[0].summary_statistics.error_statistics.throttle_count #=> Integer
resp.services[0].edges[0].summary_statistics.error_statistics.other_count #=> Integer
resp.services[0].edges[0].summary_statistics.error_statistics.total_count #=> Integer
resp.services[0].edges[0].summary_statistics.fault_statistics.other_count #=> Integer
resp.services[0].edges[0].summary_statistics.fault_statistics.total_count #=> Integer
resp.services[0].edges[0].summary_statistics.total_count #=> Integer
resp.services[0].edges[0].summary_statistics.total_response_time #=> Float
resp.services[0].edges[0].response_time_histogram #=> Array
resp.services[0].edges[0].response_time_histogram[0].value #=> Float
resp.services[0].edges[0].response_time_histogram[0].count #=> Integer
resp.services[0].edges[0].aliases #=> Array
resp.services[0].edges[0].aliases[0].name #=> String
resp.services[0].edges[0].aliases[0].names #=> Array
resp.services[0].edges[0].aliases[0].names[0] #=> String
resp.services[0].edges[0].aliases[0].type #=> String
resp.services[0].summary_statistics.ok_count #=> Integer
resp.services[0].summary_statistics.error_statistics.throttle_count #=> Integer
resp.services[0].summary_statistics.error_statistics.other_count #=> Integer
resp.services[0].summary_statistics.error_statistics.total_count #=> Integer
resp.services[0].summary_statistics.fault_statistics.other_count #=> Integer
resp.services[0].summary_statistics.fault_statistics.total_count #=> Integer
resp.services[0].summary_statistics.total_count #=> Integer
resp.services[0].summary_statistics.total_response_time #=> Float
resp.services[0].duration_histogram #=> Array
resp.services[0].duration_histogram[0].value #=> Float
resp.services[0].duration_histogram[0].count #=> Integer
resp.services[0].response_time_histogram #=> Array
resp.services[0].response_time_histogram[0].value #=> Float
resp.services[0].response_time_histogram[0].count #=> Integer
resp.next_token #=> String

Options Hash (options):

  • :start_time (required, Time)

    The start of the time frame for which to generate a graph.

  • :end_time (required, Time)

    The end of the time frame for which to generate a graph.

  • :next_token (String)

    Pagination token. Not used.

Returns:

See Also:

#get_trace_graph(options = {}) ⇒ Types::GetTraceGraphResult

Retrieves a service graph for one or more specific trace IDs.

Examples:

Request syntax with placeholder values


resp = client.get_trace_graph({
  trace_ids: ["TraceId"], # required
  next_token: "String",
})

Response structure


resp.services #=> Array
resp.services[0].reference_id #=> Integer
resp.services[0].name #=> String
resp.services[0].names #=> Array
resp.services[0].names[0] #=> String
resp.services[0].root #=> true/false
resp.services[0]. #=> String
resp.services[0].type #=> String
resp.services[0].state #=> String
resp.services[0].start_time #=> Time
resp.services[0].end_time #=> Time
resp.services[0].edges #=> Array
resp.services[0].edges[0].reference_id #=> Integer
resp.services[0].edges[0].start_time #=> Time
resp.services[0].edges[0].end_time #=> Time
resp.services[0].edges[0].summary_statistics.ok_count #=> Integer
resp.services[0].edges[0].summary_statistics.error_statistics.throttle_count #=> Integer
resp.services[0].edges[0].summary_statistics.error_statistics.other_count #=> Integer
resp.services[0].edges[0].summary_statistics.error_statistics.total_count #=> Integer
resp.services[0].edges[0].summary_statistics.fault_statistics.other_count #=> Integer
resp.services[0].edges[0].summary_statistics.fault_statistics.total_count #=> Integer
resp.services[0].edges[0].summary_statistics.total_count #=> Integer
resp.services[0].edges[0].summary_statistics.total_response_time #=> Float
resp.services[0].edges[0].response_time_histogram #=> Array
resp.services[0].edges[0].response_time_histogram[0].value #=> Float
resp.services[0].edges[0].response_time_histogram[0].count #=> Integer
resp.services[0].edges[0].aliases #=> Array
resp.services[0].edges[0].aliases[0].name #=> String
resp.services[0].edges[0].aliases[0].names #=> Array
resp.services[0].edges[0].aliases[0].names[0] #=> String
resp.services[0].edges[0].aliases[0].type #=> String
resp.services[0].summary_statistics.ok_count #=> Integer
resp.services[0].summary_statistics.error_statistics.throttle_count #=> Integer
resp.services[0].summary_statistics.error_statistics.other_count #=> Integer
resp.services[0].summary_statistics.error_statistics.total_count #=> Integer
resp.services[0].summary_statistics.fault_statistics.other_count #=> Integer
resp.services[0].summary_statistics.fault_statistics.total_count #=> Integer
resp.services[0].summary_statistics.total_count #=> Integer
resp.services[0].summary_statistics.total_response_time #=> Float
resp.services[0].duration_histogram #=> Array
resp.services[0].duration_histogram[0].value #=> Float
resp.services[0].duration_histogram[0].count #=> Integer
resp.services[0].response_time_histogram #=> Array
resp.services[0].response_time_histogram[0].value #=> Float
resp.services[0].response_time_histogram[0].count #=> Integer
resp.next_token #=> String

Options Hash (options):

  • :trace_ids (required, Array<String>)

    Trace IDs of requests for which to generate a service graph.

  • :next_token (String)

    Pagination token. Not used.

Returns:

See Also:

#get_trace_summaries(options = {}) ⇒ Types::GetTraceSummariesResult

Retrieves IDs and metadata for traces available for a specified time frame using an optional filter. To get the full traces, pass the trace IDs to BatchGetTraces.

A filter expression can target traced requests that hit specific service nodes or edges, have errors, or come from a known user. For example, the following filter expression targets traces that pass through api.example.com:

service("api.example.com")

This filter expression finds traces that have an annotation named account with the value 12345:

annotation.account = "12345"

For a full list of indexed fields and keywords that you can use in filter expressions, see Using Filter Expressions in the AWS X-Ray Developer Guide.

Examples:

Request syntax with placeholder values


resp = client.get_trace_summaries({
  start_time: Time.now, # required
  end_time: Time.now, # required
  sampling: false,
  filter_expression: "FilterExpression",
  next_token: "String",
})

Response structure


resp.trace_summaries #=> Array
resp.trace_summaries[0].id #=> String
resp.trace_summaries[0].duration #=> Float
resp.trace_summaries[0].response_time #=> Float
resp.trace_summaries[0].has_fault #=> true/false
resp.trace_summaries[0].has_error #=> true/false
resp.trace_summaries[0].has_throttle #=> true/false
resp.trace_summaries[0].is_partial #=> true/false
resp.trace_summaries[0].http.http_url #=> String
resp.trace_summaries[0].http.http_status #=> Integer
resp.trace_summaries[0].http.http_method #=> String
resp.trace_summaries[0].http.user_agent #=> String
resp.trace_summaries[0].http.client_ip #=> String
resp.trace_summaries[0].annotations #=> Hash
resp.trace_summaries[0].annotations["AnnotationKey"] #=> Array
resp.trace_summaries[0].annotations["AnnotationKey"][0].annotation_value.number_value #=> Float
resp.trace_summaries[0].annotations["AnnotationKey"][0].annotation_value.boolean_value #=> true/false
resp.trace_summaries[0].annotations["AnnotationKey"][0].annotation_value.string_value #=> String
resp.trace_summaries[0].annotations["AnnotationKey"][0].service_ids #=> Array
resp.trace_summaries[0].annotations["AnnotationKey"][0].service_ids[0].name #=> String
resp.trace_summaries[0].annotations["AnnotationKey"][0].service_ids[0].names #=> Array
resp.trace_summaries[0].annotations["AnnotationKey"][0].service_ids[0].names[0] #=> String
resp.trace_summaries[0].annotations["AnnotationKey"][0].service_ids[0]. #=> String
resp.trace_summaries[0].annotations["AnnotationKey"][0].service_ids[0].type #=> String
resp.trace_summaries[0].users #=> Array
resp.trace_summaries[0].users[0].user_name #=> String
resp.trace_summaries[0].users[0].service_ids #=> Array
resp.trace_summaries[0].users[0].service_ids[0].name #=> String
resp.trace_summaries[0].users[0].service_ids[0].names #=> Array
resp.trace_summaries[0].users[0].service_ids[0].names[0] #=> String
resp.trace_summaries[0].users[0].service_ids[0]. #=> String
resp.trace_summaries[0].users[0].service_ids[0].type #=> String
resp.trace_summaries[0].service_ids #=> Array
resp.trace_summaries[0].service_ids[0].name #=> String
resp.trace_summaries[0].service_ids[0].names #=> Array
resp.trace_summaries[0].service_ids[0].names[0] #=> String
resp.trace_summaries[0].service_ids[0]. #=> String
resp.trace_summaries[0].service_ids[0].type #=> String
resp.approximate_time #=> Time
resp.traces_processed_count #=> Integer
resp.next_token #=> String

Options Hash (options):

  • :start_time (required, Time)

    The start of the time frame for which to retrieve traces.

  • :end_time (required, Time)

    The end of the time frame for which to retrieve traces.

  • :sampling (Boolean)

    Set to true to get summaries for only a subset of available traces.

  • :filter_expression (String)

    Specify a filter expression to retrieve trace summaries for services or requests that meet certain requirements.

  • :next_token (String)

    Specify the pagination token returned by a previous request to retrieve the next page of results.

Returns:

See Also:

#put_telemetry_records(options = {}) ⇒ Struct

Used by the AWS X-Ray daemon to upload telemetry.

Examples:

Request syntax with placeholder values


resp = client.put_telemetry_records({
  telemetry_records: [ # required
    {
      timestamp: Time.now, # required
      segments_received_count: 1,
      segments_sent_count: 1,
      segments_spillover_count: 1,
      segments_rejected_count: 1,
      backend_connection_errors: {
        timeout_count: 1,
        connection_refused_count: 1,
        http_code_4_xx_count: 1,
        http_code_5_xx_count: 1,
        unknown_host_count: 1,
        other_count: 1,
      },
    },
  ],
  ec2_instance_id: "EC2InstanceId",
  hostname: "Hostname",
  resource_arn: "ResourceARN",
})

Options Hash (options):

  • :telemetry_records (required, Array<Types::TelemetryRecord>)
  • :ec2_instance_id (String)
  • :hostname (String)
  • :resource_arn (String)

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#put_trace_segments(options = {}) ⇒ Types::PutTraceSegmentsResult

Uploads segment documents to AWS X-Ray. The X-Ray SDK generates segment documents and sends them to the X-Ray daemon, which uploads them in batches. A segment document can be a completed segment, an in-progress segment, or an array of subsegments.

Segments must include the following fields. For the full segment document schema, see AWS X-Ray Segment Documents in the AWS X-Ray Developer Guide.

Required Segment Document Fields

  • name - The name of the service that handled the request.

  • id - A 64-bit identifier for the segment, unique among segments in the same trace, in 16 hexadecimal digits.

  • trace_id - A unique identifier that connects all segments and subsegments originating from a single client request.

  • start_time - Time the segment or subsegment was created, in floating point seconds in epoch time, accurate to milliseconds. For example, 1480615200.010 or 1.480615200010E9.

  • end_time - Time the segment or subsegment was closed. For example, 1480615200.090 or 1.480615200090E9. Specify either an end_time or in_progress.

  • in_progress - Set to true instead of specifying an end_time to record that a segment has been started, but is not complete. Send an in progress segment when your application receives a request that will take a long time to serve, to trace the fact that the request was received. When the response is sent, send the complete segment to overwrite the in-progress segment.

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

Trace ID Format

  • 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 time is 1480615200 seconds, or 58406520 in hexadecimal.

  • A 96-bit identifier for the trace, globally unique, in 24 hexadecimal digits.

Examples:

Request syntax with placeholder values


resp = client.put_trace_segments({
  trace_segment_documents: ["TraceSegmentDocument"], # required
})

Response structure


resp.unprocessed_trace_segments #=> Array
resp.unprocessed_trace_segments[0].id #=> String
resp.unprocessed_trace_segments[0].error_code #=> String
resp.unprocessed_trace_segments[0].message #=> String

Options Hash (options):

  • :trace_segment_documents (required, Array<String>)

    A string containing a JSON document defining one or more segments or subsegments.

Returns:

See Also:

#wait_until(waiter_name, params = {}) {|waiter| ... } ⇒ Boolean

Waiters polls an API operation until a resource enters a desired state.

Basic Usage

Waiters will poll until they are succesful, they fail by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop, sleeping between attempts client.waiter_until(waiter_name, params)

Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. You configure waiters by passing a block to #wait_until:

# poll for ~25 seconds
client.wait_until(...) do |w|
  w.max_attempts = 5
  w.delay = 5
end

Callbacks

You can be notified before each polling attempt and before each delay. If you throw :success or :failure from these callbacks, it will terminate the waiter.

started_at = Time.now
client.wait_until(...) do |w|

  # disable max attempts
  w.max_attempts = nil

  # poll for 1 hour, instead of a number of attempts
  w.before_wait do |attempts, response|
    throw :failure if Time.now - started_at > 3600
  end

end

Handling Errors

When a waiter is successful, it returns true. When a waiter fails, it raises an error. All errors raised extend from Waiters::Errors::WaiterFailed.

begin
  client.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

Parameters:

  • waiter_name (Symbol)

    The name of the waiter. See #waiter_names for a full list of supported waiters.

  • params (Hash) (defaults to: {})

    Additional request parameters. See the #waiter_names for a list of supported waiters and what request they call. The called request determines the list of accepted parameters.

Yield Parameters:

Returns:

  • (Boolean)

    Returns true if the waiter was successful.

Raises:

  • (Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

  • (Errors::TooManyAttemptsError)

    Raised when the configured maximum number of attempts have been made, and the waiter is not yet successful.

  • (Errors::UnexpectedError)

    Raised when an error is encounted while polling for a resource that is not expected.

  • (Errors::NoSuchWaiterError)

    Raised when you request to wait for an unknown state.

#waiter_namesArray<Symbol>

Returns the list of supported waiters. The following table lists the supported waiters and the client method they call:

Waiter NameClient MethodDefault Delay:Default Max Attempts:

Returns:

  • (Array<Symbol>)

    the list of supported waiters.