Class: Google::Cloud::Trace::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/trace/project.rb

Overview

Project

Projects are top-level containers in Google Cloud Platform. They store information about billing and authorized users, and they control access to Stackdriver Trace resources. Each project has a friendly name and a unique ID. Projects can be created only in the Google Developers Console.

This class is a client to make API calls for the project's trace data. Create an instance using new or Google::Cloud#trace. You may then use the get_trace method to retrieve a trace by ID, list_traces to query for a set of traces, and patch_traces to update trace data. You may also use new_trace as a convenience constructor to build a TraceRecord object.

Examples:

require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new
traces = trace_client.list_traces Time.now - 3600, Time.now

Instance Method Summary collapse

Instance Method Details

#get_trace(trace_id) ⇒ Google::Cloud::Trace::TraceRecord?

Gets a single trace by its ID.

Examples:

require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new

trace = trace_client.get_trace "1234567890abcdef1234567890abcdef"

Parameters:

  • trace_id (String)

    The ID of the trace to fetch.

Returns:



147
148
149
150
# File 'lib/google/cloud/trace/project.rb', line 147

def get_trace trace_id
  ensure_service!
  service.get_trace trace_id
end

#list_traces(start_time, end_time, filter: nil, order_by: nil, view: nil, page_size: nil, page_token: nil) ⇒ Google::Cloud::Trace::ResultSet

Returns of a list of traces that match the specified conditions. You must provide a time interval. You may optionally provide a filter, an ordering, a view type. Results are paginated, and you may specify a page size. The result will come with a token you can pass back to retrieve the next page.

Examples:

require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new

traces = trace_client.list_traces Time.now - 3600, Time.now
traces.each do |trace|
  puts "Retrieved trace ID: #{trace.trace_id}"
end

Parameters:

  • start_time (Time)

    The start of the time interval (inclusive).

  • end_time (Time)

    The end of the time interval (inclusive).

  • filter (String)

    An optional filter.

  • order_by (String)

    The optional sort order for returned traces. May be trace_id, name, duration, or start. Any sort order may also be reversed by appending desc; for example use start desc to order traces from newest to oldest.

  • view (Symbol)

    The optional type of view. Valid values are :MINIMAL, :ROOTSPAN, and :COMPLETE. Default is :MINIMAL.

  • page_size (Integer)

    The size of each page to return. Optional; if omitted, the service will select a reasonable page size.

  • page_token (String)

    A token indicating the page to return. Each page of results includes proper token for specifying the following page.

Returns:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/google/cloud/trace/project.rb', line 185

def list_traces start_time, end_time,
                filter: nil,
                order_by: nil,
                view: nil,
                page_size: nil,
                page_token: nil
  ensure_service!
  service.list_traces project, start_time, end_time,
                      filter: filter,
                      order_by: order_by,
                      view: view,
                      page_size: page_size,
                      page_token: page_token
end

#new_trace(trace_context: :DEFAULT) ⇒ Google::Cloud::Trace::TraceRecord

Create a new empty trace record for this project. Uses the current thread's TraceContext by default; otherwise you may provide a specific TraceContext.

Examples:

require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new(
  project_id: "my-project",
  credentials: "/path/to/keyfile.json"
)

trace = trace_client.new_trace

Parameters:

  • trace_context (Stackdriver::Core::TraceContext, nil)

    The context within which to locate this trace (i.e. sets the trace ID and the context parent span, if present.) If the context is set explicitly to nil, a new trace with a new trace ID is created. If no context is provided, the current thread's context is used.

Returns:



97
98
99
100
101
102
# File 'lib/google/cloud/trace/project.rb', line 97

def new_trace trace_context: :DEFAULT
  if trace_context == :DEFAULT
    trace_context = Stackdriver::Core::TraceContext.get
  end
  Google::Cloud::Trace::TraceRecord.new project, trace_context
end

#patch_traces(traces) ⇒ Array{Google::Cloud::Trace::TraceRecord}

Sends new traces to Stackdriver Trace or updates existing traces. If the ID of a trace that you send matches that of an existing trace, any fields in the existing trace and its spans are overwritten by the provided values, and any new fields provided are merged with the existing trace data. If the ID does not match, a new trace is created.

Examples:

require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new

trace = trace_client.new_trace
trace.in_span "root_span" do
  # Do stuff...
end

trace_client.patch_traces trace

Parameters:

Returns:



128
129
130
131
# File 'lib/google/cloud/trace/project.rb', line 128

def patch_traces traces
  ensure_service!
  service.patch_traces traces
end

#project_idString Also known as: project

The ID of the current project.

Examples:

require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new(
  project_id: "my-project",
  credentials: "/path/to/keyfile.json"
)

trace_client.project_id #=> "my-project"

Returns:

  • (String)

    the Google Cloud project ID



70
71
72
# File 'lib/google/cloud/trace/project.rb', line 70

def project_id
  service.project
end