Reference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::TraceRecord.
Trace represents an entire trace record.
A trace has an ID and contains a forest of spans. The trace object methods may be used to walk or manipulate the set of spans.
Inherits
- Object
Example
require "google/cloud/trace" env = {} trace_context = Stackdriver::Core::TraceContext.parse_rack_env env trace = Google::Cloud::Trace::TraceRecord.new "my-project", trace_context span = trace.create_span "root_span" subspan = span.create_span "subspan" trace_proto = trace.to_grpc
Methods
.from_grpc
def self.from_grpc(trace_proto) -> Trace, nil
Create a new Trace object from a trace protobuf.
- trace_proto (Google::Cloud::Trace::V1::Trace) — The trace protobuf from the V1 gRPC Trace API.
-
(Trace, nil) — A corresponding Trace object, or
nil
if the proto does not represent an existing trace object.
#==
def ==(other) -> Boolean
Standard value equality check for this object.
- other (Object) — Object to compare with
- (Boolean)
#all_spans
def all_spans() -> Array{TraceSpan}
Returns an array of all spans in this trace, not in any particular order
- (Array{TraceSpan})
#create_span
def create_span(name, span_id: nil, parent_span_id: 0, kind: SpanKind::UNSPECIFIED, start_time: nil, end_time: nil, labels: {}) -> TraceSpan
Creates a new span in this trace.
- name (String) — The name of the span.
- span_id (Integer) (defaults to: nil) — The numeric ID of the span, or nil to generate a new random unique ID. Optional (defaults to nil).
- parent_span_id (Integer) (defaults to: 0) — The span ID of the parent span, or 0 if this should be a new root span within the context. Note that a root span would not necessarily end up with a parent ID of 0 if the trace context specifies a different context span ID. Optional (defaults to 0).
- kind (SpanKind) (defaults to: SpanKind::UNSPECIFIED) — The kind of span. Optional.
- start_time (Time) (defaults to: nil) — The starting timestamp, or nil if not yet specified. Optional (defaults to nil).
- end_time (Time) (defaults to: nil) — The ending timestamp, or nil if not yet specified. Optional (defaults to nil).
- labels (Hash{String=>String}) (defaults to: {}) — The span properties. Optional (defaults to empty).
- (TraceSpan) — The created span.
require "google/cloud/trace" trace_record = Google::Cloud::Trace::TraceRecord.new "my-project" span = trace_record.create_span "root_span"
#eql?
def eql?(other) -> Boolean
Standard value equality check for this object.
- other (Object) — Object to compare with
- (Boolean)
#in_span
def in_span(name, kind: SpanKind::UNSPECIFIED, labels: {}) -> TraceSpan
Creates a root span around the given block. Automatically populates the start and end timestamps. The span (with start time but not end time populated) is yielded to the block.
- name (String) — The name of the span.
- kind (SpanKind) (defaults to: SpanKind::UNSPECIFIED) — The kind of span. Optional.
- labels (Hash{String=>String}) (defaults to: {}) — The span properties. Optional (defaults to empty).
- (TraceSpan) — The created span.
require "google/cloud/trace" trace_record = Google::Cloud::Trace::TraceRecord.new "my-project" trace_record.in_span "root_span" do |span| # Do stuff... end
#initialize
def initialize(project_id, trace_context = nil, span_id_generator: nil) -> TraceRecord
Create an empty Trace object. If a trace context is provided, it is used to locate this trace within that context.
- project_id (String) — The ID of the project containing this trace.
- trace_context (Stackdriver::Core::TraceContext) — The context within which to locate this trace (i.e. sets the trace ID and the context parent span, if present.) If no context is provided, a new trace with a new trace ID is created.
- (TraceRecord) — a new instance of TraceRecord
#project
def project() -> String
The project ID for this trace.
- (String)
#project_id
def project_id() -> String
The project ID for this trace.
- (String)
#root_spans
def root_spans() -> Array{TraceSpan}
Returns an array of all root spans in this trace, not in any particular order
- (Array{TraceSpan})
#to_grpc
def to_grpc() -> Google::Cloud::Trace::V1::Trace
Convert this Trace object to an equivalent Trace protobuf suitable for the V1 gRPC Trace API.
- (Google::Cloud::Trace::V1::Trace) — The generated protobuf.
#trace_context
def trace_context() -> Stackdriver::Core::TraceContext
The context for this trace.
- (Stackdriver::Core::TraceContext)
#trace_id
def trace_id() -> String
The ID string for the trace.
- (String)