|
| 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