Google Cloud Trace v2 API - Class TraceServiceClient (3.6.0)

public abstract class TraceServiceClient

Reference documentation and code samples for the Google Cloud Trace v2 API class TraceServiceClient.

TraceService client wrapper, for convenient use.

Inheritance

object > TraceServiceClient

Derived Types

Namespace

Google.Cloud.Trace.V2

Assembly

Google.Cloud.Trace.V2.dll

Remarks

Service for collecting and viewing traces and spans within a trace.

A trace is a collection of spans corresponding to a single operation or a set of operations in an application.

A span is an individual timed event which forms a node of the trace tree. A single trace can contain spans from multiple services.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the TraceService service, which is a host of "cloudtrace.googleapis.com" and a port of 443.

Property Value
Type Description
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default TraceService scopes.

Property Value
Type Description
IReadOnlyListstring
Remarks

GrpcClient

public virtual TraceService.TraceServiceClient GrpcClient { get; }

The underlying gRPC TraceService client

Property Value
Type Description
TraceServiceTraceServiceClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
Type Description
ServiceMetadata

Methods

BatchWriteSpans(ProjectName, IEnumerable<Span>, CallSettings)

public virtual void BatchWriteSpans(ProjectName name, IEnumerable<Span> spans, CallSettings callSettings = null)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
name ProjectName

Required. The name of the project where the spans belong. The format is projects/[PROJECT_ID].

spans IEnumerableSpan

Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
TraceServiceClient traceServiceClient = TraceServiceClient.Create();
// Initialize request argument(s)
ProjectName name = ProjectName.FromProject("[PROJECT]");
IEnumerable<Span> spans = new Span[] { new Span(), };
// Make the request
traceServiceClient.BatchWriteSpans(name, spans);

BatchWriteSpans(BatchWriteSpansRequest, CallSettings)

public virtual void BatchWriteSpans(BatchWriteSpansRequest request, CallSettings callSettings = null)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
request BatchWriteSpansRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
TraceServiceClient traceServiceClient = TraceServiceClient.Create();
// Initialize request argument(s)
BatchWriteSpansRequest request = new BatchWriteSpansRequest
{
    ProjectName = ProjectName.FromProject("[PROJECT]"),
    Spans = { new Span(), },
};
// Make the request
traceServiceClient.BatchWriteSpans(request);

BatchWriteSpans(string, IEnumerable<Span>, CallSettings)

public virtual void BatchWriteSpans(string name, IEnumerable<Span> spans, CallSettings callSettings = null)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
name string

Required. The name of the project where the spans belong. The format is projects/[PROJECT_ID].

spans IEnumerableSpan

Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
TraceServiceClient traceServiceClient = TraceServiceClient.Create();
// Initialize request argument(s)
string name = "projects/[PROJECT]";
IEnumerable<Span> spans = new Span[] { new Span(), };
// Make the request
traceServiceClient.BatchWriteSpans(name, spans);

BatchWriteSpansAsync(ProjectName, IEnumerable<Span>, CallSettings)

public virtual Task BatchWriteSpansAsync(ProjectName name, IEnumerable<Span> spans, CallSettings callSettings = null)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
name ProjectName

Required. The name of the project where the spans belong. The format is projects/[PROJECT_ID].

spans IEnumerableSpan

Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
Task

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
ProjectName name = ProjectName.FromProject("[PROJECT]");
IEnumerable<Span> spans = new Span[] { new Span(), };
// Make the request
await traceServiceClient.BatchWriteSpansAsync(name, spans);

BatchWriteSpansAsync(ProjectName, IEnumerable<Span>, CancellationToken)

public virtual Task BatchWriteSpansAsync(ProjectName name, IEnumerable<Span> spans, CancellationToken cancellationToken)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
name ProjectName

Required. The name of the project where the spans belong. The format is projects/[PROJECT_ID].

spans IEnumerableSpan

Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
Task

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
ProjectName name = ProjectName.FromProject("[PROJECT]");
IEnumerable<Span> spans = new Span[] { new Span(), };
// Make the request
await traceServiceClient.BatchWriteSpansAsync(name, spans);

BatchWriteSpansAsync(BatchWriteSpansRequest, CallSettings)

public virtual Task BatchWriteSpansAsync(BatchWriteSpansRequest request, CallSettings callSettings = null)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
request BatchWriteSpansRequest

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
Task

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
BatchWriteSpansRequest request = new BatchWriteSpansRequest
{
    ProjectName = ProjectName.FromProject("[PROJECT]"),
    Spans = { new Span(), },
};
// Make the request
await traceServiceClient.BatchWriteSpansAsync(request);

BatchWriteSpansAsync(BatchWriteSpansRequest, CancellationToken)

public virtual Task BatchWriteSpansAsync(BatchWriteSpansRequest request, CancellationToken cancellationToken)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
request BatchWriteSpansRequest

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
Task

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
BatchWriteSpansRequest request = new BatchWriteSpansRequest
{
    ProjectName = ProjectName.FromProject("[PROJECT]"),
    Spans = { new Span(), },
};
// Make the request
await traceServiceClient.BatchWriteSpansAsync(request);

