Skip to content

Commit 4cbe5b7

Browse files
authored
feat: add Trace V1 (#9013)
1 parent a76ee6c commit 4cbe5b7

20 files changed

Lines changed: 2721 additions & 2 deletions

Trace/.OwlBot.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
deep-copy-regex:
2-
- source: /google/devtools/cloudtrace/(v2)/.*-php/(.*)
3-
dest: /owl-bot-staging/Trace/$1/$2
2+
-
3+
source: '/google/devtools/cloudtrace/(v2|v1)/.*-php/(.*)'
4+
dest: /owl-bot-staging/Trace/$1/$2
45
api-name: Trace

Trace/metadata/V1/Trace.php

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START cloudtrace_v1_generated_TraceService_GetTrace_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\Trace\V1\Client\TraceServiceClient;
28+
use Google\Cloud\Trace\V1\GetTraceRequest;
29+
use Google\Cloud\Trace\V1\Trace;
30+
31+
/**
32+
* Gets a single trace by its ID.
33+
*
34+
* @param string $projectId ID of the Cloud project where the trace data is stored.
35+
* @param string $traceId ID of the trace to return.
36+
*/
37+
function get_trace_sample(string $projectId, string $traceId): void
38+
{
39+
// Create a client.
40+
$traceServiceClient = new TraceServiceClient();
41+
42+
// Prepare the request message.
43+
$request = (new GetTraceRequest())
44+
->setProjectId($projectId)
45+
->setTraceId($traceId);
46+
47+
// Call the API and handle any network failures.
48+
try {
49+
/** @var Trace $response */
50+
$response = $traceServiceClient->getTrace($request);
51+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
52+
} catch (ApiException $ex) {
53+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
54+
}
55+
}
56+
57+
/**
58+
* Helper to execute the sample.
59+
*
60+
* This sample has been automatically generated and should be regarded as a code
61+
* template only. It will require modifications to work:
62+
* - It may require correct/in-range values for request initialization.
63+
* - It may require specifying regional endpoints when creating the service client,
64+
* please see the apiEndpoint client configuration option for more details.
65+
*/
66+
function callSample(): void
67+
{
68+
$projectId = '[PROJECT_ID]';
69+
$traceId = '[TRACE_ID]';
70+
71+
get_trace_sample($projectId, $traceId);
72+
}
73+
// [END cloudtrace_v1_generated_TraceService_GetTrace_sync]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START cloudtrace_v1_generated_TraceService_ListTraces_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
28+
use Google\Cloud\Trace\V1\Client\TraceServiceClient;
29+
use Google\Cloud\Trace\V1\ListTracesRequest;
30+
use Google\Cloud\Trace\V1\Trace;
31+
32+
/**
33+
* Returns of a list of traces that match the specified filter conditions.
34+
*
35+
* @param string $projectId ID of the Cloud project where the trace data is stored.
36+
*/
37+
function list_traces_sample(string $projectId): void
38+
{
39+
// Create a client.
40+
$traceServiceClient = new TraceServiceClient();
41+
42+
// Prepare the request message.
43+
$request = (new ListTracesRequest())
44+
->setProjectId($projectId);
45+
46+
// Call the API and handle any network failures.
47+
try {
48+
/** @var PagedListResponse $response */
49+
$response = $traceServiceClient->listTraces($request);
50+
51+
/** @var Trace $element */
52+
foreach ($response as $element) {
53+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
54+
}
55+
} catch (ApiException $ex) {
56+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
57+
}
58+
}
59+
60+
/**
61+
* Helper to execute the sample.
62+
*
63+
* This sample has been automatically generated and should be regarded as a code
64+
* template only. It will require modifications to work:
65+
* - It may require correct/in-range values for request initialization.
66+
* - It may require specifying regional endpoints when creating the service client,
67+
* please see the apiEndpoint client configuration option for more details.
68+
*/
69+
function callSample(): void
70+
{
71+
$projectId = '[PROJECT_ID]';
72+
73+
list_traces_sample($projectId);
74+
}
75+
// [END cloudtrace_v1_generated_TraceService_ListTraces_sync]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/*
3+
* Copyright 2026 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START cloudtrace_v1_generated_TraceService_PatchTraces_sync]
26+
use Google\ApiCore\ApiException;
27+
use Google\Cloud\Trace\V1\Client\TraceServiceClient;
28+
use Google\Cloud\Trace\V1\PatchTracesRequest;
29+
use Google\Cloud\Trace\V1\Traces;
30+
31+
/**
32+
* Sends new traces to Stackdriver Trace or updates existing traces. If the ID
33+
* of a trace that you send matches that of an existing trace, any fields
34+
* in the existing trace and its spans are overwritten by the provided values,
35+
* and any new fields provided are merged with the existing trace data. If the
36+
* ID does not match, a new trace is created.
37+
*
38+
* @param string $projectId ID of the Cloud project where the trace data is stored.
39+
*/
40+
function patch_traces_sample(string $projectId): void
41+
{
42+
// Create a client.
43+
$traceServiceClient = new TraceServiceClient();
44+
45+
// Prepare the request message.
46+
$traces = new Traces();
47+
$request = (new PatchTracesRequest())
48+
->setProjectId($projectId)
49+
->setTraces($traces);
50+
51+
// Call the API and handle any network failures.
52+
try {
53+
$traceServiceClient->patchTraces($request);
54+
printf('Call completed successfully.' . PHP_EOL);
55+
} catch (ApiException $ex) {
56+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
57+
}
58+
}
59+
60+
/**
61+
* Helper to execute the sample.
62+
*
63+
* This sample has been automatically generated and should be regarded as a code
64+
* template only. It will require modifications to work:
65+
* - It may require correct/in-range values for request initialization.
66+
* - It may require specifying regional endpoints when creating the service client,
67+
* please see the apiEndpoint client configuration option for more details.
68+
*/
69+
function callSample(): void
70+
{
71+
$projectId = '[PROJECT_ID]';
72+
73+
patch_traces_sample($projectId);
74+
}
75+
// [END cloudtrace_v1_generated_TraceService_PatchTraces_sync]

0 commit comments

Comments
 (0)