Cloud Trace API - Class Google::Cloud::Trace::Project (v0.44.1)

Reference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::Project.

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.

Inherits

  • Object

Example

require "google/cloud/trace"

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

Methods

#get_trace

def get_trace(trace_id) -> Google::Cloud::Trace::TraceRecord, nil

Gets a single trace by its ID.

Parameter
  • trace_id (String) — The ID of the trace to fetch.
Returns
Example
require "google/cloud/trace"

trace_client = Google::Cloud::Trace.new

trace = trace_client.get_trace "1234567890abcdef1234567890abcdef"

#list_traces

def 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.

Parameters
  • start_time (Time) — The start of the time interval (inclusive).
  • end_time (Time) — The end of the time interval (inclusive).
  • filter (String) (defaults to: nil) — An optional filter.
  • order_by (String) (defaults to: nil) — 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) (defaults to: nil) — The optional type of view. Valid values are :MINIMAL, :ROOTSPAN, and :COMPLETE. Default is :MINIMAL.
  • page_size (Integer) (defaults to: nil) — The size of each page to return. Optional; if omitted, the service will select a reasonable page size.
  • page_token (String) (defaults to: nil) — A token indicating the page to return. Each page of results includes proper token for specifying the following page.
Returns
Example
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

#new_trace

def 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.

Parameter
  • trace_context (Stackdriver::Core::TraceContext, nil) (defaults to: :DEFAULT) — 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
Example
require "google/cloud/trace"

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

trace = trace_client.new_trace

#patch_traces

def 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.

Parameter
Returns
  • (Array{Google::Cloud::Trace::TraceRecord}) — The traces written.
Example
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

#project

def project() -> String
Alias Of: #project_id

The ID of the current project.

Returns
  • (String) — the Google Cloud project ID
Example
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"

#project_id

def project_id() -> String
Aliases

The ID of the current project.

Returns
  • (String) — the Google Cloud project ID
Example
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"