# Stackdriver Trace V2 Client - Class Span (2.0.0)

2.0.0 (latest) 2.0.0-RC1 1.9.5 1.8.10 1.7.0 1.6.5 1.5.3 1.4.11 Reference documentation and code samples for the Stackdriver Trace V2 Client class Span.

A span represents a single operation within a trace. Spans can be
nested to form a trace tree. Often, a trace contains a root span
that describes the end-to-end latency, and one or more subspans for
its sub-operations.

A trace can also contain multiple root spans, or none at all.
Spans do not need to be contiguous. There might be
gaps or overlaps between spans in a trace.

Generated from protobuf message `google.devtools.cloudtrace.v2.Span`

## Namespace

Google \\ Cloud \\ Trace \\ V2

## Methods

### __construct

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `data` | `array` Optional. Data for populating the Message object. |
| `↳ name` | `string` Required. The resource name of the span in the following format: \* \* `projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/[SPAN_ID]` `[TRACE_ID]` is a unique identifier for a trace within a project; it is a 32-character hexadecimal encoding of a 16-byte array. It should not be zero. `[SPAN_ID]` is a unique identifier for a span within a trace; it is a 16-character hexadecimal encoding of an 8-byte array. It should not be zero. . |
| `↳ span_id` | `string` Required. The `[SPAN_ID]` portion of the span's resource name. |
| `↳ parent_span_id` | `string` The `[SPAN_ID]` of this span's parent span. If this is a root span, then this field must be empty. |
| `↳ display_name` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.TruncatableString` Required. A description of the span's operation (up to 128 bytes). Cloud Trace displays the description in the Cloud console. For example, the display name can be a qualified method name or a file name and a line number where the operation is called. A best practice is to use the same display name within an application and at the same call point. This makes it easier to correlate spans in different traces. |
| `↳ start_time` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Timestamp` Required. The start time of the span. On the client side, this is the time kept by the local machine where the span execution starts. On the server side, this is the time when the server's application handler starts running. |
| `↳ end_time` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Timestamp` Required. The end time of the span. On the client side, this is the time kept by the local machine where the span execution ends. On the server side, this is the time when the server application handler stops running. |
| `↳ attributes` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.Attributes` A set of attributes on the span. You can have up to 32 attributes per span. |
| `↳ stack_trace` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.StackTrace` Stack trace captured at the start of the span. |
| `↳ time_events` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.TimeEvents` A set of time events. You can have up to 32 annotations and 128 message events per span. |
| `↳ links` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.Links` Links associated with the span. You can have up to 128 links per Span. |
| `↳ status` | `https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Status.html` Optional. The final status for this span. |
| `↳ same_process_as_parent_span` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/BoolValue` Optional. Set this parameter to indicate whether this span is in the same process as its parent. If you do not set this parameter, Trace is unable to take advantage of this helpful information. |
| `↳ child_span_count` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Int32Value` Optional. The number of child spans that were generated while this span was active. If set, allows implementation to detect missing child spans. |
| `↳ span_kind` | `int` Optional. Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `CLIENT` (caller) and `SERVER` (callee) to identify an RPC call. |

### getName

Required. The resource name of the span in the following format:

- `projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/[SPAN_ID]` `[TRACE_ID]` is a unique identifier for a trace within a project; it is a 32-character hexadecimal encoding of a 16-byte array. It should not be zero.

`[SPAN_ID]` is a unique identifier for a span within a trace; it
is a 16-character hexadecimal encoding of an 8-byte array. It should not
be zero.
.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setName

Required. The resource name of the span in the following format:

- `projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/[SPAN_ID]` `[TRACE_ID]` is a unique identifier for a trace within a project; it is a 32-character hexadecimal encoding of a 16-byte array. It should not be zero.

`[SPAN_ID]` is a unique identifier for a span within a trace; it
is a 16-character hexadecimal encoding of an 8-byte array. It should not
be zero.
.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getSpanId

Required. The `[SPAN_ID]` portion of the span's resource name.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setSpanId

Required. The `[SPAN_ID]` portion of the span's resource name.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getParentSpanId

The `[SPAN_ID]` of this span's parent span. If this is a root span,
then this field must be empty.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setParentSpanId

The `[SPAN_ID]` of this span's parent span. If this is a root span,
then this field must be empty.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getDisplayName

Required. A description of the span's operation (up to 128 bytes).

Cloud Trace displays the description in the
Cloud console.
For example, the display name can be a qualified method name or a file name
and a line number where the operation is called. A best practice is to use
the same display name within an application and at the same call point.
This makes it easier to correlate spans in different traces.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.TruncatableString|null` |   |

### hasDisplayName

### clearDisplayName

### setDisplayName

Required. A description of the span's operation (up to 128 bytes).

