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).
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.
Parameters
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).
Returns
(TraceSpan) — The created span.
Example
require"google/cloud/trace"trace_record=Google::Cloud::Trace::TraceRecord.new"my-project"trace_record.in_span"root_span"do|span|# Do stuff...end
Create an empty Trace object. If a trace context is provided, it is
used to locate this trace within that context.
Parameters
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Trace API - Class Google::Cloud::Trace::TraceRecord (v0.45.0)\n\nVersion latestkeyboard_arrow_down\n\n- [0.45.0 (latest)](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace-TraceRecord)\n- [0.44.1](/ruby/docs/reference/google-cloud-trace/0.44.1/Google-Cloud-Trace-TraceRecord)\n- [0.43.0](/ruby/docs/reference/google-cloud-trace/0.43.0/Google-Cloud-Trace-TraceRecord)\n- [0.42.2](/ruby/docs/reference/google-cloud-trace/0.42.2/Google-Cloud-Trace-TraceRecord)\n- [0.41.4](/ruby/docs/reference/google-cloud-trace/0.41.4/Google-Cloud-Trace-TraceRecord) \nReference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::TraceRecord.\n\nTrace represents an entire trace record.\n\n\n\u003cbr /\u003e\n\nA trace has an ID and contains a forest of spans. The trace object\nmethods may be used to walk or manipulate the set of spans. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/trace\"\n\nenv = {}\ntrace_context = Stackdriver::Core::TraceContext.parse_rack_env env\n\ntrace = Google::Cloud::Trace::TraceRecord.new \"my-project\",\n trace_context\nspan = trace.create_span \"root_span\"\nsubspan = span.create_span \"subspan\"\n\ntrace_proto = trace.to_grpc\n```\n\nMethods\n-------\n\n### .from_grpc\n\n def self.from_grpc(trace_proto) -\u003e Trace, nil\n\nCreate a new Trace object from a trace protobuf. \n**Parameter**\n\n- **trace_proto** (Google::Cloud::Trace::V1::Trace) --- The trace protobuf from the V1 gRPC Trace API. \n**Returns**\n\n- ([Trace](./Google-Cloud-Trace), nil) --- A corresponding Trace object, or `nil` if the proto does not represent an existing trace object.\n\n### #==\n\n def ==(other) -\u003e Boolean\n\n**Alias Of** : [#eql?](./Google-Cloud-Trace-TraceRecord#Google__Cloud__Trace__TraceRecord_eql?_instance_) \nStandard value equality check for this object. \n**Parameter**\n\n- **other** (Object) --- Object to compare with \n**Returns**\n\n- (Boolean)\n\n### #all_spans\n\n def all_spans() -\u003e Array{TraceSpan}\n\nReturns an array of all spans in this trace, not in any particular\norder \n**Returns**\n\n- (Array{TraceSpan})\n\n### #create_span\n\n def create_span(name, span_id: nil, parent_span_id: 0, kind: SpanKind::UNSPECIFIED, start_time: nil, end_time: nil, labels: {}) -\u003e TraceSpan\n\nCreates a new span in this trace. \n**Parameters**\n\n- **name** (String) --- The name of the span.\n- **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).\n- **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).\n- **kind** ([SpanKind](./Google-Cloud-Trace-SpanKind)) *(defaults to: SpanKind::UNSPECIFIED)* --- The kind of span. Optional.\n- **start_time** (Time) *(defaults to: nil)* --- The starting timestamp, or nil if not yet specified. Optional (defaults to nil).\n- **end_time** (Time) *(defaults to: nil)* --- The ending timestamp, or nil if not yet specified. Optional (defaults to nil).\n- **labels** (Hash{String=\\\u003eString}) *(defaults to: {})* --- The span properties. Optional (defaults to empty). \n**Returns**\n\n- (TraceSpan) --- The created span.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_record = Google::Cloud::Trace::TraceRecord.new \"my-project\"\nspan = trace_record.create_span \"root_span\"\n```\n\n### #eql?\n\n def eql?(other) -\u003e Boolean\n\n**Aliases**\n\n- [#==](./Google-Cloud-Trace-TraceRecord#Google__Cloud__Trace__TraceRecord_==_instance_) \nStandard value equality check for this object. \n**Parameter**\n\n- **other** (Object) --- Object to compare with \n**Returns**\n\n- (Boolean)\n\n### #in_span\n\n def in_span(name, kind: SpanKind::UNSPECIFIED, labels: {}) -\u003e TraceSpan\n\nCreates a root span around the given block. Automatically populates\nthe start and end timestamps. The span (with start time but not end\ntime populated) is yielded to the block. \n**Parameters**\n\n- **name** (String) --- The name of the span.\n- **kind** ([SpanKind](./Google-Cloud-Trace-SpanKind)) *(defaults to: SpanKind::UNSPECIFIED)* --- The kind of span. Optional.\n- **labels** (Hash{String=\\\u003eString}) *(defaults to: {})* --- The span properties. Optional (defaults to empty). \n**Returns**\n\n- (TraceSpan) --- The created span.\n**Example** \n\n```ruby\nrequire \"google/cloud/trace\"\n\ntrace_record = Google::Cloud::Trace::TraceRecord.new \"my-project\"\ntrace_record.in_span \"root_span\" do |span|\n # Do stuff...\nend\n```\n\n### #initialize\n\n def initialize(project_id, trace_context = nil, span_id_generator: nil) -\u003e TraceRecord\n\nCreate an empty Trace object. If a trace context is provided, it is\nused to locate this trace within that context. \n**Parameters**\n\n- **project_id** (String) --- The ID of the project containing this trace.\n- **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. \n**Returns**\n\n- ([TraceRecord](./Google-Cloud-Trace-TraceRecord)) --- a new instance of TraceRecord\n\n### #project\n\n def project() -\u003e String\n\n**Alias Of** : [#project_id](./Google-Cloud-Trace-TraceRecord#Google__Cloud__Trace__TraceRecord_project_id_instance_) \nThe project ID for this trace. \n**Returns**\n\n- (String)\n\n### #project_id\n\n def project_id() -\u003e String\n\n**Aliases**\n\n- [#project](./Google-Cloud-Trace-TraceRecord#Google__Cloud__Trace__TraceRecord_project_instance_) \nThe project ID for this trace. \n**Returns**\n\n- (String)\n\n### #root_spans\n\n def root_spans() -\u003e Array{TraceSpan}\n\nReturns an array of all root spans in this trace, not in any\nparticular order \n**Returns**\n\n- (Array{TraceSpan})\n\n### #to_grpc\n\n def to_grpc() -\u003e Google::Cloud::Trace::V1::Trace\n\nConvert this Trace object to an equivalent Trace protobuf suitable\nfor the V1 gRPC Trace API. \n**Returns**\n\n- (Google::Cloud::Trace::V1::Trace) --- The generated protobuf.\n\n### #trace_context\n\n def trace_context() -\u003e Stackdriver::Core::TraceContext\n\nThe context for this trace. \n**Returns**\n\n- (Stackdriver::Core::TraceContext)\n\n### #trace_id\n\n def trace_id() -\u003e String\n\nThe ID string for the trace. \n**Returns**\n\n- (String)"]]