# Interface TraceUtil.Span (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    public static interface TraceUtil.Span

Represents a trace span.

## Methods

### \<T\>endAtFuture(ApiFuture\<T\> futureValue)

    public abstract void <T>endAtFuture(ApiFuture<T> futureValue)

If an operation ends in the future, its relevant span should end *after* the future has been
completed. This method "appends" the span completion code at the completion of the given
future. In order for telemetry info to be recorded, the future returned by this method should
be completed.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `futureValue` | `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html<T>` |

### addEvent(String name)

    public abstract TraceUtil.Span addEvent(String name)

Adds the given event to this span.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Span` |   |

### addEvent(String name, Map\<String,Object\> attributes)

    public abstract TraceUtil.Span addEvent(String name, Map<String,Object> attributes)

Adds the given event with the given attributes to this span.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `name` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `attributes` | `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Span` |   |

### end()

    public abstract void end()

Ends this span.

### end(Throwable error)

    public abstract void end(Throwable error)

Ends this span in an error.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `error` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` |

### getSpan()

    public abstract Span getSpan()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `io.opentelemetry.api.trace.Span` |   |

### makeCurrent()

    public abstract TraceUtil.Scope makeCurrent()

Marks this span as the current span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Scope` |   |

### setAttribute(String key, boolean value)

    public abstract TraceUtil.Span setAttribute(String key, boolean value)

Adds the given attribute to this span.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Span` |   |

### setAttribute(String key, int value)

    public abstract TraceUtil.Span setAttribute(String key, int value)

Adds the given attribute to this span.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `value` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Span` |   |

### setAttribute(String key, String value)

    public abstract TraceUtil.Span setAttribute(String key, String value)

Adds the given attribute to this span.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Span` |   |