Reference documentation and code samples for the Cloud Trace V1 API class Google::Cloud::Trace::V1::TraceSpan.
A span represents a single timed event within a trace. Spans can be nested
and form a trace tree. Often, a trace contains a root span that describes the
end-to-end latency of an operation and, optionally, one or more subspans for
its suboperations. Spans do not need to be contiguous. There may be gaps
between spans in a trace.
(::Google::Cloud::Trace::V1::TraceSpan::SpanKind) — Distinguishes between spans generated in a particular context. For example,
two spans with the same name may be distinguished using RPC_CLIENT
and RPC_SERVER to identify queueing latency associated with the span.
value (::Google::Cloud::Trace::V1::TraceSpan::SpanKind) — Distinguishes between spans generated in a particular context. For example,
two spans with the same name may be distinguished using RPC_CLIENT
and RPC_SERVER to identify queueing latency associated with the span.
Returns
(::Google::Cloud::Trace::V1::TraceSpan::SpanKind) — Distinguishes between spans generated in a particular context. For example,
two spans with the same name may be distinguished using RPC_CLIENT
and RPC_SERVER to identify queueing latency associated with the span.
Collection of labels associated with the span. Label keys must be less than
128 bytes. Label values must be less than 16 kilobytes (10MB for
/stacktrace values).
Some predefined label keys exist, or you may create your own. When creating
your own, we recommend the following formats:
/category/product/key for agents of well-known products (e.g.
/db/mongodb/read_size).
short_host/path/key for domain-specific keys (e.g.
foo.com/myproduct/bar)
value (::Google::Protobuf::Map{::String => ::String}) —
Collection of labels associated with the span. Label keys must be less than
128 bytes. Label values must be less than 16 kilobytes (10MB for
/stacktrace values).
Some predefined label keys exist, or you may create your own. When creating
your own, we recommend the following formats:
/category/product/key for agents of well-known products (e.g.
/db/mongodb/read_size).
short_host/path/key for domain-specific keys (e.g.
foo.com/myproduct/bar)
Predefined labels include:
/agent
/component
/error/message
/error/name
/http/client_city
/http/client_country
/http/client_protocol
/http/client_region
/http/host
/http/method
/http/path
/http/redirected_url
/http/request/size
/http/response/size
/http/route
/http/status_code
/http/url
/http/user_agent
/pid
/stacktrace
/tid
Returns
(::Google::Protobuf::Map{::String => ::String}) —
Collection of labels associated with the span. Label keys must be less than
128 bytes. Label values must be less than 16 kilobytes (10MB for
/stacktrace values).
Some predefined label keys exist, or you may create your own. When creating
your own, we recommend the following formats:
/category/product/key for agents of well-known products (e.g.
/db/mongodb/read_size).
short_host/path/key for domain-specific keys (e.g.
foo.com/myproduct/bar)
Predefined labels include:
/agent
/component
/error/message
/error/name
/http/client_city
/http/client_country
/http/client_protocol
/http/client_region
/http/host
/http/method
/http/path
/http/redirected_url
/http/request/size
/http/response/size
/http/route
/http/status_code
/http/url
/http/user_agent
/pid
/stacktrace
/tid
#name
defname()->::String
Returns
(::String) — Name of the span. Must be less than 128 bytes. The span name is sanitized
and displayed in the Stackdriver Trace tool in the
Google Cloud Platform Console.
The name may be a method name or some other per-call site name.
For the same executable and the same call point, a best practice is
to use a consistent name, which makes it easier to correlate
cross-trace spans.
#name=
defname=(value)->::String
Parameter
value (::String) — Name of the span. Must be less than 128 bytes. The span name is sanitized
and displayed in the Stackdriver Trace tool in the
Google Cloud Platform Console.
The name may be a method name or some other per-call site name.
For the same executable and the same call point, a best practice is
to use a consistent name, which makes it easier to correlate
cross-trace spans.
Returns
(::String) — Name of the span. Must be less than 128 bytes. The span name is sanitized
and displayed in the Stackdriver Trace tool in the
Google Cloud Platform Console.
The name may be a method name or some other per-call site name.
For the same executable and the same call point, a best practice is
to use a consistent name, which makes it easier to correlate
cross-trace spans.
#parent_span_id
defparent_span_id()->::Integer
Returns
(::Integer) — Optional. ID of the parent span, if any.
#parent_span_id=
defparent_span_id=(value)->::Integer
Parameter
value (::Integer) — Optional. ID of the parent span, if any.
Returns
(::Integer) — Optional. ID of the parent span, if any.
#span_id
defspan_id()->::Integer
Returns
(::Integer) — Identifier for the span. Must be a 64-bit integer other than 0 and
unique within a trace. For example, 2205310701640571284.
#span_id=
defspan_id=(value)->::Integer
Parameter
value (::Integer) — Identifier for the span. Must be a 64-bit integer other than 0 and
unique within a trace. For example, 2205310701640571284.
Returns
(::Integer) — Identifier for the span. Must be a 64-bit integer other than 0 and
unique within a trace. For example, 2205310701640571284.
[[["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-03 UTC."],[],[],null,["# Cloud Trace V1 API - Class Google::Cloud::Trace::V1::TraceSpan (v1.4.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.4.0 (latest)](/ruby/docs/reference/google-cloud-trace-v1/latest/Google-Cloud-Trace-V1-TraceSpan)\n- [1.3.1](/ruby/docs/reference/google-cloud-trace-v1/1.3.1/Google-Cloud-Trace-V1-TraceSpan)\n- [1.2.0](/ruby/docs/reference/google-cloud-trace-v1/1.2.0/Google-Cloud-Trace-V1-TraceSpan)\n- [1.1.0](/ruby/docs/reference/google-cloud-trace-v1/1.1.0/Google-Cloud-Trace-V1-TraceSpan)\n- [1.0.1](/ruby/docs/reference/google-cloud-trace-v1/1.0.1/Google-Cloud-Trace-V1-TraceSpan)\n- [0.9.0](/ruby/docs/reference/google-cloud-trace-v1/0.9.0/Google-Cloud-Trace-V1-TraceSpan)\n- [0.8.2](/ruby/docs/reference/google-cloud-trace-v1/0.8.2/Google-Cloud-Trace-V1-TraceSpan)\n- [0.7.0](/ruby/docs/reference/google-cloud-trace-v1/0.7.0/Google-Cloud-Trace-V1-TraceSpan)\n- [0.6.1](/ruby/docs/reference/google-cloud-trace-v1/0.6.1/Google-Cloud-Trace-V1-TraceSpan)\n- [0.5.0](/ruby/docs/reference/google-cloud-trace-v1/0.5.0/Google-Cloud-Trace-V1-TraceSpan)\n- [0.4.0](/ruby/docs/reference/google-cloud-trace-v1/0.4.0/Google-Cloud-Trace-V1-TraceSpan)\n- [0.3.5](/ruby/docs/reference/google-cloud-trace-v1/0.3.5/Google-Cloud-Trace-V1-TraceSpan) \nReference documentation and code samples for the Cloud Trace V1 API class Google::Cloud::Trace::V1::TraceSpan.\n\nA span represents a single timed event within a trace. Spans can be nested\nand form a trace tree. Often, a trace contains a root span that describes the\nend-to-end latency of an operation and, optionally, one or more subspans for\nits suboperations. Spans do not need to be contiguous. There may be gaps\nbetween spans in a trace. \n\nInherits\n--------\n\n- Object \n\nExtended By\n-----------\n\n- Google::Protobuf::MessageExts::ClassMethods \n\nIncludes\n--------\n\n- Google::Protobuf::MessageExts\n\nMethods\n-------\n\n### #end_time\n\n def end_time() -\u003e ::Google::Protobuf::Timestamp\n\n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- End time of the span in nanoseconds from the UNIX epoch.\n\n### #end_time=\n\n def end_time=(value) -\u003e ::Google::Protobuf::Timestamp\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- End time of the span in nanoseconds from the UNIX epoch. \n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- End time of the span in nanoseconds from the UNIX epoch.\n\n### #kind\n\n def kind() -\u003e ::Google::Cloud::Trace::V1::TraceSpan::SpanKind\n\n**Returns**\n\n- ([::Google::Cloud::Trace::V1::TraceSpan::SpanKind](./Google-Cloud-Trace-V1-TraceSpan-SpanKind)) --- Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `RPC_CLIENT` and `RPC_SERVER` to identify queueing latency associated with the span.\n\n### #kind=\n\n def kind=(value) -\u003e ::Google::Cloud::Trace::V1::TraceSpan::SpanKind\n\n**Parameter**\n\n- **value** ([::Google::Cloud::Trace::V1::TraceSpan::SpanKind](./Google-Cloud-Trace-V1-TraceSpan-SpanKind)) --- Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `RPC_CLIENT` and `RPC_SERVER` to identify queueing latency associated with the span. \n**Returns**\n\n- ([::Google::Cloud::Trace::V1::TraceSpan::SpanKind](./Google-Cloud-Trace-V1-TraceSpan-SpanKind)) --- Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `RPC_CLIENT` and `RPC_SERVER` to identify queueing latency associated with the span.\n\n### #labels\n\n def labels() -\u003e ::Google::Protobuf::Map{::String =\u003e ::String}\n\n**Returns**\n\n- (::Google::Protobuf::Map{::String =\\\u003e ::String}) --- Collection of labels associated with the span. Label keys must be less than\n 128 bytes. Label values must be less than 16 kilobytes (10MB for\n `/stacktrace` values).\n\n Some predefined label keys exist, or you may create your own. When creating\n your own, we recommend the following formats:\n - `/category/product/key` for agents of well-known products (e.g. `/db/mongodb/read_size`).\n - `short_host/path/key` for domain-specific keys (e.g. `foo.com/myproduct/bar`)\n\n Predefined labels include:\n - `/agent`\n - `/component`\n - `/error/message`\n - `/error/name`\n - `/http/client_city`\n - `/http/client_country`\n - `/http/client_protocol`\n - `/http/client_region`\n - `/http/host`\n - `/http/method`\n - `/http/path`\n - `/http/redirected_url`\n - `/http/request/size`\n - `/http/response/size`\n - `/http/route`\n - `/http/status_code`\n - `/http/url`\n - `/http/user_agent`\n - `/pid`\n - `/stacktrace`\n - `/tid`\n\n### #labels=\n\n def labels=(value) -\u003e ::Google::Protobuf::Map{::String =\u003e ::String}\n\n**Parameter**\n\n- **value** (::Google::Protobuf::Map{::String =\\\u003e ::String}) ---\n\n Collection of labels associated with the span. Label keys must be less than\n 128 bytes. Label values must be less than 16 kilobytes (10MB for\n `/stacktrace` values).\n\n Some predefined label keys exist, or you may create your own. When creating\n your own, we recommend the following formats:\n - `/category/product/key` for agents of well-known products (e.g. `/db/mongodb/read_size`).\n - `short_host/path/key` for domain-specific keys (e.g. `foo.com/myproduct/bar`)\n\n Predefined labels include:\n - `/agent`\n - `/component`\n - `/error/message`\n - `/error/name`\n - `/http/client_city`\n - `/http/client_country`\n - `/http/client_protocol`\n - `/http/client_region`\n - `/http/host`\n - `/http/method`\n - `/http/path`\n - `/http/redirected_url`\n - `/http/request/size`\n - `/http/response/size`\n - `/http/route`\n - `/http/status_code`\n - `/http/url`\n - `/http/user_agent`\n - `/pid`\n - `/stacktrace`\n- `/tid` \n**Returns**\n\n- (::Google::Protobuf::Map{::String =\\\u003e ::String}) --- Collection of labels associated with the span. Label keys must be less than\n 128 bytes. Label values must be less than 16 kilobytes (10MB for\n `/stacktrace` values).\n\n Some predefined label keys exist, or you may create your own. When creating\n your own, we recommend the following formats:\n - `/category/product/key` for agents of well-known products (e.g. `/db/mongodb/read_size`).\n - `short_host/path/key` for domain-specific keys (e.g. `foo.com/myproduct/bar`)\n\n Predefined labels include:\n - `/agent`\n - `/component`\n - `/error/message`\n - `/error/name`\n - `/http/client_city`\n - `/http/client_country`\n - `/http/client_protocol`\n - `/http/client_region`\n - `/http/host`\n - `/http/method`\n - `/http/path`\n - `/http/redirected_url`\n - `/http/request/size`\n - `/http/response/size`\n - `/http/route`\n - `/http/status_code`\n - `/http/url`\n - `/http/user_agent`\n - `/pid`\n - `/stacktrace`\n - `/tid`\n\n### #name\n\n def name() -\u003e ::String\n\n**Returns**\n\n- (::String) --- Name of the span. Must be less than 128 bytes. The span name is sanitized and displayed in the Stackdriver Trace tool in the Google Cloud Platform Console. The name may be a method name or some other per-call site name. For the same executable and the same call point, a best practice is to use a consistent name, which makes it easier to correlate cross-trace spans.\n\n### #name=\n\n def name=(value) -\u003e ::String\n\n**Parameter**\n\n- **value** (::String) --- Name of the span. Must be less than 128 bytes. The span name is sanitized and displayed in the Stackdriver Trace tool in the Google Cloud Platform Console. The name may be a method name or some other per-call site name. For the same executable and the same call point, a best practice is to use a consistent name, which makes it easier to correlate cross-trace spans. \n**Returns**\n\n- (::String) --- Name of the span. Must be less than 128 bytes. The span name is sanitized and displayed in the Stackdriver Trace tool in the Google Cloud Platform Console. The name may be a method name or some other per-call site name. For the same executable and the same call point, a best practice is to use a consistent name, which makes it easier to correlate cross-trace spans.\n\n### #parent_span_id\n\n def parent_span_id() -\u003e ::Integer\n\n**Returns**\n\n- (::Integer) --- Optional. ID of the parent span, if any.\n\n### #parent_span_id=\n\n def parent_span_id=(value) -\u003e ::Integer\n\n**Parameter**\n\n- **value** (::Integer) --- Optional. ID of the parent span, if any. \n**Returns**\n\n- (::Integer) --- Optional. ID of the parent span, if any.\n\n### #span_id\n\n def span_id() -\u003e ::Integer\n\n**Returns**\n\n- (::Integer) --- Identifier for the span. Must be a 64-bit integer other than 0 and unique within a trace. For example, `2205310701640571284`.\n\n### #span_id=\n\n def span_id=(value) -\u003e ::Integer\n\n**Parameter**\n\n- **value** (::Integer) --- Identifier for the span. Must be a 64-bit integer other than 0 and unique within a trace. For example, `2205310701640571284`. \n**Returns**\n\n- (::Integer) --- Identifier for the span. Must be a 64-bit integer other than 0 and unique within a trace. For example, `2205310701640571284`.\n\n### #start_time\n\n def start_time() -\u003e ::Google::Protobuf::Timestamp\n\n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- Start time of the span in nanoseconds from the UNIX epoch.\n\n### #start_time=\n\n def start_time=(value) -\u003e ::Google::Protobuf::Timestamp\n\n**Parameter**\n\n- **value** ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- Start time of the span in nanoseconds from the UNIX epoch. \n**Returns**\n\n- ([::Google::Protobuf::Timestamp](./Google-Protobuf-Timestamp)) --- Start time of the span in nanoseconds from the UNIX epoch."]]