Reference documentation and code samples for the Stackdriver Trace V1 Client class TraceServiceClient.
Service Description: This file describes an API for collecting and viewing traces and spans within a trace. A Trace is a collection of spans corresponding to a single operation or set of operations for an application. A span is an individual timed event which forms a node of the trace tree. Spans for a single trace may span multiple services.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods.
Namespace
Google \ Cloud \ Trace \ V1 \ ClientMethods
__construct
Constructor.
| Parameters | |
|---|---|
| Name | Description |
options |
array|Google\ApiCore\Options\ClientOptions
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
FetchAuthTokenInterface|CredentialsWrapper
This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|TransportInterface
The transport used for executing network requests. May be either the string |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
↳ logger |
false|LoggerInterface
A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag |
↳ universeDomain |
string
The service domain for the client. Defaults to 'googleapis.com'. |
getTrace
Gets a single trace by its ID.
The async variant is TraceServiceClient::getTraceAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Trace\V1\GetTraceRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\Cloud\Trace\V1\Trace |
|
use Google\ApiCore\ApiException;
use Google\Cloud\Trace\V1\Client\TraceServiceClient;
use Google\Cloud\Trace\V1\GetTraceRequest;
use Google\Cloud\Trace\V1\Trace;
/**
* @param string $projectId ID of the Cloud project where the trace data is stored.
* @param string $traceId ID of the trace to return.
*/
function get_trace_sample(string $projectId, string $traceId): void
{
// Create a client.
$traceServiceClient = new TraceServiceClient();
// Prepare the request message.
$request = (new GetTraceRequest())
->setProjectId($projectId)
->setTraceId($traceId);
// Call the API and handle any network failures.
try {
/** @var Trace $response */
$response = $traceServiceClient->getTrace($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$projectId = '[PROJECT_ID]';
$traceId = '[TRACE_ID]';
get_trace_sample($projectId, $traceId);
}
listTraces
Returns of a list of traces that match the specified filter conditions.
The async variant is TraceServiceClient::listTracesAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Trace\V1\ListTracesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
| Returns | |
|---|---|
| Type | Description |
Google\ApiCore\PagedListResponse |
|
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Trace\V1\Client\TraceServiceClient;
use Google\Cloud\Trace\V1\ListTracesRequest;
use Google\Cloud\Trace\V1\Trace;
/**
* @param string $projectId ID of the Cloud project where the trace data is stored.
*/
function list_traces_sample(string $projectId): void
{
// Create a client.
$traceServiceClient = new TraceServiceClient();
// Prepare the request message.
$request = (new ListTracesRequest())
->setProjectId($projectId);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $traceServiceClient->listTraces($request);
/** @var Trace $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$projectId = '[PROJECT_ID]';
list_traces_sample($projectId);
}
patchTraces
Sends new traces to Stackdriver Trace or updates existing traces. If the ID of a trace that you send matches that of an existing trace, any fields in the existing trace and its spans are overwritten by the provided values, and any new fields provided are merged with the existing trace data. If the ID does not match, a new trace is created.
The async variant is TraceServiceClient::patchTracesAsync() .
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Trace\V1\PatchTracesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
use Google\ApiCore\ApiException;
use Google\Cloud\Trace\V1\Client\TraceServiceClient;
use Google\Cloud\Trace\V1\PatchTracesRequest;
use Google\Cloud\Trace\V1\Traces;
/**
* @param string $projectId ID of the Cloud project where the trace data is stored.
*/
function patch_traces_sample(string $projectId): void
{
// Create a client.
$traceServiceClient = new TraceServiceClient();
// Prepare the request message.
$traces = new Traces();
$request = (new PatchTracesRequest())
->setProjectId($projectId)
->setTraces($traces);
// Call the API and handle any network failures.
try {
$traceServiceClient->patchTraces($request);
printf('Call completed successfully.' . PHP_EOL);
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$projectId = '[PROJECT_ID]';
patch_traces_sample($projectId);
}
getTraceAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Trace\V1\GetTraceRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\Cloud\Trace\V1\Trace> |
|
listTracesAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Trace\V1\ListTracesRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse> |
|
patchTracesAsync
| Parameters | |
|---|---|
| Name | Description |
request |
Google\Cloud\Trace\V1\PatchTracesRequest
|
optionalArgs |
array
|
| Returns | |
|---|---|
| Type | Description |
GuzzleHttp\Promise\PromiseInterface<void> |
|