@Generated(value="by gapic-generator") @BetaApi public class TraceServiceClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<Span> spans = new ArrayList<>();
traceServiceClient.batchWriteSpans(name, spans);
}
Note: close() needs to be called on the traceServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of TraceServiceSettings to create(). For example:
To customize credentials:
TraceServiceSettings traceServiceSettings =
TraceServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TraceServiceClient traceServiceClient =
TraceServiceClient.create(traceServiceSettings);
To customize the endpoint:
TraceServiceSettings traceServiceSettings =
TraceServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
TraceServiceClient traceServiceClient =
TraceServiceClient.create(traceServiceSettings);
Modifier | Constructor and Description |
---|---|
protected |
TraceServiceClient(TraceServiceSettings settings)
Constructs an instance of TraceServiceClient, using the given settings.
|
protected |
TraceServiceClient(TraceServiceStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
batchWriteSpans(com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest request)
Sends new spans to new or existing traces.
|
void |
batchWriteSpans(com.google.devtools.cloudtrace.v2.ProjectName name,
List<com.google.devtools.cloudtrace.v2.Span> spans)
Sends new spans to new or existing traces.
|
void |
batchWriteSpans(String name,
List<com.google.devtools.cloudtrace.v2.Span> spans)
Sends new spans to new or existing traces.
|
UnaryCallable<com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest,Empty> |
batchWriteSpansCallable()
Sends new spans to new or existing traces.
|
void |
close() |
static TraceServiceClient |
create()
Constructs an instance of TraceServiceClient with default settings.
|
static TraceServiceClient |
create(TraceServiceSettings settings)
Constructs an instance of TraceServiceClient, using the given settings.
|
static TraceServiceClient |
create(TraceServiceStub stub)
Constructs an instance of TraceServiceClient, using the given stub for making calls.
|
com.google.devtools.cloudtrace.v2.Span |
createSpan(com.google.devtools.cloudtrace.v2.Span request)
Creates a new span.
|
UnaryCallable<com.google.devtools.cloudtrace.v2.Span,com.google.devtools.cloudtrace.v2.Span> |
createSpanCallable()
Creates a new span.
|
TraceServiceSettings |
getSettings() |
TraceServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
void |
shutdown() |
void |
shutdownNow() |
protected TraceServiceClient(TraceServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected TraceServiceClient(TraceServiceStub stub)
public static final TraceServiceClient create() throws IOException
IOException
public static final TraceServiceClient create(TraceServiceSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final TraceServiceClient create(TraceServiceStub stub)
public final TraceServiceSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public TraceServiceStub getStub()
public final void batchWriteSpans(com.google.devtools.cloudtrace.v2.ProjectName name, List<com.google.devtools.cloudtrace.v2.Span> spans)
Sample code:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<Span> spans = new ArrayList<>();
traceServiceClient.batchWriteSpans(name, spans);
}
name
- Required. The name of the project where the spans belong. The format is
`projects/[PROJECT_ID]`.spans
- A list of new spans. The span names must not match existing spans, or the results
are undefined.ApiException
- if the remote call failspublic final void batchWriteSpans(String name, List<com.google.devtools.cloudtrace.v2.Span> spans)
Sample code:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<Span> spans = new ArrayList<>();
traceServiceClient.batchWriteSpans(name.toString(), spans);
}
name
- Required. The name of the project where the spans belong. The format is
`projects/[PROJECT_ID]`.spans
- A list of new spans. The span names must not match existing spans, or the results
are undefined.ApiException
- if the remote call failspublic final void batchWriteSpans(com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest request)
Sample code:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<Span> spans = new ArrayList<>();
BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder()
.setName(name.toString())
.addAllSpans(spans)
.build();
traceServiceClient.batchWriteSpans(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest,Empty> batchWriteSpansCallable()
Sample code:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
List<Span> spans = new ArrayList<>();
BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder()
.setName(name.toString())
.addAllSpans(spans)
.build();
ApiFuture<Void> future = traceServiceClient.batchWriteSpansCallable().futureCall(request);
// Do something
future.get();
}
public final com.google.devtools.cloudtrace.v2.Span createSpan(com.google.devtools.cloudtrace.v2.Span request)
Sample code:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
SpanName name = SpanName.of("[PROJECT]", "[TRACE]", "[SPAN]");
String spanId = "";
TruncatableString displayName = TruncatableString.newBuilder().build();
Timestamp startTime = Timestamp.newBuilder().build();
Timestamp endTime = Timestamp.newBuilder().build();
Span request = Span.newBuilder()
.setName(name.toString())
.setSpanId(spanId)
.setDisplayName(displayName)
.setStartTime(startTime)
.setEndTime(endTime)
.build();
Span response = traceServiceClient.createSpan(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.devtools.cloudtrace.v2.Span,com.google.devtools.cloudtrace.v2.Span> createSpanCallable()
Sample code:
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
SpanName name = SpanName.of("[PROJECT]", "[TRACE]", "[SPAN]");
String spanId = "";
TruncatableString displayName = TruncatableString.newBuilder().build();
Timestamp startTime = Timestamp.newBuilder().build();
Timestamp endTime = Timestamp.newBuilder().build();
Span request = Span.newBuilder()
.setName(name.toString())
.setSpanId(spanId)
.setDisplayName(displayName)
.setStartTime(startTime)
.setEndTime(endTime)
.build();
ApiFuture<Span> future = traceServiceClient.createSpanCallable().futureCall(request);
// Do something
Span response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.