# Interface TraceUtil (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 interface TraceUtil

Utility interface to manage OpenTelemetry tracing instrumentation based on the configuration.

## Static Fields

### ATTRIBUTE_SERVICE_PREFIX

    public static final String ATTRIBUTE_SERVICE_PREFIX

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### ENABLE_TRACING_ENV_VAR

    public static final String ENABLE_TRACING_ENV_VAR

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### LIBRARY_NAME

    public static final String LIBRARY_NAME

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_ALLOCATE_IDS

    public static final String SPAN_NAME_ALLOCATE_IDS

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_BEGIN_TRANSACTION

    public static final String SPAN_NAME_BEGIN_TRANSACTION

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_COMMIT

    public static final String SPAN_NAME_COMMIT

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_LOOKUP

    public static final String SPAN_NAME_LOOKUP

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_RESERVE_IDS

    public static final String SPAN_NAME_RESERVE_IDS

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_ROLLBACK

    public static final String SPAN_NAME_ROLLBACK

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_RUN_AGGREGATION_QUERY

    public static final String SPAN_NAME_RUN_AGGREGATION_QUERY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_RUN_QUERY

    public static final String SPAN_NAME_RUN_QUERY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_TRANSACTION_COMMIT

    public static final String SPAN_NAME_TRANSACTION_COMMIT

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_TRANSACTION_LOOKUP

    public static final String SPAN_NAME_TRANSACTION_LOOKUP

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_TRANSACTION_RUN

    public static final String SPAN_NAME_TRANSACTION_RUN

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_TRANSACTION_RUN_AGGREGATION_QUERY

    public static final String SPAN_NAME_TRANSACTION_RUN_AGGREGATION_QUERY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### SPAN_NAME_TRANSACTION_RUN_QUERY

    public static final String SPAN_NAME_TRANSACTION_RUN_QUERY

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

## Static Methods

### getInstance(DatastoreOptions datastoreOptions)

    public static TraceUtil getInstance(DatastoreOptions datastoreOptions)

Creates and returns an instance of the TraceUtil class.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `datastoreOptions` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions` The DatastoreOptions object that is requesting an instance of TraceUtil. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil` | An instance of the TraceUtil class. |

## Methods

### addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder)

    public abstract SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder)

Adds common SpanAttributes to the current span, useful when hand-creating a new Span without
using the TraceUtil.Span interface.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `spanBuilder` | `io.opentelemetry.api.trace.SpanBuilder` |

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

### getChannelConfigurator()

    public abstract ApiFunction<ManagedChannelBuilder,ManagedChannelBuilder> getChannelConfigurator()

Returns a channel configurator for gRPC, or `null` if tracing is disabled.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFunction.html<io.grpc.ManagedChannelBuilder,io.grpc.ManagedChannelBuilder>` |   |

### getCurrentContext()

    public abstract TraceUtil.Context getCurrentContext()

Returns the current Context.

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

### getCurrentSpan()

    public abstract TraceUtil.Span getCurrentSpan()

Returns the current span.

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

### getTracer()

    public abstract Tracer getTracer()

Returns the current OpenTelemetry Tracer when OpenTelemetry SDK is provided.

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

### startSpan(String spanName)

    public abstract TraceUtil.Span startSpan(String spanName)

Starts a new span with the given name, sets it as the current span, and returns it.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `spanName` | `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` |   |

### startSpan(String spanName, TraceUtil.Span parentSpan)

    public abstract TraceUtil.Span startSpan(String spanName, TraceUtil.Span parentSpan)

Starts a new span with the given name and the span represented by the parentSpan as its parent,
sets it as the current span and returns it.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `spanName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `parentSpan` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.telemetry.TraceUtil.Span` |

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