BatchWriteSpansAsync(string, IEnumerable<Span>, CallSettings)

public virtual Task BatchWriteSpansAsync(string name, IEnumerable<Span> spans, CallSettings callSettings = null)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
name string

Required. The name of the project where the spans belong. The format is projects/[PROJECT_ID].

spans IEnumerableSpan

Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
Task

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
string name = "projects/[PROJECT]";
IEnumerable<Span> spans = new Span[] { new Span(), };
// Make the request
await traceServiceClient.BatchWriteSpansAsync(name, spans);

BatchWriteSpansAsync(string, IEnumerable<Span>, CancellationToken)

public virtual Task BatchWriteSpansAsync(string name, IEnumerable<Span> spans, CancellationToken cancellationToken)

Batch writes new spans to new or existing traces. You cannot update existing spans.

Parameters
Name Description
name string

Required. The name of the project where the spans belong. The format is projects/[PROJECT_ID].

spans IEnumerableSpan

Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
Task

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
string name = "projects/[PROJECT]";
IEnumerable<Span> spans = new Span[] { new Span(), };
// Make the request
await traceServiceClient.BatchWriteSpansAsync(name, spans);

Create()

public static TraceServiceClient Create()

Synchronously creates a TraceServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use TraceServiceClientBuilder.

Returns
Type Description
TraceServiceClient

The created TraceServiceClient.

CreateAsync(CancellationToken)

public static Task<TraceServiceClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a TraceServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use TraceServiceClientBuilder.

Parameter
Name Description
cancellationToken CancellationToken

The CancellationToken to use while creating the client.

Returns
Type Description
TaskTraceServiceClient

The task representing the created TraceServiceClient.

CreateSpan(Span, CallSettings)

public virtual Span CreateSpan(Span request, CallSettings callSettings = null)

Creates a new span.

Parameters
Name Description
request Span

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
Span

The RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = TraceServiceClient.Create();
// Initialize request argument(s)
Span request = new Span
{
    SpanName = SpanName.FromProjectTraceSpan("[PROJECT]", "[TRACE]", "[SPAN]"),
    SpanId = "",
    ParentSpanId = "",
    DisplayName = new TruncatableString(),
    StartTime = new Timestamp(),
    EndTime = new Timestamp(),
    Attributes = new Span.Types.Attributes(),
    StackTrace = new StackTrace(),
    TimeEvents = new Span.Types.TimeEvents(),
    Links = new Span.Types.Links(),
    Status = new Status(),
    SameProcessAsParentSpan = false,
    ChildSpanCount = 0,
    SpanKind = Span.Types.SpanKind.Unspecified,
};
// Make the request
Span response = traceServiceClient.CreateSpan(request);

CreateSpanAsync(Span, CallSettings)

public virtual Task<Span> CreateSpanAsync(Span request, CallSettings callSettings = null)

Creates a new span.

Parameters
Name Description
request Span

The request object containing all of the parameters for the API call.

callSettings CallSettings

If not null, applies overrides to this RPC call.

Returns
Type Description
TaskSpan

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
Span request = new Span
{
    SpanName = SpanName.FromProjectTraceSpan("[PROJECT]", "[TRACE]", "[SPAN]"),
    SpanId = "",
    ParentSpanId = "",
    DisplayName = new TruncatableString(),
    StartTime = new Timestamp(),
    EndTime = new Timestamp(),
    Attributes = new Span.Types.Attributes(),
    StackTrace = new StackTrace(),
    TimeEvents = new Span.Types.TimeEvents(),
    Links = new Span.Types.Links(),
    Status = new Status(),
    SameProcessAsParentSpan = false,
    ChildSpanCount = 0,
    SpanKind = Span.Types.SpanKind.Unspecified,
};
// Make the request
Span response = await traceServiceClient.CreateSpanAsync(request);

CreateSpanAsync(Span, CancellationToken)

public virtual Task<Span> CreateSpanAsync(Span request, CancellationToken cancellationToken)

Creates a new span.

Parameters
Name Description
request Span

The request object containing all of the parameters for the API call.

cancellationToken CancellationToken

A CancellationToken to use for this RPC.

Returns
Type Description
TaskSpan

A Task containing the RPC response.

Example
// Create client
TraceServiceClient traceServiceClient = await TraceServiceClient.CreateAsync();
// Initialize request argument(s)
Span request = new Span
{
    SpanName = SpanName.FromProjectTraceSpan("[PROJECT]", "[TRACE]", "[SPAN]"),
    SpanId = "",
    ParentSpanId = "",
    DisplayName = new TruncatableString(),
    StartTime = new Timestamp(),
    EndTime = new Timestamp(),
    Attributes = new Span.Types.Attributes(),
    StackTrace = new StackTrace(),
    TimeEvents = new Span.Types.TimeEvents(),
    Links = new Span.Types.Links(),
    Status = new Status(),
    SameProcessAsParentSpan = false,
    ChildSpanCount = 0,
    SpanKind = Span.Types.SpanKind.Unspecified,
};
// Make the request
Span response = await traceServiceClient.CreateSpanAsync(request);

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
Type Description
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.