├── .gitattributes ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── VERSION ├── composer.json ├── metadata ├── V1 │ └── Trace.php └── V2 │ ├── Trace.php │ └── Tracing.php └── src ├── Annotation.php ├── AttributeTrait.php ├── Attributes.php ├── Connection ├── ConnectionInterface.php ├── Grpc.php ├── Rest.php └── ServiceDefinition │ └── trace-v2.json ├── Link.php ├── MessageEvent.php ├── Span.php ├── StackTrace.php ├── Status.php ├── TimeEvent.php ├── TimestampTrait.php ├── Trace.php ├── TraceClient.php └── V2 ├── AttributeValue.php ├── BatchWriteSpansRequest.php ├── Client └── TraceServiceClient.php ├── Gapic └── TraceServiceGapicClient.php ├── Module.php ├── README.md ├── Span.php ├── Span ├── Attributes.php ├── Link.php ├── Link │ └── Type.php ├── Links.php ├── SpanKind.php ├── TimeEvent.php ├── TimeEvent │ ├── Annotation.php │ ├── MessageEvent.php │ └── MessageEvent │ │ └── Type.php └── TimeEvents.php ├── Span_Attributes.php ├── Span_Link.php ├── Span_Link_Type.php ├── Span_Links.php ├── Span_SpanKind.php ├── Span_TimeEvent.php ├── Span_TimeEvent_Annotation.php ├── Span_TimeEvent_MessageEvent.php ├── Span_TimeEvent_MessageEvent_Type.php ├── Span_TimeEvents.php ├── StackTrace.php ├── StackTrace ├── StackFrame.php └── StackFrames.php ├── StackTrace_StackFrame.php ├── StackTrace_StackFrames.php ├── TraceServiceClient.php ├── TraceServiceGrpcClient.php ├── TruncatableString.php └── resources ├── trace_service_client_config.json ├── trace_service_descriptor_config.php └── trace_service_rest_client_config.php /.gitattributes: -------------------------------------------------------------------------------- 1 | /*.xml.dist export-ignore 2 | /tests export-ignore 3 | /.github export-ignore 4 | /samples export-ignore 5 | /.OwlBot.yaml export-ignore 6 | /owlbot.py export-ignore 7 | /src/**/gapic_metadata.json export-ignore 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, 4 | and in the interest of fostering an open and welcoming community, 5 | we pledge to respect all people who contribute through reporting issues, 6 | posting feature requests, updating documentation, 7 | submitting pull requests or patches, and other activities. 8 | 9 | We are committed to making participation in this project 10 | a harassment-free experience for everyone, 11 | regardless of level of experience, gender, gender identity and expression, 12 | sexual orientation, disability, personal appearance, 13 | body size, race, ethnicity, age, religion, or nationality. 14 | 15 | Examples of unacceptable behavior by participants include: 16 | 17 | * The use of sexualized language or imagery 18 | * Personal attacks 19 | * Trolling or insulting/derogatory comments 20 | * Public or private harassment 21 | * Publishing other's private information, 22 | such as physical or electronic 23 | addresses, without explicit permission 24 | * Other unethical or unprofessional conduct. 25 | 26 | Project maintainers have the right and responsibility to remove, edit, or reject 27 | comments, commits, code, wiki edits, issues, and other contributions 28 | that are not aligned to this Code of Conduct. 29 | By adopting this Code of Conduct, 30 | project maintainers commit themselves to fairly and consistently 31 | applying these principles to every aspect of managing this project. 32 | Project maintainers who do not follow or enforce the Code of Conduct 33 | may be permanently removed from the project team. 34 | 35 | This code of conduct applies both within project spaces and in public spaces 36 | when an individual is representing the project or its community. 37 | 38 | Instances of abusive, harassing, or otherwise unacceptable behavior 39 | may be reported by opening an issue 40 | or contacting one or more of the project maintainers. 41 | 42 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, 43 | available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. We accept 4 | and review pull requests against the main 5 | [Google Cloud PHP](https://github.com/googleapis/google-cloud-php) 6 | repository, which contains all of our client libraries. You will also need to 7 | sign a Contributor License Agreement. For more details about how to contribute, 8 | see the 9 | [CONTRIBUTING.md](https://github.com/googleapis/google-cloud-php/blob/main/CONTRIBUTING.md) 10 | file in the main Google Cloud PHP repository. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stackdriver Trace for PHP 2 | 3 | > Idiomatic PHP client for [Stackdriver Trace][stackdriver-trace]. 4 | 5 | [![Latest Stable Version](https://poser.pugx.org/google/cloud-trace/v/stable)](https://packagist.org/packages/google/cloud-trace) [![Packagist](https://img.shields.io/packagist/dm/google/cloud-trace.svg)](https://packagist.org/packages/google/cloud-trace) 6 | 7 | * [API documentation][api-docs] 8 | 9 | **NOTE:** This repository is part of [Google Cloud PHP][homepage]. Any 10 | support requests, bug reports, or development contributions should be directed to 11 | that project. 12 | 13 | A distributed tracing system for Google Cloud Platform that collects latency 14 | data from App Engine applications and displays it in near real time in the 15 | Google Cloud Platform Console. 16 | 17 | ### Installation 18 | 19 | To begin, install the preferred dependency manager for PHP, 20 | [Composer](https://getcomposer.org/). 21 | 22 | Now install this component: 23 | 24 | ```sh 25 | $ composer require google/cloud-trace 26 | ``` 27 | 28 | This component supports both REST over HTTP/1.1 and gRPC. In order to take 29 | advantage of the benefits offered by gRPC (such as streaming methods) 30 | please see our [gRPC installation guide](https://cloud.google.com/php/grpc). 31 | 32 | ### Authentication 33 | 34 | Please see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) 35 | for more information on authenticating your client. Once authenticated, you'll 36 | be ready to start making requests. 37 | 38 | ### Sample 39 | 40 | ```php 41 | require 'vendor/autoload.php'; 42 | 43 | use Google\Cloud\Trace\TraceClient; 44 | 45 | $traceClient = new TraceClient(); 46 | 47 | // Create a Trace 48 | $trace = $traceClient->trace(); 49 | $span = $trace->span([ 50 | 'name' => 'main' 51 | ]); 52 | $span->setStartTime(); 53 | // some expensive operation 54 | $span->setEndTime(); 55 | 56 | $trace->setSpans([$span]); 57 | $traceClient->insert($trace); 58 | 59 | // List recent Traces 60 | foreach($traceClient->traces() as $trace) { 61 | var_dump($trace->traceId()); 62 | } 63 | ``` 64 | 65 | ### Creating a Trace 66 | 67 | ```php 68 | use Google\Cloud\Trace\TraceClient; 69 | 70 | $client = new TraceClient(); 71 | $trace = $client->trace(); 72 | $span = $trace->span(['name' => 'main']); 73 | $trace->setSpans([$span]); 74 | 75 | $client->insert($trace); 76 | ``` 77 | 78 | ### Using OpenCensus 79 | 80 | We highly recommend using the [OpenCensus][opencensus] project to instrument 81 | your application. OpenCensus is an open source, distributed tracing framework 82 | that maintains integrations with popular frameworks and tools. OpenCensus 83 | provides a data exporter for Stackdriver Trace which uses this library. If you 84 | were using google/cloud-trace <= v0.3.3 or google/cloud <= 0.46.0, then check 85 | out the [migration guide to OpenCensus][opencensus-migration]. 86 | 87 | Install with `composer` or add to your `composer.json`. 88 | 89 | ```sh 90 | $ composer require opencensus/opencensus opencensus/opencensus-exporter-stackdriver 91 | ``` 92 | 93 | `opencensus/opencensus` provides a service-agnostic implementation. Be sure to 94 | also require `opencensus/opencensus-exporter-stackdriver` to enable exporting of 95 | traces to Stackdriver Trace. 96 | 97 | ```php 98 | use OpenCensus\Trace\Exporter\StackdriverExporter; 99 | use OpenCensus\Trace\Tracer; 100 | 101 | Tracer::start(new StackdriverExporter()); 102 | ``` 103 | 104 | See the [OpenCensus documentation][opencensus-php] for more configuration 105 | options and features. 106 | 107 | ### Debugging 108 | 109 | Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) 110 | for more information about the debugging tools. 111 | 112 | ### Version 113 | 114 | This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in 115 | any minor or patch releases. We will address issues and requests with the highest priority. 116 | 117 | ### Next Steps 118 | 119 | 1. Understand the [official documentation][official-documentation]. 120 | 2. Take a look at [in-depth usage samples][usage-samples]. 121 | 122 | 123 | [stackdriver-trace]: https://cloud.google.com/trace/ 124 | [homepage]: https://cloud.google.com/php/docs/reference 125 | [api-docs]: https://cloud.google.com/php/docs/reference/cloud-trace/latest 126 | [opencensus]: http://opencensus.io 127 | [opencensus-php]: https://github.com/census-instrumentation/opencensus-php 128 | [opencensus-migration]: http://opencensus.io/opencensus-php/migrating-stackdriver-trace 129 | [official-documentation]: https://cloud.google.com/trace/docs/ 130 | [usage-samples]: https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/trace/ 131 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). 4 | 5 | The Google Security Team will respond within 5 working days of your report on g.co/vulnz. 6 | 7 | We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. 8 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.8.9 2 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google/cloud-trace", 3 | "description": "Stackdriver Trace Client for PHP", 4 | "license": "Apache-2.0", 5 | "minimum-stability": "stable", 6 | "require": { 7 | "php": "^8.0", 8 | "google/cloud-core": "^1.57", 9 | "ramsey/uuid": "^3.0|^4.0", 10 | "google/gax": "^1.36.0" 11 | }, 12 | "require-dev": { 13 | "phpunit/phpunit": "^9.0", 14 | "phpspec/prophecy-phpunit": "^2.0", 15 | "squizlabs/php_codesniffer": "2.*", 16 | "phpdocumentor/reflection": "^5.3.3||^6.0", 17 | "phpdocumentor/reflection-docblock": "^5.3", 18 | "erusev/parsedown": "^1.6" 19 | }, 20 | "suggest": { 21 | "ext-grpc": "The gRPC extension enables use of the performant gRPC transport", 22 | "ext-protobuf": "Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions.", 23 | "opencensus/opencensus": "Provides application tracing integrations." 24 | }, 25 | "extra": { 26 | "component": { 27 | "id": "cloud-trace", 28 | "target": "googleapis/google-cloud-php-trace.git", 29 | "path": "Trace", 30 | "entry": "src/TraceClient.php" 31 | } 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Google\\Cloud\\Trace\\": "src", 36 | "GPBMetadata\\Google\\Devtools\\Cloudtrace\\": "metadata" 37 | } 38 | }, 39 | "autoload-dev": { 40 | "psr-4": { 41 | "Google\\Cloud\\Trace\\Tests\\": "tests" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /metadata/V1/Trace.php: -------------------------------------------------------------------------------- 1 | internalAddGeneratedFile(hex2bin( 21 | "0aaa0f0a29676f6f676c652f646576746f6f6c732f636c6f756474726163" . 22 | "652f76312f74726163652e70726f746f121d676f6f676c652e646576746f" . 23 | "6f6c732e636c6f756474726163652e76311a1b676f6f676c652f70726f74" . 24 | "6f6275662f656d7074792e70726f746f1a1f676f6f676c652f70726f746f" . 25 | "6275662f74696d657374616d702e70726f746f22660a0554726163651212" . 26 | "0a0a70726f6a6563745f696418012001280912100a0874726163655f6964" . 27 | "18022001280912370a057370616e7318032003280b32282e676f6f676c65" . 28 | "2e646576746f6f6c732e636c6f756474726163652e76312e547261636553" . 29 | "70616e223e0a0654726163657312340a0674726163657318012003280b32" . 30 | "242e676f6f676c652e646576746f6f6c732e636c6f756474726163652e76" . 31 | "312e5472616365229d030a0954726163655370616e120f0a077370616e5f" . 32 | "6964180120012806123f0a046b696e6418022001280e32312e676f6f676c" . 33 | "652e646576746f6f6c732e636c6f756474726163652e76312e5472616365" . 34 | "5370616e2e5370616e4b696e64120c0a046e616d65180320012809122e0a" . 35 | "0a73746172745f74696d6518042001280b321a2e676f6f676c652e70726f" . 36 | "746f6275662e54696d657374616d70122c0a08656e645f74696d65180520" . 37 | "01280b321a2e676f6f676c652e70726f746f6275662e54696d657374616d" . 38 | "7012160a0e706172656e745f7370616e5f696418062001280612440a066c" . 39 | "6162656c7318072003280b32342e676f6f676c652e646576746f6f6c732e" . 40 | "636c6f756474726163652e76312e54726163655370616e2e4c6162656c73" . 41 | "456e7472791a2d0a0b4c6162656c73456e747279120b0a036b6579180120" . 42 | "012809120d0a0576616c75651802200128093a02380122450a085370616e" . 43 | "4b696e6412190a155350414e5f4b494e445f554e53504543494649454410" . 44 | "00120e0a0a5250435f5345525645521001120e0a0a5250435f434c49454e" . 45 | "54100222e7020a114c6973745472616365735265717565737412120a0a70" . 46 | "726f6a6563745f696418012001280912470a047669657718022001280e32" . 47 | "392e676f6f676c652e646576746f6f6c732e636c6f756474726163652e76" . 48 | "312e4c697374547261636573526571756573742e56696577547970651211" . 49 | "0a09706167655f73697a6518032001280512120a0a706167655f746f6b65" . 50 | "6e180420012809122e0a0a73746172745f74696d6518052001280b321a2e" . 51 | "676f6f676c652e70726f746f6275662e54696d657374616d70122c0a0865" . 52 | "6e645f74696d6518062001280b321a2e676f6f676c652e70726f746f6275" . 53 | "662e54696d657374616d70120e0a0666696c74657218072001280912100a" . 54 | "086f726465725f6279180820012809224e0a08566965775479706512190a" . 55 | "15564945575f545950455f554e5350454349464945441000120b0a074d49" . 56 | "4e494d414c1001120c0a08524f4f545350414e1002120c0a08434f4d504c" . 57 | "455445100322630a124c697374547261636573526573706f6e736512340a" . 58 | "0674726163657318012003280b32242e676f6f676c652e646576746f6f6c" . 59 | "732e636c6f756474726163652e76312e547261636512170a0f6e6578745f" . 60 | "706167655f746f6b656e18022001280922370a0f47657454726163655265" . 61 | "717565737412120a0a70726f6a6563745f696418012001280912100a0874" . 62 | "726163655f6964180220012809225f0a1250617463685472616365735265" . 63 | "717565737412120a0a70726f6a6563745f696418012001280912350a0674" . 64 | "726163657318022001280b32252e676f6f676c652e646576746f6f6c732e" . 65 | "636c6f756474726163652e76312e54726163657332d1030a0c5472616365" . 66 | "53657276696365129b010a0a4c69737454726163657312302e676f6f676c" . 67 | "652e646576746f6f6c732e636c6f756474726163652e76312e4c69737454" . 68 | "7261636573526571756573741a312e676f6f676c652e646576746f6f6c73" . 69 | "2e636c6f756474726163652e76312e4c697374547261636573526573706f" . 70 | "6e7365222882d3e493022212202f76312f70726f6a656374732f7b70726f" . 71 | "6a6563745f69647d2f7472616365731295010a084765745472616365122e" . 72 | "2e676f6f676c652e646576746f6f6c732e636c6f756474726163652e7631" . 73 | "2e4765745472616365526571756573741a242e676f6f676c652e64657674" . 74 | "6f6f6c732e636c6f756474726163652e76312e5472616365223382d3e493" . 75 | "022d122b2f76312f70726f6a656374732f7b70726f6a6563745f69647d2f" . 76 | "7472616365732f7b74726163655f69647d128a010a0b5061746368547261" . 77 | "63657312312e676f6f676c652e646576746f6f6c732e636c6f7564747261" . 78 | "63652e76312e5061746368547261636573526571756573741a162e676f6f" . 79 | "676c652e70726f746f6275662e456d707479223082d3e493022a32202f76" . 80 | "312f70726f6a656374732f7b70726f6a6563745f69647d2f747261636573" . 81 | "3a067472616365734292010a21636f6d2e676f6f676c652e646576746f6f" . 82 | "6c732e636c6f756474726163652e7631420a547261636550726f746f5001" . 83 | "5a47676f6f676c652e676f6c616e672e6f72672f67656e70726f746f2f67" . 84 | "6f6f676c65617069732f646576746f6f6c732f636c6f756474726163652f" . 85 | "76313b636c6f75647472616365aa0215476f6f676c652e436c6f75642e54" . 86 | "726163652e5631620670726f746f33" 87 | )); 88 | 89 | static::$is_initialized = true; 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /metadata/V2/Trace.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-php-trace/a11c026440ee6e8d28074f5befecb0e634bc93cb/metadata/V2/Trace.php -------------------------------------------------------------------------------- /metadata/V2/Tracing.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/google-cloud-php-trace/a11c026440ee6e8d28074f5befecb0e634bc93cb/metadata/V2/Tracing.php -------------------------------------------------------------------------------- /src/Annotation.php: -------------------------------------------------------------------------------- 1 | addTimeEvent($annotation); 30 | * ``` 31 | * 32 | * @see https://cloud.google.com/trace/docs/reference/v2/rest/v2/TimeEvents#annotation Annotation model documentation 33 | */ 34 | class Annotation extends TimeEvent 35 | { 36 | use AttributeTrait; 37 | 38 | /** 39 | * @var string A user-supplied message describing the event. The maximum 40 | * length for the description is 256 bytes. 41 | */ 42 | private $description; 43 | 44 | /** 45 | * Create a new Annotation. 46 | * 47 | * @param string $description A user-supplied message describing the event. 48 | * The maximum length for the description is 256 bytes. 49 | * @param array $options [optional] { 50 | * Configuration options. 51 | * 52 | * @type array $attributes A set of attributes on the annotation. You 53 | * can have up to 4 attributes per Annotation. 54 | * } 55 | */ 56 | public function __construct($description, array $options = []) 57 | { 58 | parent::__construct($options); 59 | $this->description = $description; 60 | if (array_key_exists('attributes', $options)) { 61 | $this->addAttributes($options['attributes']); 62 | } 63 | } 64 | 65 | /** 66 | * Returns a serializable array representing this Link. 67 | * 68 | * @access private 69 | * @return array 70 | */ 71 | public function info() 72 | { 73 | $data = [ 74 | 'description' => [ 75 | 'value' => $this->description 76 | ] 77 | ]; 78 | if ($this->attributes) { 79 | $data['attributes'] = $this->attributes->info(); 80 | } 81 | 82 | return [ 83 | 'time' => $this->time, 84 | 'annotation' => $data 85 | ]; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/AttributeTrait.php: -------------------------------------------------------------------------------- 1 | $value 34 | */ 35 | public function addAttributes(array $attributes) 36 | { 37 | foreach ($attributes as $key => $value) { 38 | $this->addAttribute($key, $value); 39 | } 40 | } 41 | 42 | /** 43 | * Attach a single label to this span. 44 | * 45 | * @param string $label The name of the label. 46 | * @param mixed $value The value of the label. Will be cast to a string 47 | */ 48 | public function addAttribute($key, $value) 49 | { 50 | if (!$this->attributes) { 51 | $this->attributes = new Attributes(); 52 | } 53 | 54 | $this->attributes[$key] = $value; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Attributes.php: -------------------------------------------------------------------------------- 1 | attributes[$offset] = $value; 58 | } 59 | 60 | /** 61 | * Callback for \ArrayAccess isset. 62 | * 63 | * @access private 64 | * @param string $offset 65 | */ 66 | #[\ReturnTypeWillChange] 67 | public function offsetExists($offset) 68 | { 69 | return isset($this->attributes[$offset]); 70 | } 71 | 72 | /** 73 | * Callback for \ArrayAccess unset. 74 | * 75 | * @access private 76 | * @param string $offset 77 | */ 78 | #[\ReturnTypeWillChange] 79 | public function offsetUnset($offset) 80 | { 81 | unset($this->attributes[$offset]); 82 | } 83 | 84 | /** 85 | * Callback for \ArrayAccess [$key] getter. 86 | * 87 | * @access private 88 | * @param string $offset 89 | */ 90 | #[\ReturnTypeWillChange] 91 | public function offsetGet($offset) 92 | { 93 | return isset($this->attributes[$offset]) 94 | ? $this->attributes[$offset] 95 | : null; 96 | } 97 | 98 | /** 99 | * Returns a serializable array representing this Link. 100 | * 101 | * @access private 102 | * @return array 103 | */ 104 | public function info() 105 | { 106 | $data = []; 107 | foreach ($this->attributes as $key => $value) { 108 | switch (gettype($value)) { 109 | case 'boolean': 110 | $data[$key] = [ 111 | 'boolValue' => $value 112 | ]; 113 | break; 114 | case 'integer': 115 | $data[$key] = [ 116 | 'intValue' => $value 117 | ]; 118 | break; 119 | default: 120 | $data[$key] = [ 121 | 'stringValue' => ['value' => (string) $value] 122 | ]; 123 | } 124 | } 125 | return [ 126 | 'attributeMap' => $data 127 | ]; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/Connection/ConnectionInterface.php: -------------------------------------------------------------------------------- 1 | serializer = new Serializer( 55 | [], 56 | [ 57 | 'google.protobuf.Timestamp' => function ($v) { 58 | return $this->formatTimestampFromApi($v); 59 | } 60 | ], 61 | [], 62 | [ 63 | 'google.protobuf.Timestamp' => function ($v) { 64 | return $this->formatTimestampForApi($v); 65 | } 66 | ] 67 | ); 68 | $config['serializer'] = $this->serializer; 69 | $this->setRequestWrapper(new GrpcRequestWrapper($config)); 70 | $gaxConfig = $this->getGaxConfig( 71 | TraceClient::VERSION, 72 | isset($config['authHttpHandler']) 73 | ? $config['authHttpHandler'] 74 | : null 75 | ); 76 | 77 | if (isset($config['apiEndpoint'])) { 78 | $gaxConfig['apiEndpoint'] = $config['apiEndpoint']; 79 | } 80 | 81 | $this->traceClient = $this->constructGapic(TraceServiceClient::class, $gaxConfig); 82 | } 83 | 84 | /** 85 | * Sends new spans to new or existing traces. You cannot update existing 86 | * spans. 87 | * 88 | * @param array $args { 89 | * Batch write params. 90 | * 91 | * @type string $projectsId The ID of the Google Cloud Project 92 | * @type array $spans Array of associative array span data. See 93 | * {@see Google\Cloud\Trace\Span::info()} for format. 94 | * } 95 | */ 96 | public function traceBatchWrite(array $args) 97 | { 98 | $spans = $this->pluck('spans', $args); 99 | return $this->send([$this->traceClient, 'batchWriteSpans'], [ 100 | TraceServiceClient::projectName($this->pluck('projectsId', $args)), 101 | array_map(function (array $span) { 102 | return $this->serializer->decodeMessage(new Span(), $span); 103 | }, $spans), 104 | $args 105 | ]); 106 | } 107 | 108 | /** 109 | * @param array $args 110 | */ 111 | public function traceSpanCreate(array $args) 112 | { 113 | return $this->send([$this->traceClient, 'createSpan'], [ 114 | TraceServiceClient::projectName($this->pluck('projectsId', $args)), 115 | $this->pluck('spanId', $args), 116 | $this->pluck('displayName', $args), 117 | $this->formatTimestampForApi($this->pluck('startTime', $args)), 118 | $this->formatTimestampForApi($this->pluck('endTime', $args)), 119 | $args 120 | ]); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Connection/Rest.php: -------------------------------------------------------------------------------- 1 | __DIR__ . '/ServiceDefinition/trace-v2.json' 45 | ]; 46 | 47 | $this->setRequestWrapper(new RequestWrapper($config)); 48 | $this->setRequestBuilder(new RequestBuilder( 49 | $config['serviceDefinitionPath'], 50 | $this->getApiEndpoint(self::BASE_URI, $config) 51 | )); 52 | } 53 | 54 | /** 55 | * Sends new spans to new or existing traces. You cannot update existing 56 | * spans. 57 | * 58 | * @param array $args { 59 | * Batch write params. 60 | * 61 | * @type string $projectsId The ID of the Google Cloud Project 62 | * @type array $spans Array of associative array span data. See 63 | * {@see Google\Cloud\Trace\Span::info()} for format. 64 | * } 65 | */ 66 | public function traceBatchWrite(array $args) 67 | { 68 | return $this->send('projects.resources.traces', 'batchWrite', $args); 69 | } 70 | 71 | /** 72 | * @param array $args 73 | */ 74 | public function traceSpanCreate(array $args) 75 | { 76 | return $this->send('projects.resources.traces.resources.spans', 'create', $args); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Link.php: -------------------------------------------------------------------------------- 1 | addLink($link); 35 | * ``` 36 | * 37 | * @see https://cloud.google.com/trace/docs/reference/v2/rest/v2/Links#link Link model documentation 38 | */ 39 | class Link 40 | { 41 | use AttributeTrait; 42 | 43 | const TYPE_UNSPECIFIED = Type::TYPE_UNSPECIFIED; 44 | const TYPE_CHILD_LINKED_SPAN = Type::CHILD_LINKED_SPAN; 45 | const TYPE_PARENT_LINKED_SPAN = Type::PARENT_LINKED_SPAN; 46 | 47 | /** 48 | * @var string The [TRACE_ID] for a trace within a project. 49 | */ 50 | private $traceId; 51 | 52 | /** 53 | * @var string The [SPAN_ID] for a span within a trace. 54 | */ 55 | private $spanId; 56 | 57 | /** 58 | * @var string The relationship of the current span relative to the linked 59 | * span. 60 | */ 61 | private $type; 62 | 63 | /** 64 | * Create a new Link. 65 | * 66 | * @param string $traceId 67 | * @param string $spanId 68 | * @param array $options [optional] { 69 | * Configuration options. 70 | * 71 | * @type string $type The relationship of the current span relative to 72 | * the linked span. **Defaults to** `TYPE_UNSPECIFIED`. 73 | * @type int $uncompressedSizeBytes The number of uncompressed bytes 74 | * sent or received. 75 | * @type int $compressedSizeBytes The number of compressed bytes sent or 76 | * received. If missing assumed to be the same size as 77 | * uncompressed. 78 | * } 79 | */ 80 | public function __construct($traceId, $spanId, array $options = []) 81 | { 82 | $options += [ 83 | 'type' => self::TYPE_UNSPECIFIED 84 | ]; 85 | $this->traceId = $traceId; 86 | $this->spanId = $spanId; 87 | $this->type = $options['type']; 88 | if (array_key_exists('attributes', $options)) { 89 | $this->addAttributes($options['attributes']); 90 | } 91 | } 92 | 93 | /** 94 | * Returns a serializable array representing this Link. 95 | * 96 | * @access private 97 | * @return array 98 | */ 99 | public function info() 100 | { 101 | $data = [ 102 | 'traceId' => $this->traceId, 103 | 'spanId' => $this->spanId, 104 | 'type' => $this->type 105 | ]; 106 | if ($this->attributes) { 107 | $data['attributes'] = $this->attributes->info(); 108 | } 109 | 110 | return $data; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/MessageEvent.php: -------------------------------------------------------------------------------- 1 | addTimeEvent($messageEvent); 32 | * ``` 33 | * 34 | * @codingStandardsIgnoreStart 35 | * @see https://cloud.google.com/trace/docs/reference/v2/rest/v2/TimeEvents#messageevent MessageEvent model documentation 36 | * @codingStandardsIgnoreEnd 37 | */ 38 | class MessageEvent extends TimeEvent 39 | { 40 | const TYPE_UNSPECIFIED = Type::TYPE_UNSPECIFIED; 41 | const TYPE_SENT = Type::SENT; 42 | const TYPE_RECEIVED = Type::RECEIVED; 43 | 44 | /** 45 | * @var string Type of MessageEvent. Indicates whether the message was sent 46 | * or received. 47 | */ 48 | private $type; 49 | 50 | /** 51 | * @var int An identifier for the MessageEvent's message that can be used to 52 | * match SENT and RECEIVED MessageEvents. It is recommended to be 53 | * unique within a Span. 54 | */ 55 | private $id; 56 | 57 | /** 58 | * @var int The number of uncompressed bytes sent or received. 59 | */ 60 | private $uncompressedSizeBytes; 61 | 62 | /** 63 | * @var int The number of compressed bytes sent or received. If missing, 64 | * assumed to be the same size as uncompressed. 65 | */ 66 | private $compressedSizeBytes; 67 | 68 | /** 69 | * Create a new MessageEvent. 70 | * 71 | * @param $id An identifier for the MessageEvent's message that can be used 72 | * to match SENT and RECEIVED MessageEvents. It is recommended to be 73 | * unique within a Span. 74 | * @param array $options [optional] { 75 | * Configuration options. 76 | * 77 | * @type string $type Type of MessageEvent. Indicates whether the 78 | * message was sent or received. **Defaults to** 79 | * `TYPE_UNSPECIFIED`. 80 | * @type int $uncompressedSizeBytes The number of uncompressed bytes 81 | * sent or received. 82 | * @type int $compressedSizeBytes The number of compressed bytes sent or 83 | * received. If missing assumed to be the same size as 84 | * uncompressed. 85 | * } 86 | */ 87 | public function __construct($id, array $options = []) 88 | { 89 | parent::__construct($options); 90 | $options += [ 91 | 'type' => self::TYPE_UNSPECIFIED, 92 | 'uncompressedSizeBytes' => null, 93 | 'compressedSizeBytes' => null 94 | ]; 95 | $this->id = $id; 96 | $this->type = $options['type']; 97 | $this->uncompressedSizeBytes = $options['uncompressedSizeBytes']; 98 | $this->compressedSizeBytes = $options['compressedSizeBytes']; 99 | } 100 | 101 | /** 102 | * Returns a serializable array representing this MessageEvent. 103 | * 104 | * @access private 105 | * @return array 106 | */ 107 | public function info() 108 | { 109 | $data = [ 110 | 'id' => $this->id, 111 | 'type' => $this->type 112 | ]; 113 | 114 | if ($this->uncompressedSizeBytes) { 115 | $data['uncompressedSizeBytes'] = $this->uncompressedSizeBytes; 116 | } 117 | if ($this->compressedSizeBytes) { 118 | $data['compressedSizeBytes'] = $this->compressedSizeBytes; 119 | } 120 | 121 | return [ 122 | 'time' => $this->time, 123 | 'messageEvent' => $data 124 | ]; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Span.php: -------------------------------------------------------------------------------- 1 | trace(); 35 | * $span = $trace->span([ 36 | * 'name' => 'span name', 37 | * 'attributes' => ['foo' => 'bar'], 38 | * 'stackTrace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) 39 | * ]); 40 | * $span->setStartTime(); 41 | * $span->setEndTime(); 42 | * ``` 43 | * @codingStandardsIgnoreStart 44 | * @see https://cloud.google.com/trace/docs/reference/v2/rest/v2/projects.traces/batchWrite#Span Span model documentation 45 | * @codingStandardsIgnoreEnd 46 | */ 47 | class Span 48 | { 49 | use AttributeTrait; 50 | use TimestampTrait; 51 | 52 | /** 53 | * @var string A unique identifier for a trace within a 54 | * project; it is a 32-character hexadecimal encoding of a 16-byte 55 | * array. 56 | */ 57 | private $traceId; 58 | 59 | /** 60 | * @var string The id portion of the span's resource name. 61 | */ 62 | private $spanId; 63 | 64 | /** 65 | * @var string The id of this span's parent span. If this is a root 66 | * span, then this field must be empty. 67 | */ 68 | private $parentSpanId; 69 | 70 | /** 71 | * @var string The displayable name of this span. 72 | */ 73 | private $name; 74 | 75 | /** 76 | * @var string The start time of the span. On the client side, 77 | * this is the time kept by the local machine where the span execution 78 | * starts. On the server side, this is the time when the server's 79 | * application handler starts running. 80 | */ 81 | private $startTime; 82 | 83 | /** 84 | * @var string The end time of the span. On the client side, 85 | * this is the time kept by the local machine where the span execution 86 | * ends. On the server side, this is the time when the server's 87 | * application handler stops running. 88 | */ 89 | private $endTime; 90 | 91 | /** 92 | * @var array Stack trace captured at the start of the span. 93 | */ 94 | private $stackTrace; 95 | 96 | /** 97 | * @var TimeEvent[] A set of time events. You can have up to 32 annotations 98 | * and 128 message events per span. 99 | */ 100 | private $timeEvents; 101 | 102 | /** 103 | * @var Link[] Links associated with the span. You can have up to 128 links 104 | * per Span. 105 | */ 106 | private $links; 107 | 108 | /** 109 | * @var Status An optional final status for this span. 110 | */ 111 | private $status; 112 | 113 | /** 114 | * @var bool A highly recommended but not required flag that identifies when 115 | * a trace crosses a process boundary. True when the parent_span 116 | * belongs to the same process as the current span. 117 | */ 118 | private $sameProcessAsParentSpan; 119 | 120 | /** 121 | * Instantiate a new Span instance. 122 | * 123 | * @param string $traceId A unique identifier for a trace within a 124 | * project; it is a 32-character hexadecimal encoding of a 16-byte 125 | * array. 126 | * @param array $options [optional] { 127 | * Configuration options. 128 | * 129 | * @type string $spanId The ID of the span. If not provided, 130 | * one will be generated automatically for you. 131 | * @type string $name The name of the span. 132 | * @type \DateTimeInterface|int|float|string $startTime Start time of the span in nanoseconds. 133 | * If provided as a string, it must be in "Zulu" format. If provided as an int or float, it is 134 | * expected to be a Unix timestamp. 135 | * @type \DateTimeInterface|int|float|string $endTime End time of the span in nanoseconds. 136 | * If provided as a string, it must be in "Zulu" format. If provided as an int or float, it is 137 | * expected to be a Unix timestamp. 138 | * @type string $parentSpanId ID of the parent span if any. 139 | * @type array $attributes Associative array of $label => $value 140 | * to attach to this span. 141 | * @type array $stackTrace Stack trace captured at the start of the span. 142 | * @type TimeEvent[] $timeEvents A set of time events. You can have up 143 | * to 32 annotations and 128 message events per span. 144 | * @type Link[] $links Links associated with the span. You can have up 145 | * to 128 links per Span. 146 | * @type Status $status An optional final status for this span. 147 | * @type bool $sameProcessAsParentSpan A highly recommended but not 148 | * required flag that identifies when a trace crosses a process 149 | * boundary. True when the parent_span belongs to the same 150 | * process as the current span. 151 | * } 152 | */ 153 | public function __construct($traceId, array $options = []) 154 | { 155 | $this->traceId = $traceId; 156 | $options += [ 157 | 'status' => null, 158 | 'attributes' => [], 159 | 'timeEvents' => [], 160 | 'links' => [] 161 | ]; 162 | 163 | $this->name = array_key_exists('name', $options) 164 | ? $options['name'] 165 | : $this->generateSpanName(); 166 | $this->setSpanId( 167 | array_key_exists('spanId', $options) 168 | ? $options['spanId'] 169 | : $this->generateSpanId() 170 | ); 171 | 172 | if (array_key_exists('parentSpanId', $options)) { 173 | $this->setParentSpanId($options['parentSpanId']); 174 | } 175 | 176 | if (array_key_exists('stackTrace', $options)) { 177 | $this->stackTrace = new StackTrace($options['stackTrace']); 178 | } 179 | 180 | if (array_key_exists('startTime', $options)) { 181 | $this->setStartTime($options['startTime']); 182 | } 183 | if (array_key_exists('endTime', $options)) { 184 | $this->setEndTime($options['endTime']); 185 | } 186 | 187 | $this->status = $options['status']; 188 | $this->addAttributes($options['attributes']); 189 | $this->addTimeEvents($options['timeEvents']); 190 | $this->addLinks($options['links']); 191 | 192 | if (array_key_exists('sameProcessAsParentSpan', $options)) { 193 | $this->sameProcessAsParentSpan = $options['sameProcessAsParentSpan']; 194 | } 195 | } 196 | 197 | /** 198 | * Set the start time for this span. 199 | * 200 | * Example: 201 | * ``` 202 | * // Set the start time to now 203 | * $span->setStartTime(); 204 | * ``` 205 | * 206 | * ``` 207 | * // Set the start time to a custom time 208 | * $span->setStartTime(new \DateTime('2017-11-29 11:51:23')); 209 | * ``` 210 | * 211 | * @param \DateTimeInterface|int|float|string $when [optional] The start time of this span. 212 | * **Defaults to** now. If provided as a string, it must be in "Zulu" format. 213 | * If provided as an int or float, it is expected to be a Unix timestamp. 214 | */ 215 | public function setStartTime($when = null) 216 | { 217 | $this->startTime = $this->formatDate($when); 218 | } 219 | 220 | /** 221 | * Returns a "Zulu" formatted string representing the start time for this span. 222 | * 223 | * Example: 224 | * ``` 225 | * echo $span->startTime(); 226 | * ``` 227 | * 228 | * @return string 229 | */ 230 | public function startTime() 231 | { 232 | return $this->startTime; 233 | } 234 | 235 | /** 236 | * Set the end time for this span. 237 | * 238 | * Example: 239 | * ``` 240 | * // Set the end time to now 241 | * $span->setEndTime(); 242 | * ``` 243 | * 244 | * ``` 245 | * // Set the end time to a custom time 246 | * $span->setEndTime(new \DateTime('2017-11-29 11:51:23')); 247 | * ``` 248 | * 249 | * @param \DateTimeInterface|int|float|string $when [optional] The end time of this span. 250 | * **Defaults to** now. If provided as a string, it must be in "Zulu" format. 251 | * If provided as an int or float, it is expected to be a Unix timestamp. 252 | */ 253 | public function setEndTime($when = null) 254 | { 255 | $this->endTime = $this->formatDate($when); 256 | } 257 | 258 | /** 259 | * Returns a "Zulu" formatted string representing the end time for this span. 260 | * 261 | * Example: 262 | * ``` 263 | * echo $span->endTime(); 264 | * ``` 265 | * 266 | * @return string 267 | */ 268 | public function endTime() 269 | { 270 | return $this->endTime; 271 | } 272 | 273 | /** 274 | * Set the ID of this span 275 | * 276 | * Example: 277 | * ``` 278 | * $span->setSpanId('1234abcd'); 279 | * ``` 280 | * 281 | * @param string $spanId 282 | */ 283 | public function setSpanId($spanId) 284 | { 285 | $this->spanId = str_pad($spanId, 16, '0', STR_PAD_LEFT); 286 | } 287 | 288 | /** 289 | * Set the ID of this span's parent 290 | * 291 | * Example: 292 | * ``` 293 | * $span->setParentSpanId('1234abcd'); 294 | * ``` 295 | * 296 | * @param string $spanId 297 | */ 298 | public function setParentSpanId($spanId) 299 | { 300 | $this->parentSpanId = str_pad($spanId, 16, '0', STR_PAD_LEFT); 301 | } 302 | 303 | /** 304 | * Retrieve the ID of this span. 305 | * 306 | * Example: 307 | * ``` 308 | * echo $span->spanId(); 309 | * ``` 310 | * 311 | * @return string 312 | */ 313 | public function spanId() 314 | { 315 | return $this->spanId; 316 | } 317 | 318 | /** 319 | * Retrieve the TraceID of this span 320 | * 321 | * Example: 322 | * ``` 323 | * echo $span->traceId(); 324 | * ``` 325 | * 326 | * @return string 327 | */ 328 | public function traceId() 329 | { 330 | return $this->traceId; 331 | } 332 | 333 | /** 334 | * Retrieve the ID of this span's parent if it exists. 335 | * 336 | * Example: 337 | * ``` 338 | * echo $span->parentSpanId(); 339 | * ``` 340 | * 341 | * @return string 342 | */ 343 | public function parentSpanId() 344 | { 345 | return $this->parentSpanId; 346 | } 347 | 348 | /** 349 | * Retrieve the name of this span. 350 | * 351 | * Example: 352 | * ``` 353 | * echo $span->name(); 354 | * ``` 355 | * 356 | * @return string 357 | */ 358 | public function name() 359 | { 360 | return $this->name; 361 | } 362 | 363 | /** 364 | * Returns the info array for serialization. 365 | * 366 | * @access private 367 | * @return array 368 | */ 369 | public function info() 370 | { 371 | $data = [ 372 | 'displayName' => [ 373 | 'value' => $this->name 374 | ], 375 | 'spanId' => $this->spanId, 376 | 'startTime' => $this->startTime, 377 | 'endTime' => $this->endTime 378 | ]; 379 | if ($this->parentSpanId) { 380 | $data['parentSpanId'] = $this->parentSpanId; 381 | } 382 | if ($this->attributes) { 383 | $data['attributes'] = $this->attributes->info(); 384 | } 385 | if ($this->timeEvents) { 386 | $data['timeEvents'] = [ 387 | 'timeEvent' => array_map(function ($timeEvent) { 388 | return $timeEvent->info(); 389 | }, $this->timeEvents) 390 | ]; 391 | } 392 | if ($this->links) { 393 | $data['links'] = [ 394 | 'link' => array_map(function ($link) { 395 | return $link->info(); 396 | }, $this->links) 397 | ]; 398 | } 399 | if ($this->status) { 400 | $data['status'] = $this->status->info(); 401 | } 402 | if ($this->stackTrace) { 403 | $data['stackTrace'] = $this->stackTrace->info(); 404 | } 405 | if ($this->sameProcessAsParentSpan !== null) { 406 | $data['sameProcessAsParentSpan'] = $this->sameProcessAsParentSpan; 407 | } 408 | return $data; 409 | } 410 | 411 | /** 412 | * Add multiple TimeEvent to this span. 413 | * 414 | * Example: 415 | * ``` 416 | * $annotation = new Annotation('some message'); 417 | * $messageEvent = new MessageEvent('message id'); 418 | * $span->addTimeEvents([ 419 | * $annotation, 420 | * $messageEvent 421 | * ]); 422 | * ``` 423 | * 424 | * @param TimeEvent[] $events 425 | */ 426 | public function addTimeEvents(array $events) 427 | { 428 | foreach ($events as $event) { 429 | $this->addTimeEvent($event); 430 | } 431 | } 432 | 433 | /** 434 | * Add a single TimeEvent to this span. 435 | * 436 | * Example: 437 | * ``` 438 | * $annotation = new Annotation('some message'); 439 | * $span->addTimeEvent($annotation); 440 | * ``` 441 | * 442 | * @param TimeEvent $event 443 | */ 444 | public function addTimeEvent(TimeEvent $event) 445 | { 446 | if (!$this->timeEvents) { 447 | $this->timeEvents = []; 448 | } 449 | $this->timeEvents[] = $event; 450 | } 451 | 452 | /** 453 | * Add multiple Links to this span. 454 | * 455 | * Example: 456 | * ``` 457 | * $link = new Link('abcd1234', 'abcd2345'); 458 | * $span->addLinks([$link]); 459 | * ``` 460 | * 461 | * @param Link[] $links 462 | */ 463 | public function addLinks(array $links) 464 | { 465 | foreach ($links as $link) { 466 | $this->addLink($link); 467 | } 468 | } 469 | 470 | /** 471 | * Add a single Link to this span. 472 | * 473 | * Example: 474 | * ``` 475 | * $link = new Link('abcd1234', 'abcd2345'); 476 | * $span->addLink($link); 477 | * ``` 478 | * 479 | * @param Link $link 480 | */ 481 | public function addLink(Link $link) 482 | { 483 | if (!$this->links) { 484 | $this->links = []; 485 | } 486 | $this->links[] = $link; 487 | } 488 | 489 | /** 490 | * Generate a random ID for this span. Must be unique per trace, 491 | * but does not need to be globally unique. 492 | * 493 | * @return string 494 | */ 495 | private function generateSpanId() 496 | { 497 | return dechex(mt_rand()); 498 | } 499 | 500 | /** 501 | * Generate a name for this span. Attempts to generate a name 502 | * based on the caller's code. 503 | * 504 | * @return string 505 | */ 506 | private function generateSpanName() 507 | { 508 | // Try to find the first stacktrace class entry that doesn't start with Google\Cloud\Trace 509 | foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $bt) { 510 | $bt += ['line' => null]; 511 | if (!array_key_exists('class', $bt)) { 512 | return implode('/', array_filter(['app', basename($bt['file']), $bt['function'], $bt['line']])); 513 | } elseif (substr($bt['class'], 0, 18) != 'Google\Cloud\Trace') { 514 | return implode('/', array_filter(['app', $bt['class'], $bt['function'], $bt['line']])); 515 | } 516 | } 517 | 518 | // We couldn't find a suitable backtrace entry - generate a random one 519 | return uniqid('span'); 520 | } 521 | } 522 | -------------------------------------------------------------------------------- /src/StackTrace.php: -------------------------------------------------------------------------------- 1 | backtrace = $backtrace; 48 | } 49 | 50 | /** 51 | * Returns a serializable array representing this StackTrace 52 | * 53 | * @access private 54 | * @return array 55 | */ 56 | public function info() 57 | { 58 | return [ 59 | 'stackFrames' => [ 60 | 'frame' => array_map([$this, 'mapStackFrame'], $this->backtrace) 61 | ] 62 | ]; 63 | } 64 | 65 | private function mapStackFrame($sf) 66 | { 67 | $data = []; 68 | if (isset($sf['line'])) { 69 | $data['lineNumber'] = $sf['line']; 70 | } 71 | if (isset($sf['file'])) { 72 | $data['fileName'] = [ 73 | 'value' => $sf['file'] 74 | ]; 75 | } 76 | if (isset($sf['function'])) { 77 | $data['functionName'] = [ 78 | 'value' => $sf['function'] 79 | ]; 80 | } 81 | return $data; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Status.php: -------------------------------------------------------------------------------- 1 | 1234, "@type" => "types.example.com/standard/id"]. 55 | */ 56 | private $details; 57 | 58 | /** 59 | * Create a new Status. 60 | * 61 | * @param int $code The status code, which should be an enum value of 62 | * google.rpc.Code. 63 | * @param string $message A developer-facing error message, which should be 64 | * in English. Any user-facing error message should be localized and 65 | * sent in the google.rpc.Status.details field, or localized by the 66 | * client. 67 | * @param array $options [optional] Configuration options. 68 | * @param array $options['details'] [optional] A list of messages that carry the error details. There is a 69 | * common set of message types for APIs to use. An object containing fields 70 | * of an arbitrary type. An additional field "@type" contains a URI 71 | * identifying the type. 72 | */ 73 | public function __construct($code, $message, array $options = []) 74 | { 75 | $options += [ 76 | 'details' => [] 77 | ]; 78 | $this->code = $code; 79 | $this->message = $message; 80 | $this->details = $options['details']; 81 | } 82 | 83 | /** 84 | * Returns a serializable array representing this Link. 85 | * 86 | * @access private 87 | * @return array 88 | */ 89 | public function info() 90 | { 91 | $data = [ 92 | 'code' => $this->code, 93 | 'message' => $this->message 94 | ]; 95 | if ($this->details) { 96 | $data['details'] = $this->details; 97 | } 98 | 99 | return $data; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/TimeEvent.php: -------------------------------------------------------------------------------- 1 | time = $this->formatDate($options['time']); 46 | } else { 47 | $this->time = $this->formatDate(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/TimestampTrait.php: -------------------------------------------------------------------------------- 1 | setTimezone(new \DateTimeZone('UTC')); 47 | return $when->format('Y-m-d\TH:i:s.u000\Z'); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Trace.php: -------------------------------------------------------------------------------- 1 | trace(); 34 | * ``` 35 | */ 36 | class Trace 37 | { 38 | use ValidateTrait; 39 | 40 | /** 41 | * @var Connection\ConnectionInterface Represents a connection to Stackdriver Trace. 42 | * @internal 43 | */ 44 | private $connection; 45 | 46 | /** 47 | * @var string The id of the project this trace belongs to. 48 | */ 49 | private $projectId; 50 | 51 | /** 52 | * @var string The trace id for this trace. 128-bit numeric formatted as a 32-byte hex string 53 | */ 54 | private $traceId; 55 | 56 | /** 57 | * @var Span[] List of Spans to report 58 | */ 59 | private $spans = []; 60 | 61 | /** 62 | * Instantiate a new Trace instance. 63 | * 64 | * @param string $projectId The id of the project this trace belongs to. 65 | * @param string $traceId [optional] The id of the trace. If not provided, one will be generated 66 | * automatically for you. 67 | * @param array $spans [optional] Array of Span constructor arguments. See 68 | * {@see \Google\Cloud\Trace\Span::__construct()} for configuration details. 69 | */ 70 | public function __construct($projectId, $traceId = null, array $spans = []) 71 | { 72 | $this->projectId = $projectId; 73 | $this->traceId = $traceId ?: $this->generateTraceId(); 74 | if ($spans) { 75 | $this->spans = array_map(function ($spanData) use ($traceId) { 76 | return new Span($traceId, $spanData); 77 | }, $spans); 78 | } 79 | } 80 | 81 | /** 82 | * Retrieves the trace's id. 83 | * 84 | * Example: 85 | * ``` 86 | * echo $trace->traceId(); 87 | * ``` 88 | * 89 | * @return string 90 | */ 91 | public function traceId() 92 | { 93 | return $this->traceId; 94 | } 95 | 96 | /** 97 | * Returns a serializable array representing this trace. 98 | * 99 | * @access private 100 | * @return array 101 | */ 102 | public function info() 103 | { 104 | return [ 105 | 'projectId' => $this->projectId, 106 | 'traceId' => $this->traceId, 107 | 'spans' => $this->spans 108 | ]; 109 | } 110 | 111 | /** 112 | * Retrieves the spans for this trace. 113 | * 114 | * Example: 115 | * ``` 116 | * $spans = $trace->spans(); 117 | * ``` 118 | * 119 | * @return Span[] 120 | */ 121 | public function spans() 122 | { 123 | return $this->spans; 124 | } 125 | 126 | /** 127 | * Create an instance of {@see \Google\Cloud\Trace\Span} 128 | * 129 | * Example: 130 | * ``` 131 | * $span = $trace->span(['name' => 'newSpan']); 132 | * ``` 133 | * 134 | * @param array $options [optional] See {@see \Google\Cloud\Trace\Span::__construct()} 135 | * for configuration details. 136 | * @return Span 137 | */ 138 | public function span(array $options = []) 139 | { 140 | return new Span($this->traceId, $options); 141 | } 142 | 143 | /** 144 | * Set the spans for this trace. 145 | * 146 | * Example: 147 | * ``` 148 | * $trace->setSpans([$span1, $span2]); 149 | * ``` 150 | * 151 | * @param Span[] $spans 152 | */ 153 | public function setSpans(array $spans) 154 | { 155 | $this->validateBatch($spans, Span::class); 156 | $this->spans = $spans; 157 | } 158 | 159 | /** 160 | * Generates a random trace id as a UUID without dashes. 161 | * 162 | * @return string 163 | */ 164 | private function generateTraceId() 165 | { 166 | return str_replace('-', '', Uuid::uuid4()->toString()); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/TraceClient.php: -------------------------------------------------------------------------------- 1 | clientConfig = $config; 95 | $connectionType = $this->getConnectionType($config); 96 | $config += [ 97 | 'scopes' => [self::FULL_CONTROL_SCOPE], 98 | 'projectIdRequired' => true 99 | ]; 100 | 101 | $this->connection = $connectionType === 'grpc' 102 | ? new Grpc($this->configureAuthentication($config)) 103 | : new Rest($this->configureAuthentication($config)); 104 | } 105 | 106 | /** 107 | * Sends a Trace log in a simple fashion. 108 | * 109 | * Example: 110 | * ``` 111 | * $trace = $traceClient->trace(); 112 | * $result = $traceClient->insert($trace); 113 | * ``` 114 | * 115 | * @codingStandardsIgnoreStart 116 | * @see https://cloud.google.com/trace/docs/reference/v1/rest/v1/projects/patchTraces Project patchTraces API documentation. 117 | * @codingStandardsIgnoreEnd 118 | * 119 | * @param Trace $trace The trace log to send. 120 | * @param array $options [optional] Configuration Options 121 | * @return bool 122 | */ 123 | public function insert(Trace $trace, array $options = []) 124 | { 125 | return $this->insertBatch([$trace], $options); 126 | } 127 | 128 | /** 129 | * Sends multiple Trace logs in a simple fashion. 130 | * 131 | * Example: 132 | * ``` 133 | * $trace = $traceClient->trace(); 134 | * $result = $traceClient->insertBatch([$trace]); 135 | * ``` 136 | * 137 | * @codingStandardsIgnoreStart 138 | * @see https://cloud.google.com/trace/docs/reference/v1/rest/v1/projects/patchTraces Project patchTraces API documentation. 139 | * @codingStandardsIgnoreEnd 140 | * 141 | * @param Trace[] $traces The trace logs to send. 142 | * @param array $options [optional] Configuration Options 143 | * @return bool 144 | */ 145 | public function insertBatch(array $traces, array $options = []) 146 | { 147 | $spans = []; 148 | foreach ($traces as $trace) { 149 | foreach ($trace->spans() as $span) { 150 | $spans[] = $this->transformSpan($span); 151 | } 152 | } 153 | // throws ServiceException on failure 154 | $this->connection->traceBatchWrite([ 155 | 'projectsId' => $this->projectId, 156 | 'spans' => $spans 157 | ] + $options); 158 | return true; 159 | } 160 | 161 | /** 162 | * Lazily find or instantiates a trace. There are no network requests made at this 163 | * point. To see the operations that can be performed on a trace please 164 | * see {@see \Google\Cloud\Trace\Trace}. If no traceId is provided, one will be 165 | * generated for you. 166 | * 167 | * Example: 168 | * ``` 169 | * // Create a trace with a generated traceId 170 | * $trace = $traceClient->trace(); 171 | * ``` 172 | * 173 | * ``` 174 | * // Create a trace with a specific traceId 175 | * $trace = $traceClient->trace('1234abcd'); 176 | * ``` 177 | * 178 | * @param string $traceId [optional] The trace id of the trace to reference. 179 | * @return Trace 180 | */ 181 | public function trace($traceId = null) 182 | { 183 | return new Trace($this->projectId, $traceId); 184 | } 185 | 186 | private function transformSpan(Span $span) 187 | { 188 | $data = $span->info(); 189 | $data['name'] = sprintf( 190 | 'projects/%s/traces/%s/spans/%s', 191 | $this->projectId, 192 | $span->traceId(), 193 | $span->spanId() 194 | ); 195 | return $data; 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /src/V2/AttributeValue.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.AttributeValue 15 | */ 16 | class AttributeValue extends \Google\Protobuf\Internal\Message 17 | { 18 | protected $value; 19 | 20 | /** 21 | * Constructor. 22 | * 23 | * @param array $data { 24 | * Optional. Data for populating the Message object. 25 | * 26 | * @type \Google\Cloud\Trace\V2\TruncatableString $string_value 27 | * A string up to 256 bytes long. 28 | * @type int|string $int_value 29 | * A 64-bit signed integer. 30 | * @type bool $bool_value 31 | * A Boolean value represented by `true` or `false`. 32 | * } 33 | */ 34 | public function __construct($data = NULL) { 35 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 36 | parent::__construct($data); 37 | } 38 | 39 | /** 40 | * A string up to 256 bytes long. 41 | * 42 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString string_value = 1; 43 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 44 | */ 45 | public function getStringValue() 46 | { 47 | return $this->readOneof(1); 48 | } 49 | 50 | public function hasStringValue() 51 | { 52 | return $this->hasOneof(1); 53 | } 54 | 55 | /** 56 | * A string up to 256 bytes long. 57 | * 58 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString string_value = 1; 59 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 60 | * @return $this 61 | */ 62 | public function setStringValue($var) 63 | { 64 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 65 | $this->writeOneof(1, $var); 66 | 67 | return $this; 68 | } 69 | 70 | /** 71 | * A 64-bit signed integer. 72 | * 73 | * Generated from protobuf field int64 int_value = 2; 74 | * @return int|string 75 | */ 76 | public function getIntValue() 77 | { 78 | return $this->readOneof(2); 79 | } 80 | 81 | public function hasIntValue() 82 | { 83 | return $this->hasOneof(2); 84 | } 85 | 86 | /** 87 | * A 64-bit signed integer. 88 | * 89 | * Generated from protobuf field int64 int_value = 2; 90 | * @param int|string $var 91 | * @return $this 92 | */ 93 | public function setIntValue($var) 94 | { 95 | GPBUtil::checkInt64($var); 96 | $this->writeOneof(2, $var); 97 | 98 | return $this; 99 | } 100 | 101 | /** 102 | * A Boolean value represented by `true` or `false`. 103 | * 104 | * Generated from protobuf field bool bool_value = 3; 105 | * @return bool 106 | */ 107 | public function getBoolValue() 108 | { 109 | return $this->readOneof(3); 110 | } 111 | 112 | public function hasBoolValue() 113 | { 114 | return $this->hasOneof(3); 115 | } 116 | 117 | /** 118 | * A Boolean value represented by `true` or `false`. 119 | * 120 | * Generated from protobuf field bool bool_value = 3; 121 | * @param bool $var 122 | * @return $this 123 | */ 124 | public function setBoolValue($var) 125 | { 126 | GPBUtil::checkBool($var); 127 | $this->writeOneof(3, $var); 128 | 129 | return $this; 130 | } 131 | 132 | /** 133 | * @return string 134 | */ 135 | public function getValue() 136 | { 137 | return $this->whichOneof("value"); 138 | } 139 | 140 | } 141 | 142 | -------------------------------------------------------------------------------- /src/V2/BatchWriteSpansRequest.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.BatchWriteSpansRequest 15 | */ 16 | class BatchWriteSpansRequest extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * Required. The name of the project where the spans belong. The format is 20 | * `projects/[PROJECT_ID]`. 21 | * 22 | * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { 23 | */ 24 | private $name = ''; 25 | /** 26 | * Required. A list of new spans. The span names must not match existing 27 | * spans, otherwise the results are undefined. 28 | * 29 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span spans = 2 [(.google.api.field_behavior) = REQUIRED]; 30 | */ 31 | private $spans; 32 | 33 | /** 34 | * @param string $name Required. The name of the project where the spans belong. The format is 35 | * `projects/[PROJECT_ID]`. Please see 36 | * {@see TraceServiceClient::projectName()} for help formatting this field. 37 | * @param \Google\Cloud\Trace\V2\Span[] $spans Required. A list of new spans. The span names must not match existing 38 | * spans, otherwise the results are undefined. 39 | * 40 | * @return \Google\Cloud\Trace\V2\BatchWriteSpansRequest 41 | * 42 | * @experimental 43 | */ 44 | public static function build(string $name, array $spans): self 45 | { 46 | return (new self()) 47 | ->setName($name) 48 | ->setSpans($spans); 49 | } 50 | 51 | /** 52 | * Constructor. 53 | * 54 | * @param array $data { 55 | * Optional. Data for populating the Message object. 56 | * 57 | * @type string $name 58 | * Required. The name of the project where the spans belong. The format is 59 | * `projects/[PROJECT_ID]`. 60 | * @type array<\Google\Cloud\Trace\V2\Span>|\Google\Protobuf\Internal\RepeatedField $spans 61 | * Required. A list of new spans. The span names must not match existing 62 | * spans, otherwise the results are undefined. 63 | * } 64 | */ 65 | public function __construct($data = NULL) { 66 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Tracing::initOnce(); 67 | parent::__construct($data); 68 | } 69 | 70 | /** 71 | * Required. The name of the project where the spans belong. The format is 72 | * `projects/[PROJECT_ID]`. 73 | * 74 | * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { 75 | * @return string 76 | */ 77 | public function getName() 78 | { 79 | return $this->name; 80 | } 81 | 82 | /** 83 | * Required. The name of the project where the spans belong. The format is 84 | * `projects/[PROJECT_ID]`. 85 | * 86 | * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { 87 | * @param string $var 88 | * @return $this 89 | */ 90 | public function setName($var) 91 | { 92 | GPBUtil::checkString($var, True); 93 | $this->name = $var; 94 | 95 | return $this; 96 | } 97 | 98 | /** 99 | * Required. A list of new spans. The span names must not match existing 100 | * spans, otherwise the results are undefined. 101 | * 102 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span spans = 2 [(.google.api.field_behavior) = REQUIRED]; 103 | * @return \Google\Protobuf\Internal\RepeatedField 104 | */ 105 | public function getSpans() 106 | { 107 | return $this->spans; 108 | } 109 | 110 | /** 111 | * Required. A list of new spans. The span names must not match existing 112 | * spans, otherwise the results are undefined. 113 | * 114 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span spans = 2 [(.google.api.field_behavior) = REQUIRED]; 115 | * @param array<\Google\Cloud\Trace\V2\Span>|\Google\Protobuf\Internal\RepeatedField $var 116 | * @return $this 117 | */ 118 | public function setSpans($var) 119 | { 120 | $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Trace\V2\Span::class); 121 | $this->spans = $arr; 122 | 123 | return $this; 124 | } 125 | 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/V2/Client/TraceServiceClient.php: -------------------------------------------------------------------------------- 1 | batchWriteSpansAsync(BatchWriteSpansRequest $request, array $optionalArgs = []) 58 | * @method PromiseInterface createSpanAsync(Span $request, array $optionalArgs = []) 59 | */ 60 | final class TraceServiceClient 61 | { 62 | use GapicClientTrait; 63 | use ResourceHelperTrait; 64 | 65 | /** The name of the service. */ 66 | private const SERVICE_NAME = 'google.devtools.cloudtrace.v2.TraceService'; 67 | 68 | /** 69 | * The default address of the service. 70 | * 71 | * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. 72 | */ 73 | private const SERVICE_ADDRESS = 'cloudtrace.googleapis.com'; 74 | 75 | /** The address template of the service. */ 76 | private const SERVICE_ADDRESS_TEMPLATE = 'cloudtrace.UNIVERSE_DOMAIN'; 77 | 78 | /** The default port of the service. */ 79 | private const DEFAULT_SERVICE_PORT = 443; 80 | 81 | /** The name of the code generator, to be included in the agent header. */ 82 | private const CODEGEN_NAME = 'gapic'; 83 | 84 | /** The default scopes required by the service. */ 85 | public static $serviceScopes = [ 86 | 'https://www.googleapis.com/auth/cloud-platform', 87 | 'https://www.googleapis.com/auth/trace.append', 88 | ]; 89 | 90 | private static function getClientDefaults() 91 | { 92 | return [ 93 | 'serviceName' => self::SERVICE_NAME, 94 | 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, 95 | 'clientConfig' => __DIR__ . '/../resources/trace_service_client_config.json', 96 | 'descriptorsConfigPath' => __DIR__ . '/../resources/trace_service_descriptor_config.php', 97 | 'gcpApiConfigPath' => __DIR__ . '/../resources/trace_service_grpc_config.json', 98 | 'credentialsConfig' => [ 99 | 'defaultScopes' => self::$serviceScopes, 100 | ], 101 | 'transportConfig' => [ 102 | 'rest' => [ 103 | 'restClientConfigPath' => __DIR__ . '/../resources/trace_service_rest_client_config.php', 104 | ], 105 | ], 106 | ]; 107 | } 108 | 109 | /** 110 | * Formats a string containing the fully-qualified path to represent a project 111 | * resource. 112 | * 113 | * @param string $project 114 | * 115 | * @return string The formatted project resource. 116 | */ 117 | public static function projectName(string $project): string 118 | { 119 | return self::getPathTemplate('project')->render([ 120 | 'project' => $project, 121 | ]); 122 | } 123 | 124 | /** 125 | * Formats a string containing the fully-qualified path to represent a span 126 | * resource. 127 | * 128 | * @param string $project 129 | * @param string $trace 130 | * @param string $span 131 | * 132 | * @return string The formatted span resource. 133 | */ 134 | public static function spanName(string $project, string $trace, string $span): string 135 | { 136 | return self::getPathTemplate('span')->render([ 137 | 'project' => $project, 138 | 'trace' => $trace, 139 | 'span' => $span, 140 | ]); 141 | } 142 | 143 | /** 144 | * Parses a formatted name string and returns an associative array of the components in the name. 145 | * The following name formats are supported: 146 | * Template: Pattern 147 | * - project: projects/{project} 148 | * - span: projects/{project}/traces/{trace}/spans/{span} 149 | * 150 | * The optional $template argument can be supplied to specify a particular pattern, 151 | * and must match one of the templates listed above. If no $template argument is 152 | * provided, or if the $template argument does not match one of the templates 153 | * listed, then parseName will check each of the supported templates, and return 154 | * the first match. 155 | * 156 | * @param string $formattedName The formatted name string 157 | * @param ?string $template Optional name of template to match 158 | * 159 | * @return array An associative array from name component IDs to component values. 160 | * 161 | * @throws ValidationException If $formattedName could not be matched. 162 | */ 163 | public static function parseName(string $formattedName, ?string $template = null): array 164 | { 165 | return self::parseFormattedName($formattedName, $template); 166 | } 167 | 168 | /** 169 | * Constructor. 170 | * 171 | * @param array $options { 172 | * Optional. Options for configuring the service API wrapper. 173 | * 174 | * @type string $apiEndpoint 175 | * The address of the API remote host. May optionally include the port, formatted 176 | * as ":". Default 'cloudtrace.googleapis.com:443'. 177 | * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials 178 | * The credentials to be used by the client to authorize API calls. This option 179 | * accepts either a path to a credentials file, or a decoded credentials file as a 180 | * PHP array. 181 | * *Advanced usage*: In addition, this option can also accept a pre-constructed 182 | * {@see \Google\Auth\FetchAuthTokenInterface} object or 183 | * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these 184 | * objects are provided, any settings in $credentialsConfig will be ignored. 185 | * *Important*: If you accept a credential configuration (credential 186 | * JSON/File/Stream) from an external source for authentication to Google Cloud 187 | * Platform, you must validate it before providing it to any Google API or library. 188 | * Providing an unvalidated credential configuration to Google APIs can compromise 189 | * the security of your systems and data. For more information {@see 190 | * https://cloud.google.com/docs/authentication/external/externally-sourced-credentials} 191 | * @type array $credentialsConfig 192 | * Options used to configure credentials, including auth token caching, for the 193 | * client. For a full list of supporting configuration options, see 194 | * {@see \Google\ApiCore\CredentialsWrapper::build()} . 195 | * @type bool $disableRetries 196 | * Determines whether or not retries defined by the client configuration should be 197 | * disabled. Defaults to `false`. 198 | * @type string|array $clientConfig 199 | * Client method configuration, including retry settings. This option can be either 200 | * a path to a JSON file, or a PHP array containing the decoded JSON data. By 201 | * default this settings points to the default client config file, which is 202 | * provided in the resources folder. 203 | * @type string|TransportInterface $transport 204 | * The transport used for executing network requests. May be either the string 205 | * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. 206 | * *Advanced usage*: Additionally, it is possible to pass in an already 207 | * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note 208 | * that when this object is provided, any settings in $transportConfig, and any 209 | * $apiEndpoint setting, will be ignored. 210 | * @type array $transportConfig 211 | * Configuration options that will be used to construct the transport. Options for 212 | * each supported transport type should be passed in a key for that transport. For 213 | * example: 214 | * $transportConfig = [ 215 | * 'grpc' => [...], 216 | * 'rest' => [...], 217 | * ]; 218 | * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and 219 | * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the 220 | * supported options. 221 | * @type callable $clientCertSource 222 | * A callable which returns the client cert as a string. This can be used to 223 | * provide a certificate and private key to the transport layer for mTLS. 224 | * @type false|LoggerInterface $logger 225 | * A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 226 | * 'GOOGLE_SDK_PHP_LOGGING' environment flag 227 | * } 228 | * 229 | * @throws ValidationException 230 | */ 231 | public function __construct(array $options = []) 232 | { 233 | $clientOptions = $this->buildClientOptions($options); 234 | $this->setClientOptions($clientOptions); 235 | } 236 | 237 | /** Handles execution of the async variants for each documented method. */ 238 | public function __call($method, $args) 239 | { 240 | if (substr($method, -5) !== 'Async') { 241 | trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); 242 | } 243 | 244 | array_unshift($args, substr($method, 0, -5)); 245 | return call_user_func_array([$this, 'startAsyncCall'], $args); 246 | } 247 | 248 | /** 249 | * Batch writes new spans to new or existing traces. You cannot update 250 | * existing spans. 251 | * 252 | * The async variant is {@see TraceServiceClient::batchWriteSpansAsync()} . 253 | * 254 | * @example samples/V2/TraceServiceClient/batch_write_spans.php 255 | * 256 | * @param BatchWriteSpansRequest $request A request to house fields associated with the call. 257 | * @param array $callOptions { 258 | * Optional. 259 | * 260 | * @type RetrySettings|array $retrySettings 261 | * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an 262 | * associative array of retry settings parameters. See the documentation on 263 | * {@see RetrySettings} for example usage. 264 | * } 265 | * 266 | * @throws ApiException Thrown if the API call fails. 267 | */ 268 | public function batchWriteSpans(BatchWriteSpansRequest $request, array $callOptions = []): void 269 | { 270 | $this->startApiCall('BatchWriteSpans', $request, $callOptions)->wait(); 271 | } 272 | 273 | /** 274 | * Creates a new span. 275 | * 276 | * The async variant is {@see TraceServiceClient::createSpanAsync()} . 277 | * 278 | * @example samples/V2/TraceServiceClient/create_span.php 279 | * 280 | * @param Span $request A request to house fields associated with the call. 281 | * @param array $callOptions { 282 | * Optional. 283 | * 284 | * @type RetrySettings|array $retrySettings 285 | * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an 286 | * associative array of retry settings parameters. See the documentation on 287 | * {@see RetrySettings} for example usage. 288 | * } 289 | * 290 | * @return Span 291 | * 292 | * @throws ApiException Thrown if the API call fails. 293 | */ 294 | public function createSpan(Span $request, array $callOptions = []): Span 295 | { 296 | return $this->startApiCall('CreateSpan', $request, $callOptions)->wait(); 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /src/V2/Module.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Module 15 | */ 16 | class Module extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * For example: main binary, kernel modules, and dynamic libraries 20 | * such as libc.so, sharedlib.so (up to 256 bytes). 21 | * 22 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString module = 1; 23 | */ 24 | private $module = null; 25 | /** 26 | * A unique identifier for the module, usually a hash of its 27 | * contents (up to 128 bytes). 28 | * 29 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString build_id = 2; 30 | */ 31 | private $build_id = null; 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param array $data { 37 | * Optional. Data for populating the Message object. 38 | * 39 | * @type \Google\Cloud\Trace\V2\TruncatableString $module 40 | * For example: main binary, kernel modules, and dynamic libraries 41 | * such as libc.so, sharedlib.so (up to 256 bytes). 42 | * @type \Google\Cloud\Trace\V2\TruncatableString $build_id 43 | * A unique identifier for the module, usually a hash of its 44 | * contents (up to 128 bytes). 45 | * } 46 | */ 47 | public function __construct($data = NULL) { 48 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 49 | parent::__construct($data); 50 | } 51 | 52 | /** 53 | * For example: main binary, kernel modules, and dynamic libraries 54 | * such as libc.so, sharedlib.so (up to 256 bytes). 55 | * 56 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString module = 1; 57 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 58 | */ 59 | public function getModule() 60 | { 61 | return $this->module; 62 | } 63 | 64 | public function hasModule() 65 | { 66 | return isset($this->module); 67 | } 68 | 69 | public function clearModule() 70 | { 71 | unset($this->module); 72 | } 73 | 74 | /** 75 | * For example: main binary, kernel modules, and dynamic libraries 76 | * such as libc.so, sharedlib.so (up to 256 bytes). 77 | * 78 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString module = 1; 79 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 80 | * @return $this 81 | */ 82 | public function setModule($var) 83 | { 84 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 85 | $this->module = $var; 86 | 87 | return $this; 88 | } 89 | 90 | /** 91 | * A unique identifier for the module, usually a hash of its 92 | * contents (up to 128 bytes). 93 | * 94 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString build_id = 2; 95 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 96 | */ 97 | public function getBuildId() 98 | { 99 | return $this->build_id; 100 | } 101 | 102 | public function hasBuildId() 103 | { 104 | return isset($this->build_id); 105 | } 106 | 107 | public function clearBuildId() 108 | { 109 | unset($this->build_id); 110 | } 111 | 112 | /** 113 | * A unique identifier for the module, usually a hash of its 114 | * contents (up to 128 bytes). 115 | * 116 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString build_id = 2; 117 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 118 | * @return $this 119 | */ 120 | public function setBuildId($var) 121 | { 122 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 123 | $this->build_id = $var; 124 | 125 | return $this; 126 | } 127 | 128 | } 129 | 130 | -------------------------------------------------------------------------------- /src/V2/README.md: -------------------------------------------------------------------------------- 1 | # Stackdriver Trace V2 generated client for PHP 2 | 3 | ### Sample 4 | 5 | ```php 6 | require 'vendor/autoload.php'; 7 | 8 | use Google\Cloud\Trace\V2\TraceServiceClient; 9 | 10 | $traceServiceClient = new TraceServiceClient(); 11 | try { 12 | $formattedName = $traceServiceClient->projectName('[PROJECT]'); 13 | $spans = []; 14 | $traceServiceClient->batchWriteSpans($formattedName, $spans); 15 | } finally { 16 | $traceServiceClient->close(); 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /src/V2/Span/Attributes.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.Attributes 15 | */ 16 | class Attributes extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * A set of attributes. Each attribute's key can be up to 128 bytes 20 | * long. The value can be a string up to 256 bytes, a signed 64-bit integer, 21 | * or the boolean values `true` or `false`. For example: 22 | * "/instance_id": { "string_value": { "value": "my-instance" } } 23 | * "/http/request_bytes": { "int_value": 300 } 24 | * "abc.com/myattribute": { "bool_value": false } 25 | * 26 | * Generated from protobuf field map attribute_map = 1; 27 | */ 28 | private $attribute_map; 29 | /** 30 | * The number of attributes that were discarded. Attributes can be discarded 31 | * because their keys are too long or because there are too many attributes. 32 | * If this value is 0 then all attributes are valid. 33 | * 34 | * Generated from protobuf field int32 dropped_attributes_count = 2; 35 | */ 36 | private $dropped_attributes_count = 0; 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param array $data { 42 | * Optional. Data for populating the Message object. 43 | * 44 | * @type array|\Google\Protobuf\Internal\MapField $attribute_map 45 | * A set of attributes. Each attribute's key can be up to 128 bytes 46 | * long. The value can be a string up to 256 bytes, a signed 64-bit integer, 47 | * or the boolean values `true` or `false`. For example: 48 | * "/instance_id": { "string_value": { "value": "my-instance" } } 49 | * "/http/request_bytes": { "int_value": 300 } 50 | * "abc.com/myattribute": { "bool_value": false } 51 | * @type int $dropped_attributes_count 52 | * The number of attributes that were discarded. Attributes can be discarded 53 | * because their keys are too long or because there are too many attributes. 54 | * If this value is 0 then all attributes are valid. 55 | * } 56 | */ 57 | public function __construct($data = NULL) { 58 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 59 | parent::__construct($data); 60 | } 61 | 62 | /** 63 | * A set of attributes. Each attribute's key can be up to 128 bytes 64 | * long. The value can be a string up to 256 bytes, a signed 64-bit integer, 65 | * or the boolean values `true` or `false`. For example: 66 | * "/instance_id": { "string_value": { "value": "my-instance" } } 67 | * "/http/request_bytes": { "int_value": 300 } 68 | * "abc.com/myattribute": { "bool_value": false } 69 | * 70 | * Generated from protobuf field map attribute_map = 1; 71 | * @return \Google\Protobuf\Internal\MapField 72 | */ 73 | public function getAttributeMap() 74 | { 75 | return $this->attribute_map; 76 | } 77 | 78 | /** 79 | * A set of attributes. Each attribute's key can be up to 128 bytes 80 | * long. The value can be a string up to 256 bytes, a signed 64-bit integer, 81 | * or the boolean values `true` or `false`. For example: 82 | * "/instance_id": { "string_value": { "value": "my-instance" } } 83 | * "/http/request_bytes": { "int_value": 300 } 84 | * "abc.com/myattribute": { "bool_value": false } 85 | * 86 | * Generated from protobuf field map attribute_map = 1; 87 | * @param array|\Google\Protobuf\Internal\MapField $var 88 | * @return $this 89 | */ 90 | public function setAttributeMap($var) 91 | { 92 | $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Trace\V2\AttributeValue::class); 93 | $this->attribute_map = $arr; 94 | 95 | return $this; 96 | } 97 | 98 | /** 99 | * The number of attributes that were discarded. Attributes can be discarded 100 | * because their keys are too long or because there are too many attributes. 101 | * If this value is 0 then all attributes are valid. 102 | * 103 | * Generated from protobuf field int32 dropped_attributes_count = 2; 104 | * @return int 105 | */ 106 | public function getDroppedAttributesCount() 107 | { 108 | return $this->dropped_attributes_count; 109 | } 110 | 111 | /** 112 | * The number of attributes that were discarded. Attributes can be discarded 113 | * because their keys are too long or because there are too many attributes. 114 | * If this value is 0 then all attributes are valid. 115 | * 116 | * Generated from protobuf field int32 dropped_attributes_count = 2; 117 | * @param int $var 118 | * @return $this 119 | */ 120 | public function setDroppedAttributesCount($var) 121 | { 122 | GPBUtil::checkInt32($var); 123 | $this->dropped_attributes_count = $var; 124 | 125 | return $this; 126 | } 127 | 128 | } 129 | 130 | // Adding a class alias for backwards compatibility with the previous class name. 131 | class_alias(Attributes::class, \Google\Cloud\Trace\V2\Span_Attributes::class); 132 | 133 | -------------------------------------------------------------------------------- /src/V2/Span/Link.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.Link 18 | */ 19 | class Link extends \Google\Protobuf\Internal\Message 20 | { 21 | /** 22 | * The `[TRACE_ID]` for a trace within a project. 23 | * 24 | * Generated from protobuf field string trace_id = 1; 25 | */ 26 | private $trace_id = ''; 27 | /** 28 | * The `[SPAN_ID]` for a span within a trace. 29 | * 30 | * Generated from protobuf field string span_id = 2; 31 | */ 32 | private $span_id = ''; 33 | /** 34 | * The relationship of the current span relative to the linked span. 35 | * 36 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Link.Type type = 3; 37 | */ 38 | private $type = 0; 39 | /** 40 | * A set of attributes on the link. Up to 32 attributes can be 41 | * specified per link. 42 | * 43 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Attributes attributes = 4; 44 | */ 45 | private $attributes = null; 46 | 47 | /** 48 | * Constructor. 49 | * 50 | * @param array $data { 51 | * Optional. Data for populating the Message object. 52 | * 53 | * @type string $trace_id 54 | * The `[TRACE_ID]` for a trace within a project. 55 | * @type string $span_id 56 | * The `[SPAN_ID]` for a span within a trace. 57 | * @type int $type 58 | * The relationship of the current span relative to the linked span. 59 | * @type \Google\Cloud\Trace\V2\Span\Attributes $attributes 60 | * A set of attributes on the link. Up to 32 attributes can be 61 | * specified per link. 62 | * } 63 | */ 64 | public function __construct($data = NULL) { 65 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 66 | parent::__construct($data); 67 | } 68 | 69 | /** 70 | * The `[TRACE_ID]` for a trace within a project. 71 | * 72 | * Generated from protobuf field string trace_id = 1; 73 | * @return string 74 | */ 75 | public function getTraceId() 76 | { 77 | return $this->trace_id; 78 | } 79 | 80 | /** 81 | * The `[TRACE_ID]` for a trace within a project. 82 | * 83 | * Generated from protobuf field string trace_id = 1; 84 | * @param string $var 85 | * @return $this 86 | */ 87 | public function setTraceId($var) 88 | { 89 | GPBUtil::checkString($var, True); 90 | $this->trace_id = $var; 91 | 92 | return $this; 93 | } 94 | 95 | /** 96 | * The `[SPAN_ID]` for a span within a trace. 97 | * 98 | * Generated from protobuf field string span_id = 2; 99 | * @return string 100 | */ 101 | public function getSpanId() 102 | { 103 | return $this->span_id; 104 | } 105 | 106 | /** 107 | * The `[SPAN_ID]` for a span within a trace. 108 | * 109 | * Generated from protobuf field string span_id = 2; 110 | * @param string $var 111 | * @return $this 112 | */ 113 | public function setSpanId($var) 114 | { 115 | GPBUtil::checkString($var, True); 116 | $this->span_id = $var; 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * The relationship of the current span relative to the linked span. 123 | * 124 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Link.Type type = 3; 125 | * @return int 126 | */ 127 | public function getType() 128 | { 129 | return $this->type; 130 | } 131 | 132 | /** 133 | * The relationship of the current span relative to the linked span. 134 | * 135 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Link.Type type = 3; 136 | * @param int $var 137 | * @return $this 138 | */ 139 | public function setType($var) 140 | { 141 | GPBUtil::checkEnum($var, \Google\Cloud\Trace\V2\Span\Link\Type::class); 142 | $this->type = $var; 143 | 144 | return $this; 145 | } 146 | 147 | /** 148 | * A set of attributes on the link. Up to 32 attributes can be 149 | * specified per link. 150 | * 151 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Attributes attributes = 4; 152 | * @return \Google\Cloud\Trace\V2\Span\Attributes|null 153 | */ 154 | public function getAttributes() 155 | { 156 | return $this->attributes; 157 | } 158 | 159 | public function hasAttributes() 160 | { 161 | return isset($this->attributes); 162 | } 163 | 164 | public function clearAttributes() 165 | { 166 | unset($this->attributes); 167 | } 168 | 169 | /** 170 | * A set of attributes on the link. Up to 32 attributes can be 171 | * specified per link. 172 | * 173 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Attributes attributes = 4; 174 | * @param \Google\Cloud\Trace\V2\Span\Attributes $var 175 | * @return $this 176 | */ 177 | public function setAttributes($var) 178 | { 179 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\Span\Attributes::class); 180 | $this->attributes = $var; 181 | 182 | return $this; 183 | } 184 | 185 | } 186 | 187 | // Adding a class alias for backwards compatibility with the previous class name. 188 | class_alias(Link::class, \Google\Cloud\Trace\V2\Span_Link::class); 189 | 190 | -------------------------------------------------------------------------------- /src/V2/Span/Link/Type.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.Link.Type 14 | */ 15 | class Type 16 | { 17 | /** 18 | * The relationship of the two spans is unknown. 19 | * 20 | * Generated from protobuf enum TYPE_UNSPECIFIED = 0; 21 | */ 22 | const TYPE_UNSPECIFIED = 0; 23 | /** 24 | * The linked span is a child of the current span. 25 | * 26 | * Generated from protobuf enum CHILD_LINKED_SPAN = 1; 27 | */ 28 | const CHILD_LINKED_SPAN = 1; 29 | /** 30 | * The linked span is a parent of the current span. 31 | * 32 | * Generated from protobuf enum PARENT_LINKED_SPAN = 2; 33 | */ 34 | const PARENT_LINKED_SPAN = 2; 35 | 36 | private static $valueToName = [ 37 | self::TYPE_UNSPECIFIED => 'TYPE_UNSPECIFIED', 38 | self::CHILD_LINKED_SPAN => 'CHILD_LINKED_SPAN', 39 | self::PARENT_LINKED_SPAN => 'PARENT_LINKED_SPAN', 40 | ]; 41 | 42 | public static function name($value) 43 | { 44 | if (!isset(self::$valueToName[$value])) { 45 | throw new UnexpectedValueException(sprintf( 46 | 'Enum %s has no name defined for value %s', __CLASS__, $value)); 47 | } 48 | return self::$valueToName[$value]; 49 | } 50 | 51 | 52 | public static function value($name) 53 | { 54 | $const = __CLASS__ . '::' . strtoupper($name); 55 | if (!defined($const)) { 56 | throw new UnexpectedValueException(sprintf( 57 | 'Enum %s has no value defined for name %s', __CLASS__, $name)); 58 | } 59 | return constant($const); 60 | } 61 | } 62 | 63 | // Adding a class alias for backwards compatibility with the previous class name. 64 | class_alias(Type::class, \Google\Cloud\Trace\V2\Span_Link_Type::class); 65 | 66 | -------------------------------------------------------------------------------- /src/V2/Span/Links.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.Links 16 | */ 17 | class Links extends \Google\Protobuf\Internal\Message 18 | { 19 | /** 20 | * A collection of links. 21 | * 22 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span.Link link = 1; 23 | */ 24 | private $link; 25 | /** 26 | * The number of dropped links after the maximum size was enforced. If 27 | * this value is 0, then no links were dropped. 28 | * 29 | * Generated from protobuf field int32 dropped_links_count = 2; 30 | */ 31 | private $dropped_links_count = 0; 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param array $data { 37 | * Optional. Data for populating the Message object. 38 | * 39 | * @type array<\Google\Cloud\Trace\V2\Span\Link>|\Google\Protobuf\Internal\RepeatedField $link 40 | * A collection of links. 41 | * @type int $dropped_links_count 42 | * The number of dropped links after the maximum size was enforced. If 43 | * this value is 0, then no links were dropped. 44 | * } 45 | */ 46 | public function __construct($data = NULL) { 47 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 48 | parent::__construct($data); 49 | } 50 | 51 | /** 52 | * A collection of links. 53 | * 54 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span.Link link = 1; 55 | * @return \Google\Protobuf\Internal\RepeatedField 56 | */ 57 | public function getLink() 58 | { 59 | return $this->link; 60 | } 61 | 62 | /** 63 | * A collection of links. 64 | * 65 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span.Link link = 1; 66 | * @param array<\Google\Cloud\Trace\V2\Span\Link>|\Google\Protobuf\Internal\RepeatedField $var 67 | * @return $this 68 | */ 69 | public function setLink($var) 70 | { 71 | $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Trace\V2\Span\Link::class); 72 | $this->link = $arr; 73 | 74 | return $this; 75 | } 76 | 77 | /** 78 | * The number of dropped links after the maximum size was enforced. If 79 | * this value is 0, then no links were dropped. 80 | * 81 | * Generated from protobuf field int32 dropped_links_count = 2; 82 | * @return int 83 | */ 84 | public function getDroppedLinksCount() 85 | { 86 | return $this->dropped_links_count; 87 | } 88 | 89 | /** 90 | * The number of dropped links after the maximum size was enforced. If 91 | * this value is 0, then no links were dropped. 92 | * 93 | * Generated from protobuf field int32 dropped_links_count = 2; 94 | * @param int $var 95 | * @return $this 96 | */ 97 | public function setDroppedLinksCount($var) 98 | { 99 | GPBUtil::checkInt32($var); 100 | $this->dropped_links_count = $var; 101 | 102 | return $this; 103 | } 104 | 105 | } 106 | 107 | // Adding a class alias for backwards compatibility with the previous class name. 108 | class_alias(Links::class, \Google\Cloud\Trace\V2\Span_Links::class); 109 | 110 | -------------------------------------------------------------------------------- /src/V2/Span/SpanKind.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.SpanKind 14 | */ 15 | class SpanKind 16 | { 17 | /** 18 | * Unspecified. Do NOT use as default. 19 | * Implementations MAY assume SpanKind.INTERNAL to be default. 20 | * 21 | * Generated from protobuf enum SPAN_KIND_UNSPECIFIED = 0; 22 | */ 23 | const SPAN_KIND_UNSPECIFIED = 0; 24 | /** 25 | * Indicates that the span is used internally. Default value. 26 | * 27 | * Generated from protobuf enum INTERNAL = 1; 28 | */ 29 | const INTERNAL = 1; 30 | /** 31 | * Indicates that the span covers server-side handling of an RPC or other 32 | * remote network request. 33 | * 34 | * Generated from protobuf enum SERVER = 2; 35 | */ 36 | const SERVER = 2; 37 | /** 38 | * Indicates that the span covers the client-side wrapper around an RPC or 39 | * other remote request. 40 | * 41 | * Generated from protobuf enum CLIENT = 3; 42 | */ 43 | const CLIENT = 3; 44 | /** 45 | * Indicates that the span describes producer sending a message to a broker. 46 | * Unlike client and server, there is no direct critical path latency 47 | * relationship between producer and consumer spans (e.g. publishing a 48 | * message to a pubsub service). 49 | * 50 | * Generated from protobuf enum PRODUCER = 4; 51 | */ 52 | const PRODUCER = 4; 53 | /** 54 | * Indicates that the span describes consumer receiving a message from a 55 | * broker. Unlike client and server, there is no direct critical path 56 | * latency relationship between producer and consumer spans (e.g. receiving 57 | * a message from a pubsub service subscription). 58 | * 59 | * Generated from protobuf enum CONSUMER = 5; 60 | */ 61 | const CONSUMER = 5; 62 | 63 | private static $valueToName = [ 64 | self::SPAN_KIND_UNSPECIFIED => 'SPAN_KIND_UNSPECIFIED', 65 | self::INTERNAL => 'INTERNAL', 66 | self::SERVER => 'SERVER', 67 | self::CLIENT => 'CLIENT', 68 | self::PRODUCER => 'PRODUCER', 69 | self::CONSUMER => 'CONSUMER', 70 | ]; 71 | 72 | public static function name($value) 73 | { 74 | if (!isset(self::$valueToName[$value])) { 75 | throw new UnexpectedValueException(sprintf( 76 | 'Enum %s has no name defined for value %s', __CLASS__, $value)); 77 | } 78 | return self::$valueToName[$value]; 79 | } 80 | 81 | 82 | public static function value($name) 83 | { 84 | $const = __CLASS__ . '::' . strtoupper($name); 85 | if (!defined($const)) { 86 | throw new UnexpectedValueException(sprintf( 87 | 'Enum %s has no value defined for name %s', __CLASS__, $name)); 88 | } 89 | return constant($const); 90 | } 91 | } 92 | 93 | // Adding a class alias for backwards compatibility with the previous class name. 94 | class_alias(SpanKind::class, \Google\Cloud\Trace\V2\Span_SpanKind::class); 95 | 96 | -------------------------------------------------------------------------------- /src/V2/Span/TimeEvent.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.TimeEvent 15 | */ 16 | class TimeEvent extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * The timestamp indicating the time the event occurred. 20 | * 21 | * Generated from protobuf field .google.protobuf.Timestamp time = 1; 22 | */ 23 | private $time = null; 24 | protected $value; 25 | 26 | /** 27 | * Constructor. 28 | * 29 | * @param array $data { 30 | * Optional. Data for populating the Message object. 31 | * 32 | * @type \Google\Protobuf\Timestamp $time 33 | * The timestamp indicating the time the event occurred. 34 | * @type \Google\Cloud\Trace\V2\Span\TimeEvent\Annotation $annotation 35 | * Text annotation with a set of attributes. 36 | * @type \Google\Cloud\Trace\V2\Span\TimeEvent\MessageEvent $message_event 37 | * An event describing a message sent/received between Spans. 38 | * } 39 | */ 40 | public function __construct($data = NULL) { 41 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 42 | parent::__construct($data); 43 | } 44 | 45 | /** 46 | * The timestamp indicating the time the event occurred. 47 | * 48 | * Generated from protobuf field .google.protobuf.Timestamp time = 1; 49 | * @return \Google\Protobuf\Timestamp|null 50 | */ 51 | public function getTime() 52 | { 53 | return $this->time; 54 | } 55 | 56 | public function hasTime() 57 | { 58 | return isset($this->time); 59 | } 60 | 61 | public function clearTime() 62 | { 63 | unset($this->time); 64 | } 65 | 66 | /** 67 | * The timestamp indicating the time the event occurred. 68 | * 69 | * Generated from protobuf field .google.protobuf.Timestamp time = 1; 70 | * @param \Google\Protobuf\Timestamp $var 71 | * @return $this 72 | */ 73 | public function setTime($var) 74 | { 75 | GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); 76 | $this->time = $var; 77 | 78 | return $this; 79 | } 80 | 81 | /** 82 | * Text annotation with a set of attributes. 83 | * 84 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.Annotation annotation = 2; 85 | * @return \Google\Cloud\Trace\V2\Span\TimeEvent\Annotation|null 86 | */ 87 | public function getAnnotation() 88 | { 89 | return $this->readOneof(2); 90 | } 91 | 92 | public function hasAnnotation() 93 | { 94 | return $this->hasOneof(2); 95 | } 96 | 97 | /** 98 | * Text annotation with a set of attributes. 99 | * 100 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.Annotation annotation = 2; 101 | * @param \Google\Cloud\Trace\V2\Span\TimeEvent\Annotation $var 102 | * @return $this 103 | */ 104 | public function setAnnotation($var) 105 | { 106 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\Span\TimeEvent\Annotation::class); 107 | $this->writeOneof(2, $var); 108 | 109 | return $this; 110 | } 111 | 112 | /** 113 | * An event describing a message sent/received between Spans. 114 | * 115 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent message_event = 3; 116 | * @return \Google\Cloud\Trace\V2\Span\TimeEvent\MessageEvent|null 117 | */ 118 | public function getMessageEvent() 119 | { 120 | return $this->readOneof(3); 121 | } 122 | 123 | public function hasMessageEvent() 124 | { 125 | return $this->hasOneof(3); 126 | } 127 | 128 | /** 129 | * An event describing a message sent/received between Spans. 130 | * 131 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent message_event = 3; 132 | * @param \Google\Cloud\Trace\V2\Span\TimeEvent\MessageEvent $var 133 | * @return $this 134 | */ 135 | public function setMessageEvent($var) 136 | { 137 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\Span\TimeEvent\MessageEvent::class); 138 | $this->writeOneof(3, $var); 139 | 140 | return $this; 141 | } 142 | 143 | /** 144 | * @return string 145 | */ 146 | public function getValue() 147 | { 148 | return $this->whichOneof("value"); 149 | } 150 | 151 | } 152 | 153 | // Adding a class alias for backwards compatibility with the previous class name. 154 | class_alias(TimeEvent::class, \Google\Cloud\Trace\V2\Span_TimeEvent::class); 155 | 156 | -------------------------------------------------------------------------------- /src/V2/Span/TimeEvent/Annotation.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.TimeEvent.Annotation 15 | */ 16 | class Annotation extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * A user-supplied message describing the event. The maximum length for 20 | * the description is 256 bytes. 21 | * 22 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString description = 1; 23 | */ 24 | private $description = null; 25 | /** 26 | * A set of attributes on the annotation. You can have up to 4 attributes 27 | * per Annotation. 28 | * 29 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Attributes attributes = 2; 30 | */ 31 | private $attributes = null; 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param array $data { 37 | * Optional. Data for populating the Message object. 38 | * 39 | * @type \Google\Cloud\Trace\V2\TruncatableString $description 40 | * A user-supplied message describing the event. The maximum length for 41 | * the description is 256 bytes. 42 | * @type \Google\Cloud\Trace\V2\Span\Attributes $attributes 43 | * A set of attributes on the annotation. You can have up to 4 attributes 44 | * per Annotation. 45 | * } 46 | */ 47 | public function __construct($data = NULL) { 48 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 49 | parent::__construct($data); 50 | } 51 | 52 | /** 53 | * A user-supplied message describing the event. The maximum length for 54 | * the description is 256 bytes. 55 | * 56 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString description = 1; 57 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 58 | */ 59 | public function getDescription() 60 | { 61 | return $this->description; 62 | } 63 | 64 | public function hasDescription() 65 | { 66 | return isset($this->description); 67 | } 68 | 69 | public function clearDescription() 70 | { 71 | unset($this->description); 72 | } 73 | 74 | /** 75 | * A user-supplied message describing the event. The maximum length for 76 | * the description is 256 bytes. 77 | * 78 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString description = 1; 79 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 80 | * @return $this 81 | */ 82 | public function setDescription($var) 83 | { 84 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 85 | $this->description = $var; 86 | 87 | return $this; 88 | } 89 | 90 | /** 91 | * A set of attributes on the annotation. You can have up to 4 attributes 92 | * per Annotation. 93 | * 94 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Attributes attributes = 2; 95 | * @return \Google\Cloud\Trace\V2\Span\Attributes|null 96 | */ 97 | public function getAttributes() 98 | { 99 | return $this->attributes; 100 | } 101 | 102 | public function hasAttributes() 103 | { 104 | return isset($this->attributes); 105 | } 106 | 107 | public function clearAttributes() 108 | { 109 | unset($this->attributes); 110 | } 111 | 112 | /** 113 | * A set of attributes on the annotation. You can have up to 4 attributes 114 | * per Annotation. 115 | * 116 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.Attributes attributes = 2; 117 | * @param \Google\Cloud\Trace\V2\Span\Attributes $var 118 | * @return $this 119 | */ 120 | public function setAttributes($var) 121 | { 122 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\Span\Attributes::class); 123 | $this->attributes = $var; 124 | 125 | return $this; 126 | } 127 | 128 | } 129 | 130 | // Adding a class alias for backwards compatibility with the previous class name. 131 | class_alias(Annotation::class, \Google\Cloud\Trace\V2\Span_TimeEvent_Annotation::class); 132 | 133 | -------------------------------------------------------------------------------- /src/V2/Span/TimeEvent/MessageEvent.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent 15 | */ 16 | class MessageEvent extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * Type of MessageEvent. Indicates whether the message was sent or 20 | * received. 21 | * 22 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent.Type type = 1; 23 | */ 24 | private $type = 0; 25 | /** 26 | * An identifier for the MessageEvent's message that can be used to match 27 | * `SENT` and `RECEIVED` MessageEvents. 28 | * 29 | * Generated from protobuf field int64 id = 2; 30 | */ 31 | private $id = 0; 32 | /** 33 | * The number of uncompressed bytes sent or received. 34 | * 35 | * Generated from protobuf field int64 uncompressed_size_bytes = 3; 36 | */ 37 | private $uncompressed_size_bytes = 0; 38 | /** 39 | * The number of compressed bytes sent or received. If missing, the 40 | * compressed size is assumed to be the same size as the uncompressed 41 | * size. 42 | * 43 | * Generated from protobuf field int64 compressed_size_bytes = 4; 44 | */ 45 | private $compressed_size_bytes = 0; 46 | 47 | /** 48 | * Constructor. 49 | * 50 | * @param array $data { 51 | * Optional. Data for populating the Message object. 52 | * 53 | * @type int $type 54 | * Type of MessageEvent. Indicates whether the message was sent or 55 | * received. 56 | * @type int|string $id 57 | * An identifier for the MessageEvent's message that can be used to match 58 | * `SENT` and `RECEIVED` MessageEvents. 59 | * @type int|string $uncompressed_size_bytes 60 | * The number of uncompressed bytes sent or received. 61 | * @type int|string $compressed_size_bytes 62 | * The number of compressed bytes sent or received. If missing, the 63 | * compressed size is assumed to be the same size as the uncompressed 64 | * size. 65 | * } 66 | */ 67 | public function __construct($data = NULL) { 68 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 69 | parent::__construct($data); 70 | } 71 | 72 | /** 73 | * Type of MessageEvent. Indicates whether the message was sent or 74 | * received. 75 | * 76 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent.Type type = 1; 77 | * @return int 78 | */ 79 | public function getType() 80 | { 81 | return $this->type; 82 | } 83 | 84 | /** 85 | * Type of MessageEvent. Indicates whether the message was sent or 86 | * received. 87 | * 88 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent.Type type = 1; 89 | * @param int $var 90 | * @return $this 91 | */ 92 | public function setType($var) 93 | { 94 | GPBUtil::checkEnum($var, \Google\Cloud\Trace\V2\Span\TimeEvent\MessageEvent\Type::class); 95 | $this->type = $var; 96 | 97 | return $this; 98 | } 99 | 100 | /** 101 | * An identifier for the MessageEvent's message that can be used to match 102 | * `SENT` and `RECEIVED` MessageEvents. 103 | * 104 | * Generated from protobuf field int64 id = 2; 105 | * @return int|string 106 | */ 107 | public function getId() 108 | { 109 | return $this->id; 110 | } 111 | 112 | /** 113 | * An identifier for the MessageEvent's message that can be used to match 114 | * `SENT` and `RECEIVED` MessageEvents. 115 | * 116 | * Generated from protobuf field int64 id = 2; 117 | * @param int|string $var 118 | * @return $this 119 | */ 120 | public function setId($var) 121 | { 122 | GPBUtil::checkInt64($var); 123 | $this->id = $var; 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * The number of uncompressed bytes sent or received. 130 | * 131 | * Generated from protobuf field int64 uncompressed_size_bytes = 3; 132 | * @return int|string 133 | */ 134 | public function getUncompressedSizeBytes() 135 | { 136 | return $this->uncompressed_size_bytes; 137 | } 138 | 139 | /** 140 | * The number of uncompressed bytes sent or received. 141 | * 142 | * Generated from protobuf field int64 uncompressed_size_bytes = 3; 143 | * @param int|string $var 144 | * @return $this 145 | */ 146 | public function setUncompressedSizeBytes($var) 147 | { 148 | GPBUtil::checkInt64($var); 149 | $this->uncompressed_size_bytes = $var; 150 | 151 | return $this; 152 | } 153 | 154 | /** 155 | * The number of compressed bytes sent or received. If missing, the 156 | * compressed size is assumed to be the same size as the uncompressed 157 | * size. 158 | * 159 | * Generated from protobuf field int64 compressed_size_bytes = 4; 160 | * @return int|string 161 | */ 162 | public function getCompressedSizeBytes() 163 | { 164 | return $this->compressed_size_bytes; 165 | } 166 | 167 | /** 168 | * The number of compressed bytes sent or received. If missing, the 169 | * compressed size is assumed to be the same size as the uncompressed 170 | * size. 171 | * 172 | * Generated from protobuf field int64 compressed_size_bytes = 4; 173 | * @param int|string $var 174 | * @return $this 175 | */ 176 | public function setCompressedSizeBytes($var) 177 | { 178 | GPBUtil::checkInt64($var); 179 | $this->compressed_size_bytes = $var; 180 | 181 | return $this; 182 | } 183 | 184 | } 185 | 186 | // Adding a class alias for backwards compatibility with the previous class name. 187 | class_alias(MessageEvent::class, \Google\Cloud\Trace\V2\Span_TimeEvent_MessageEvent::class); 188 | 189 | -------------------------------------------------------------------------------- /src/V2/Span/TimeEvent/MessageEvent/Type.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.TimeEvent.MessageEvent.Type 13 | */ 14 | class Type 15 | { 16 | /** 17 | * Unknown event type. 18 | * 19 | * Generated from protobuf enum TYPE_UNSPECIFIED = 0; 20 | */ 21 | const TYPE_UNSPECIFIED = 0; 22 | /** 23 | * Indicates a sent message. 24 | * 25 | * Generated from protobuf enum SENT = 1; 26 | */ 27 | const SENT = 1; 28 | /** 29 | * Indicates a received message. 30 | * 31 | * Generated from protobuf enum RECEIVED = 2; 32 | */ 33 | const RECEIVED = 2; 34 | 35 | private static $valueToName = [ 36 | self::TYPE_UNSPECIFIED => 'TYPE_UNSPECIFIED', 37 | self::SENT => 'SENT', 38 | self::RECEIVED => 'RECEIVED', 39 | ]; 40 | 41 | public static function name($value) 42 | { 43 | if (!isset(self::$valueToName[$value])) { 44 | throw new UnexpectedValueException(sprintf( 45 | 'Enum %s has no name defined for value %s', __CLASS__, $value)); 46 | } 47 | return self::$valueToName[$value]; 48 | } 49 | 50 | 51 | public static function value($name) 52 | { 53 | $const = __CLASS__ . '::' . strtoupper($name); 54 | if (!defined($const)) { 55 | throw new UnexpectedValueException(sprintf( 56 | 'Enum %s has no value defined for name %s', __CLASS__, $name)); 57 | } 58 | return constant($const); 59 | } 60 | } 61 | 62 | // Adding a class alias for backwards compatibility with the previous class name. 63 | class_alias(Type::class, \Google\Cloud\Trace\V2\Span_TimeEvent_MessageEvent_Type::class); 64 | 65 | -------------------------------------------------------------------------------- /src/V2/Span/TimeEvents.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.Span.TimeEvents 17 | */ 18 | class TimeEvents extends \Google\Protobuf\Internal\Message 19 | { 20 | /** 21 | * A collection of `TimeEvent`s. 22 | * 23 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span.TimeEvent time_event = 1; 24 | */ 25 | private $time_event; 26 | /** 27 | * The number of dropped annotations in all the included time events. 28 | * If the value is 0, then no annotations were dropped. 29 | * 30 | * Generated from protobuf field int32 dropped_annotations_count = 2; 31 | */ 32 | private $dropped_annotations_count = 0; 33 | /** 34 | * The number of dropped message events in all the included time events. 35 | * If the value is 0, then no message events were dropped. 36 | * 37 | * Generated from protobuf field int32 dropped_message_events_count = 3; 38 | */ 39 | private $dropped_message_events_count = 0; 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param array $data { 45 | * Optional. Data for populating the Message object. 46 | * 47 | * @type array<\Google\Cloud\Trace\V2\Span\TimeEvent>|\Google\Protobuf\Internal\RepeatedField $time_event 48 | * A collection of `TimeEvent`s. 49 | * @type int $dropped_annotations_count 50 | * The number of dropped annotations in all the included time events. 51 | * If the value is 0, then no annotations were dropped. 52 | * @type int $dropped_message_events_count 53 | * The number of dropped message events in all the included time events. 54 | * If the value is 0, then no message events were dropped. 55 | * } 56 | */ 57 | public function __construct($data = NULL) { 58 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 59 | parent::__construct($data); 60 | } 61 | 62 | /** 63 | * A collection of `TimeEvent`s. 64 | * 65 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span.TimeEvent time_event = 1; 66 | * @return \Google\Protobuf\Internal\RepeatedField 67 | */ 68 | public function getTimeEvent() 69 | { 70 | return $this->time_event; 71 | } 72 | 73 | /** 74 | * A collection of `TimeEvent`s. 75 | * 76 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.Span.TimeEvent time_event = 1; 77 | * @param array<\Google\Cloud\Trace\V2\Span\TimeEvent>|\Google\Protobuf\Internal\RepeatedField $var 78 | * @return $this 79 | */ 80 | public function setTimeEvent($var) 81 | { 82 | $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Trace\V2\Span\TimeEvent::class); 83 | $this->time_event = $arr; 84 | 85 | return $this; 86 | } 87 | 88 | /** 89 | * The number of dropped annotations in all the included time events. 90 | * If the value is 0, then no annotations were dropped. 91 | * 92 | * Generated from protobuf field int32 dropped_annotations_count = 2; 93 | * @return int 94 | */ 95 | public function getDroppedAnnotationsCount() 96 | { 97 | return $this->dropped_annotations_count; 98 | } 99 | 100 | /** 101 | * The number of dropped annotations in all the included time events. 102 | * If the value is 0, then no annotations were dropped. 103 | * 104 | * Generated from protobuf field int32 dropped_annotations_count = 2; 105 | * @param int $var 106 | * @return $this 107 | */ 108 | public function setDroppedAnnotationsCount($var) 109 | { 110 | GPBUtil::checkInt32($var); 111 | $this->dropped_annotations_count = $var; 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * The number of dropped message events in all the included time events. 118 | * If the value is 0, then no message events were dropped. 119 | * 120 | * Generated from protobuf field int32 dropped_message_events_count = 3; 121 | * @return int 122 | */ 123 | public function getDroppedMessageEventsCount() 124 | { 125 | return $this->dropped_message_events_count; 126 | } 127 | 128 | /** 129 | * The number of dropped message events in all the included time events. 130 | * If the value is 0, then no message events were dropped. 131 | * 132 | * Generated from protobuf field int32 dropped_message_events_count = 3; 133 | * @param int $var 134 | * @return $this 135 | */ 136 | public function setDroppedMessageEventsCount($var) 137 | { 138 | GPBUtil::checkInt32($var); 139 | $this->dropped_message_events_count = $var; 140 | 141 | return $this; 142 | } 143 | 144 | } 145 | 146 | // Adding a class alias for backwards compatibility with the previous class name. 147 | class_alias(TimeEvents::class, \Google\Cloud\Trace\V2\Span_TimeEvents::class); 148 | 149 | -------------------------------------------------------------------------------- /src/V2/Span_Attributes.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.StackTrace 15 | */ 16 | class StackTrace extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * Stack frames in this stack trace. A maximum of 128 frames are allowed. 20 | * 21 | * Generated from protobuf field .google.devtools.cloudtrace.v2.StackTrace.StackFrames stack_frames = 1; 22 | */ 23 | private $stack_frames = null; 24 | /** 25 | * The hash ID is used to conserve network bandwidth for duplicate 26 | * stack traces within a single trace. 27 | * Often multiple spans will have identical stack traces. 28 | * The first occurrence of a stack trace should contain both the 29 | * `stackFrame` content and a value in `stackTraceHashId`. 30 | * Subsequent spans within the same request can refer 31 | * to that stack trace by only setting `stackTraceHashId`. 32 | * 33 | * Generated from protobuf field int64 stack_trace_hash_id = 2; 34 | */ 35 | private $stack_trace_hash_id = 0; 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param array $data { 41 | * Optional. Data for populating the Message object. 42 | * 43 | * @type \Google\Cloud\Trace\V2\StackTrace\StackFrames $stack_frames 44 | * Stack frames in this stack trace. A maximum of 128 frames are allowed. 45 | * @type int|string $stack_trace_hash_id 46 | * The hash ID is used to conserve network bandwidth for duplicate 47 | * stack traces within a single trace. 48 | * Often multiple spans will have identical stack traces. 49 | * The first occurrence of a stack trace should contain both the 50 | * `stackFrame` content and a value in `stackTraceHashId`. 51 | * Subsequent spans within the same request can refer 52 | * to that stack trace by only setting `stackTraceHashId`. 53 | * } 54 | */ 55 | public function __construct($data = NULL) { 56 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 57 | parent::__construct($data); 58 | } 59 | 60 | /** 61 | * Stack frames in this stack trace. A maximum of 128 frames are allowed. 62 | * 63 | * Generated from protobuf field .google.devtools.cloudtrace.v2.StackTrace.StackFrames stack_frames = 1; 64 | * @return \Google\Cloud\Trace\V2\StackTrace\StackFrames|null 65 | */ 66 | public function getStackFrames() 67 | { 68 | return $this->stack_frames; 69 | } 70 | 71 | public function hasStackFrames() 72 | { 73 | return isset($this->stack_frames); 74 | } 75 | 76 | public function clearStackFrames() 77 | { 78 | unset($this->stack_frames); 79 | } 80 | 81 | /** 82 | * Stack frames in this stack trace. A maximum of 128 frames are allowed. 83 | * 84 | * Generated from protobuf field .google.devtools.cloudtrace.v2.StackTrace.StackFrames stack_frames = 1; 85 | * @param \Google\Cloud\Trace\V2\StackTrace\StackFrames $var 86 | * @return $this 87 | */ 88 | public function setStackFrames($var) 89 | { 90 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\StackTrace\StackFrames::class); 91 | $this->stack_frames = $var; 92 | 93 | return $this; 94 | } 95 | 96 | /** 97 | * The hash ID is used to conserve network bandwidth for duplicate 98 | * stack traces within a single trace. 99 | * Often multiple spans will have identical stack traces. 100 | * The first occurrence of a stack trace should contain both the 101 | * `stackFrame` content and a value in `stackTraceHashId`. 102 | * Subsequent spans within the same request can refer 103 | * to that stack trace by only setting `stackTraceHashId`. 104 | * 105 | * Generated from protobuf field int64 stack_trace_hash_id = 2; 106 | * @return int|string 107 | */ 108 | public function getStackTraceHashId() 109 | { 110 | return $this->stack_trace_hash_id; 111 | } 112 | 113 | /** 114 | * The hash ID is used to conserve network bandwidth for duplicate 115 | * stack traces within a single trace. 116 | * Often multiple spans will have identical stack traces. 117 | * The first occurrence of a stack trace should contain both the 118 | * `stackFrame` content and a value in `stackTraceHashId`. 119 | * Subsequent spans within the same request can refer 120 | * to that stack trace by only setting `stackTraceHashId`. 121 | * 122 | * Generated from protobuf field int64 stack_trace_hash_id = 2; 123 | * @param int|string $var 124 | * @return $this 125 | */ 126 | public function setStackTraceHashId($var) 127 | { 128 | GPBUtil::checkInt64($var); 129 | $this->stack_trace_hash_id = $var; 130 | 131 | return $this; 132 | } 133 | 134 | } 135 | 136 | -------------------------------------------------------------------------------- /src/V2/StackTrace/StackFrame.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.StackTrace.StackFrame 15 | */ 16 | class StackFrame extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * The fully-qualified name that uniquely identifies the function or 20 | * method that is active in this frame (up to 1024 bytes). 21 | * 22 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString function_name = 1; 23 | */ 24 | private $function_name = null; 25 | /** 26 | * An un-mangled function name, if `function_name` is mangled. 27 | * To get information about name mangling, run 28 | * [this search](https://www.google.com/search?q=cxx+name+mangling). 29 | * The name can be fully-qualified (up to 1024 bytes). 30 | * 31 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString original_function_name = 2; 32 | */ 33 | private $original_function_name = null; 34 | /** 35 | * The name of the source file where the function call appears (up to 256 36 | * bytes). 37 | * 38 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString file_name = 3; 39 | */ 40 | private $file_name = null; 41 | /** 42 | * The line number in `file_name` where the function call appears. 43 | * 44 | * Generated from protobuf field int64 line_number = 4; 45 | */ 46 | private $line_number = 0; 47 | /** 48 | * The column number where the function call appears, if available. 49 | * This is important in JavaScript because of its anonymous functions. 50 | * 51 | * Generated from protobuf field int64 column_number = 5; 52 | */ 53 | private $column_number = 0; 54 | /** 55 | * The binary module from where the code was loaded. 56 | * 57 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Module load_module = 6; 58 | */ 59 | private $load_module = null; 60 | /** 61 | * The version of the deployed source code (up to 128 bytes). 62 | * 63 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString source_version = 7; 64 | */ 65 | private $source_version = null; 66 | 67 | /** 68 | * Constructor. 69 | * 70 | * @param array $data { 71 | * Optional. Data for populating the Message object. 72 | * 73 | * @type \Google\Cloud\Trace\V2\TruncatableString $function_name 74 | * The fully-qualified name that uniquely identifies the function or 75 | * method that is active in this frame (up to 1024 bytes). 76 | * @type \Google\Cloud\Trace\V2\TruncatableString $original_function_name 77 | * An un-mangled function name, if `function_name` is mangled. 78 | * To get information about name mangling, run 79 | * [this search](https://www.google.com/search?q=cxx+name+mangling). 80 | * The name can be fully-qualified (up to 1024 bytes). 81 | * @type \Google\Cloud\Trace\V2\TruncatableString $file_name 82 | * The name of the source file where the function call appears (up to 256 83 | * bytes). 84 | * @type int|string $line_number 85 | * The line number in `file_name` where the function call appears. 86 | * @type int|string $column_number 87 | * The column number where the function call appears, if available. 88 | * This is important in JavaScript because of its anonymous functions. 89 | * @type \Google\Cloud\Trace\V2\Module $load_module 90 | * The binary module from where the code was loaded. 91 | * @type \Google\Cloud\Trace\V2\TruncatableString $source_version 92 | * The version of the deployed source code (up to 128 bytes). 93 | * } 94 | */ 95 | public function __construct($data = NULL) { 96 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 97 | parent::__construct($data); 98 | } 99 | 100 | /** 101 | * The fully-qualified name that uniquely identifies the function or 102 | * method that is active in this frame (up to 1024 bytes). 103 | * 104 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString function_name = 1; 105 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 106 | */ 107 | public function getFunctionName() 108 | { 109 | return $this->function_name; 110 | } 111 | 112 | public function hasFunctionName() 113 | { 114 | return isset($this->function_name); 115 | } 116 | 117 | public function clearFunctionName() 118 | { 119 | unset($this->function_name); 120 | } 121 | 122 | /** 123 | * The fully-qualified name that uniquely identifies the function or 124 | * method that is active in this frame (up to 1024 bytes). 125 | * 126 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString function_name = 1; 127 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 128 | * @return $this 129 | */ 130 | public function setFunctionName($var) 131 | { 132 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 133 | $this->function_name = $var; 134 | 135 | return $this; 136 | } 137 | 138 | /** 139 | * An un-mangled function name, if `function_name` is mangled. 140 | * To get information about name mangling, run 141 | * [this search](https://www.google.com/search?q=cxx+name+mangling). 142 | * The name can be fully-qualified (up to 1024 bytes). 143 | * 144 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString original_function_name = 2; 145 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 146 | */ 147 | public function getOriginalFunctionName() 148 | { 149 | return $this->original_function_name; 150 | } 151 | 152 | public function hasOriginalFunctionName() 153 | { 154 | return isset($this->original_function_name); 155 | } 156 | 157 | public function clearOriginalFunctionName() 158 | { 159 | unset($this->original_function_name); 160 | } 161 | 162 | /** 163 | * An un-mangled function name, if `function_name` is mangled. 164 | * To get information about name mangling, run 165 | * [this search](https://www.google.com/search?q=cxx+name+mangling). 166 | * The name can be fully-qualified (up to 1024 bytes). 167 | * 168 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString original_function_name = 2; 169 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 170 | * @return $this 171 | */ 172 | public function setOriginalFunctionName($var) 173 | { 174 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 175 | $this->original_function_name = $var; 176 | 177 | return $this; 178 | } 179 | 180 | /** 181 | * The name of the source file where the function call appears (up to 256 182 | * bytes). 183 | * 184 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString file_name = 3; 185 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 186 | */ 187 | public function getFileName() 188 | { 189 | return $this->file_name; 190 | } 191 | 192 | public function hasFileName() 193 | { 194 | return isset($this->file_name); 195 | } 196 | 197 | public function clearFileName() 198 | { 199 | unset($this->file_name); 200 | } 201 | 202 | /** 203 | * The name of the source file where the function call appears (up to 256 204 | * bytes). 205 | * 206 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString file_name = 3; 207 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 208 | * @return $this 209 | */ 210 | public function setFileName($var) 211 | { 212 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 213 | $this->file_name = $var; 214 | 215 | return $this; 216 | } 217 | 218 | /** 219 | * The line number in `file_name` where the function call appears. 220 | * 221 | * Generated from protobuf field int64 line_number = 4; 222 | * @return int|string 223 | */ 224 | public function getLineNumber() 225 | { 226 | return $this->line_number; 227 | } 228 | 229 | /** 230 | * The line number in `file_name` where the function call appears. 231 | * 232 | * Generated from protobuf field int64 line_number = 4; 233 | * @param int|string $var 234 | * @return $this 235 | */ 236 | public function setLineNumber($var) 237 | { 238 | GPBUtil::checkInt64($var); 239 | $this->line_number = $var; 240 | 241 | return $this; 242 | } 243 | 244 | /** 245 | * The column number where the function call appears, if available. 246 | * This is important in JavaScript because of its anonymous functions. 247 | * 248 | * Generated from protobuf field int64 column_number = 5; 249 | * @return int|string 250 | */ 251 | public function getColumnNumber() 252 | { 253 | return $this->column_number; 254 | } 255 | 256 | /** 257 | * The column number where the function call appears, if available. 258 | * This is important in JavaScript because of its anonymous functions. 259 | * 260 | * Generated from protobuf field int64 column_number = 5; 261 | * @param int|string $var 262 | * @return $this 263 | */ 264 | public function setColumnNumber($var) 265 | { 266 | GPBUtil::checkInt64($var); 267 | $this->column_number = $var; 268 | 269 | return $this; 270 | } 271 | 272 | /** 273 | * The binary module from where the code was loaded. 274 | * 275 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Module load_module = 6; 276 | * @return \Google\Cloud\Trace\V2\Module|null 277 | */ 278 | public function getLoadModule() 279 | { 280 | return $this->load_module; 281 | } 282 | 283 | public function hasLoadModule() 284 | { 285 | return isset($this->load_module); 286 | } 287 | 288 | public function clearLoadModule() 289 | { 290 | unset($this->load_module); 291 | } 292 | 293 | /** 294 | * The binary module from where the code was loaded. 295 | * 296 | * Generated from protobuf field .google.devtools.cloudtrace.v2.Module load_module = 6; 297 | * @param \Google\Cloud\Trace\V2\Module $var 298 | * @return $this 299 | */ 300 | public function setLoadModule($var) 301 | { 302 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\Module::class); 303 | $this->load_module = $var; 304 | 305 | return $this; 306 | } 307 | 308 | /** 309 | * The version of the deployed source code (up to 128 bytes). 310 | * 311 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString source_version = 7; 312 | * @return \Google\Cloud\Trace\V2\TruncatableString|null 313 | */ 314 | public function getSourceVersion() 315 | { 316 | return $this->source_version; 317 | } 318 | 319 | public function hasSourceVersion() 320 | { 321 | return isset($this->source_version); 322 | } 323 | 324 | public function clearSourceVersion() 325 | { 326 | unset($this->source_version); 327 | } 328 | 329 | /** 330 | * The version of the deployed source code (up to 128 bytes). 331 | * 332 | * Generated from protobuf field .google.devtools.cloudtrace.v2.TruncatableString source_version = 7; 333 | * @param \Google\Cloud\Trace\V2\TruncatableString $var 334 | * @return $this 335 | */ 336 | public function setSourceVersion($var) 337 | { 338 | GPBUtil::checkMessage($var, \Google\Cloud\Trace\V2\TruncatableString::class); 339 | $this->source_version = $var; 340 | 341 | return $this; 342 | } 343 | 344 | } 345 | 346 | // Adding a class alias for backwards compatibility with the previous class name. 347 | class_alias(StackFrame::class, \Google\Cloud\Trace\V2\StackTrace_StackFrame::class); 348 | 349 | -------------------------------------------------------------------------------- /src/V2/StackTrace/StackFrames.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.StackTrace.StackFrames 15 | */ 16 | class StackFrames extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * Stack frames in this call stack. 20 | * 21 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.StackTrace.StackFrame frame = 1; 22 | */ 23 | private $frame; 24 | /** 25 | * The number of stack frames that were dropped because there 26 | * were too many stack frames. 27 | * If this value is 0, then no stack frames were dropped. 28 | * 29 | * Generated from protobuf field int32 dropped_frames_count = 2; 30 | */ 31 | private $dropped_frames_count = 0; 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param array $data { 37 | * Optional. Data for populating the Message object. 38 | * 39 | * @type array<\Google\Cloud\Trace\V2\StackTrace\StackFrame>|\Google\Protobuf\Internal\RepeatedField $frame 40 | * Stack frames in this call stack. 41 | * @type int $dropped_frames_count 42 | * The number of stack frames that were dropped because there 43 | * were too many stack frames. 44 | * If this value is 0, then no stack frames were dropped. 45 | * } 46 | */ 47 | public function __construct($data = NULL) { 48 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 49 | parent::__construct($data); 50 | } 51 | 52 | /** 53 | * Stack frames in this call stack. 54 | * 55 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.StackTrace.StackFrame frame = 1; 56 | * @return \Google\Protobuf\Internal\RepeatedField 57 | */ 58 | public function getFrame() 59 | { 60 | return $this->frame; 61 | } 62 | 63 | /** 64 | * Stack frames in this call stack. 65 | * 66 | * Generated from protobuf field repeated .google.devtools.cloudtrace.v2.StackTrace.StackFrame frame = 1; 67 | * @param array<\Google\Cloud\Trace\V2\StackTrace\StackFrame>|\Google\Protobuf\Internal\RepeatedField $var 68 | * @return $this 69 | */ 70 | public function setFrame($var) 71 | { 72 | $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Trace\V2\StackTrace\StackFrame::class); 73 | $this->frame = $arr; 74 | 75 | return $this; 76 | } 77 | 78 | /** 79 | * The number of stack frames that were dropped because there 80 | * were too many stack frames. 81 | * If this value is 0, then no stack frames were dropped. 82 | * 83 | * Generated from protobuf field int32 dropped_frames_count = 2; 84 | * @return int 85 | */ 86 | public function getDroppedFramesCount() 87 | { 88 | return $this->dropped_frames_count; 89 | } 90 | 91 | /** 92 | * The number of stack frames that were dropped because there 93 | * were too many stack frames. 94 | * If this value is 0, then no stack frames were dropped. 95 | * 96 | * Generated from protobuf field int32 dropped_frames_count = 2; 97 | * @param int $var 98 | * @return $this 99 | */ 100 | public function setDroppedFramesCount($var) 101 | { 102 | GPBUtil::checkInt32($var); 103 | $this->dropped_frames_count = $var; 104 | 105 | return $this; 106 | } 107 | 108 | } 109 | 110 | // Adding a class alias for backwards compatibility with the previous class name. 111 | class_alias(StackFrames::class, \Google\Cloud\Trace\V2\StackTrace_StackFrames::class); 112 | 113 | -------------------------------------------------------------------------------- /src/V2/StackTrace_StackFrame.php: -------------------------------------------------------------------------------- 1 | _simpleRequest('/google.devtools.cloudtrace.v2.TraceService/BatchWriteSpans', 52 | $argument, 53 | ['\Google\Protobuf\GPBEmpty', 'decode'], 54 | $metadata, $options); 55 | } 56 | 57 | /** 58 | * Creates a new span. 59 | * @param \Google\Cloud\Trace\V2\Span $argument input argument 60 | * @param array $metadata metadata 61 | * @param array $options call options 62 | * @return \Grpc\UnaryCall 63 | */ 64 | public function CreateSpan(\Google\Cloud\Trace\V2\Span $argument, 65 | $metadata = [], $options = []) { 66 | return $this->_simpleRequest('/google.devtools.cloudtrace.v2.TraceService/CreateSpan', 67 | $argument, 68 | ['\Google\Cloud\Trace\V2\Span', 'decode'], 69 | $metadata, $options); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/V2/TruncatableString.php: -------------------------------------------------------------------------------- 1 | google.devtools.cloudtrace.v2.TruncatableString 15 | */ 16 | class TruncatableString extends \Google\Protobuf\Internal\Message 17 | { 18 | /** 19 | * The shortened string. For example, if the original string is 500 20 | * bytes long and the limit of the string is 128 bytes, then 21 | * `value` contains the first 128 bytes of the 500-byte string. 22 | * Truncation always happens on a UTF8 character boundary. If there 23 | * are multi-byte characters in the string, then the length of the 24 | * shortened string might be less than the size limit. 25 | * 26 | * Generated from protobuf field string value = 1; 27 | */ 28 | private $value = ''; 29 | /** 30 | * The number of bytes removed from the original string. If this 31 | * value is 0, then the string was not shortened. 32 | * 33 | * Generated from protobuf field int32 truncated_byte_count = 2; 34 | */ 35 | private $truncated_byte_count = 0; 36 | 37 | /** 38 | * Constructor. 39 | * 40 | * @param array $data { 41 | * Optional. Data for populating the Message object. 42 | * 43 | * @type string $value 44 | * The shortened string. For example, if the original string is 500 45 | * bytes long and the limit of the string is 128 bytes, then 46 | * `value` contains the first 128 bytes of the 500-byte string. 47 | * Truncation always happens on a UTF8 character boundary. If there 48 | * are multi-byte characters in the string, then the length of the 49 | * shortened string might be less than the size limit. 50 | * @type int $truncated_byte_count 51 | * The number of bytes removed from the original string. If this 52 | * value is 0, then the string was not shortened. 53 | * } 54 | */ 55 | public function __construct($data = NULL) { 56 | \GPBMetadata\Google\Devtools\Cloudtrace\V2\Trace::initOnce(); 57 | parent::__construct($data); 58 | } 59 | 60 | /** 61 | * The shortened string. For example, if the original string is 500 62 | * bytes long and the limit of the string is 128 bytes, then 63 | * `value` contains the first 128 bytes of the 500-byte string. 64 | * Truncation always happens on a UTF8 character boundary. If there 65 | * are multi-byte characters in the string, then the length of the 66 | * shortened string might be less than the size limit. 67 | * 68 | * Generated from protobuf field string value = 1; 69 | * @return string 70 | */ 71 | public function getValue() 72 | { 73 | return $this->value; 74 | } 75 | 76 | /** 77 | * The shortened string. For example, if the original string is 500 78 | * bytes long and the limit of the string is 128 bytes, then 79 | * `value` contains the first 128 bytes of the 500-byte string. 80 | * Truncation always happens on a UTF8 character boundary. If there 81 | * are multi-byte characters in the string, then the length of the 82 | * shortened string might be less than the size limit. 83 | * 84 | * Generated from protobuf field string value = 1; 85 | * @param string $var 86 | * @return $this 87 | */ 88 | public function setValue($var) 89 | { 90 | GPBUtil::checkString($var, True); 91 | $this->value = $var; 92 | 93 | return $this; 94 | } 95 | 96 | /** 97 | * The number of bytes removed from the original string. If this 98 | * value is 0, then the string was not shortened. 99 | * 100 | * Generated from protobuf field int32 truncated_byte_count = 2; 101 | * @return int 102 | */ 103 | public function getTruncatedByteCount() 104 | { 105 | return $this->truncated_byte_count; 106 | } 107 | 108 | /** 109 | * The number of bytes removed from the original string. If this 110 | * value is 0, then the string was not shortened. 111 | * 112 | * Generated from protobuf field int32 truncated_byte_count = 2; 113 | * @param int $var 114 | * @return $this 115 | */ 116 | public function setTruncatedByteCount($var) 117 | { 118 | GPBUtil::checkInt32($var); 119 | $this->truncated_byte_count = $var; 120 | 121 | return $this; 122 | } 123 | 124 | } 125 | 126 | -------------------------------------------------------------------------------- /src/V2/resources/trace_service_client_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "interfaces": { 3 | "google.devtools.cloudtrace.v2.TraceService": { 4 | "retry_codes": { 5 | "no_retry_codes": [], 6 | "retry_policy_1_codes": [ 7 | "UNAVAILABLE", 8 | "DEADLINE_EXCEEDED" 9 | ], 10 | "retry_policy_2_codes": [ 11 | "UNAVAILABLE", 12 | "DEADLINE_EXCEEDED" 13 | ] 14 | }, 15 | "retry_params": { 16 | "no_retry_params": { 17 | "initial_retry_delay_millis": 0, 18 | "retry_delay_multiplier": 0.0, 19 | "max_retry_delay_millis": 0, 20 | "initial_rpc_timeout_millis": 0, 21 | "rpc_timeout_multiplier": 1.0, 22 | "max_rpc_timeout_millis": 0, 23 | "total_timeout_millis": 0 24 | }, 25 | "retry_policy_1_params": { 26 | "initial_retry_delay_millis": 100, 27 | "retry_delay_multiplier": 2.0, 28 | "max_retry_delay_millis": 30000, 29 | "initial_rpc_timeout_millis": 120000, 30 | "rpc_timeout_multiplier": 1.0, 31 | "max_rpc_timeout_millis": 120000, 32 | "total_timeout_millis": 120000 33 | }, 34 | "retry_policy_2_params": { 35 | "initial_retry_delay_millis": 100, 36 | "retry_delay_multiplier": 1.2, 37 | "max_retry_delay_millis": 1000, 38 | "initial_rpc_timeout_millis": 120000, 39 | "rpc_timeout_multiplier": 1.0, 40 | "max_rpc_timeout_millis": 120000, 41 | "total_timeout_millis": 120000 42 | } 43 | }, 44 | "methods": { 45 | "BatchWriteSpans": { 46 | "timeout_millis": 120000, 47 | "retry_codes_name": "retry_policy_1_codes", 48 | "retry_params_name": "retry_policy_1_params" 49 | }, 50 | "CreateSpan": { 51 | "timeout_millis": 120000, 52 | "retry_codes_name": "retry_policy_2_codes", 53 | "retry_params_name": "retry_policy_2_params" 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/V2/resources/trace_service_descriptor_config.php: -------------------------------------------------------------------------------- 1 | [ 25 | 'google.devtools.cloudtrace.v2.TraceService' => [ 26 | 'BatchWriteSpans' => [ 27 | 'callType' => \Google\ApiCore\Call::UNARY_CALL, 28 | 'responseType' => 'Google\Protobuf\GPBEmpty', 29 | 'headerParams' => [ 30 | [ 31 | 'keyName' => 'name', 32 | 'fieldAccessors' => [ 33 | 'getName', 34 | ], 35 | ], 36 | ], 37 | ], 38 | 'CreateSpan' => [ 39 | 'callType' => \Google\ApiCore\Call::UNARY_CALL, 40 | 'responseType' => 'Google\Cloud\Trace\V2\Span', 41 | 'headerParams' => [ 42 | [ 43 | 'keyName' => 'name', 44 | 'fieldAccessors' => [ 45 | 'getName', 46 | ], 47 | ], 48 | ], 49 | ], 50 | 'templateMap' => [ 51 | 'project' => 'projects/{project}', 52 | 'span' => 'projects/{project}/traces/{trace}/spans/{span}', 53 | ], 54 | ], 55 | ], 56 | ]; 57 | -------------------------------------------------------------------------------- /src/V2/resources/trace_service_rest_client_config.php: -------------------------------------------------------------------------------- 1 | [ 25 | 'google.devtools.cloudtrace.v2.TraceService' => [ 26 | 'BatchWriteSpans' => [ 27 | 'method' => 'post', 28 | 'uriTemplate' => '/v2/{name=projects/*}/traces:batchWrite', 29 | 'body' => '*', 30 | 'placeholders' => [ 31 | 'name' => [ 32 | 'getters' => [ 33 | 'getName', 34 | ], 35 | ], 36 | ], 37 | ], 38 | 'CreateSpan' => [ 39 | 'method' => 'post', 40 | 'uriTemplate' => '/v2/{name=projects/*/traces/*/spans/*}', 41 | 'body' => '*', 42 | 'placeholders' => [ 43 | 'name' => [ 44 | 'getters' => [ 45 | 'getName', 46 | ], 47 | ], 48 | ], 49 | ], 50 | ], 51 | ], 52 | 'numericEnums' => true, 53 | ]; 54 | --------------------------------------------------------------------------------