Cloud Trace displays the description in the
Cloud console.
For example, the display name can be a qualified method name or a file name
and a line number where the operation is called. A best practice is to use
the same display name within an application and at the same call point.
This makes it easier to correlate spans in different traces.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.TruncatableString` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getStartTime

Required. The start time of the span. On the client side, this is the time
kept by the local machine where the span execution starts. On the server
side, this is the time when the server's application handler starts
running.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Timestamp|null` |   |

### hasStartTime

### clearStartTime

### setStartTime

Required. The start time of the span. On the client side, this is the time
kept by the local machine where the span execution starts. On the server
side, this is the time when the server's application handler starts
running.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Timestamp` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getEndTime

Required. The end time of the span. On the client side, this is the time
kept by the local machine where the span execution ends. On the server
side, this is the time when the server application handler stops running.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Timestamp|null` |   |

### hasEndTime

### clearEndTime

### setEndTime

Required. The end time of the span. On the client side, this is the time
kept by the local machine where the span execution ends. On the server
side, this is the time when the server application handler stops running.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Timestamp` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getAttributes

A set of attributes on the span. You can have up to 32 attributes per
span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.Attributes|null` |   |

### hasAttributes

### clearAttributes

### setAttributes

A set of attributes on the span. You can have up to 32 attributes per
span.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.Attributes` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getStackTrace

Stack trace captured at the start of the span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.StackTrace|null` |   |

### hasStackTrace

### clearStackTrace

### setStackTrace

Stack trace captured at the start of the span.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.StackTrace` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getTimeEvents

A set of time events. You can have up to 32 annotations and 128 message
events per span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.TimeEvents|null` |   |

### hasTimeEvents

### clearTimeEvents

### setTimeEvents

A set of time events. You can have up to 32 annotations and 128 message
events per span.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.TimeEvents` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getLinks

Links associated with the span. You can have up to 128 links per Span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.Links|null` |   |

### hasLinks

### clearLinks

### setLinks

Links associated with the span. You can have up to 128 links per Span.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.Links` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getStatus

Optional. The final status for this span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Status.html|null` |   |

### hasStatus

### clearStatus

### setStatus

Optional. The final status for this span.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/common-protos/latest/Rpc.Status.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getSameProcessAsParentSpan

Optional. Set this parameter to indicate whether this span is in
the same process as its parent. If you do not set this parameter,
Trace is unable to take advantage of this helpful information.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/BoolValue|null` |   |

### hasSameProcessAsParentSpan

### clearSameProcessAsParentSpan

### getSameProcessAsParentSpanUnwrapped

Returns the unboxed value from `getSameProcessAsParentSpan()`

Optional. Set this parameter to indicate whether this span is in
the same process as its parent. If you do not set this parameter,
Trace is unable to take advantage of this helpful information.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool|null` |   |

### setSameProcessAsParentSpan

Optional. Set this parameter to indicate whether this span is in
the same process as its parent. If you do not set this parameter,
Trace is unable to take advantage of this helpful information.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/BoolValue` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### setSameProcessAsParentSpanUnwrapped

Sets the field by wrapping a primitive type in a Google\\Protobuf\\BoolValue object.

Optional. Set this parameter to indicate whether this span is in
the same process as its parent. If you do not set this parameter,
Trace is unable to take advantage of this helpful information.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `bool|null` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getChildSpanCount

Optional. The number of child spans that were generated while this span
was active. If set, allows implementation to detect missing child spans.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Int32Value|null` |   |

### hasChildSpanCount

### clearChildSpanCount

### getChildSpanCountUnwrapped

Returns the unboxed value from `getChildSpanCount()`

Optional. The number of child spans that were generated while this span
was active. If set, allows implementation to detect missing child spans.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int|null` |   |

### setChildSpanCount

Optional. The number of child spans that were generated while this span
was active. If set, allows implementation to detect missing child spans.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/Int32Value` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### setChildSpanCountUnwrapped

Sets the field by wrapping a primitive type in a Google\\Protobuf\\Int32Value object.

Optional. The number of child spans that were generated while this span
was active. If set, allows implementation to detect missing child spans.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `int|null` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getSpanKind

Optional. Distinguishes between spans generated in a particular context.

For example, two spans with the same name may be distinguished using
`CLIENT` (caller) and `SERVER` (callee) to identify an RPC call.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | Enum of type [SpanKind](https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.SpanKind). |

### setSpanKind

Optional. Distinguishes between spans generated in a particular context.

For example, two spans with the same name may be distinguished using
`CLIENT` (caller) and `SERVER` (callee) to identify an RPC call.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `int` Enum of type [SpanKind](https://docs.cloud.google.com/php/docs/reference/cloud-trace/latest/V2.Span.SpanKind). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |