Stackdriver Trace API - #388
Conversation
Implements basic Trace and TraceSpan resources. TraceClient tests Fix tests. Connection needed to be protected Code style fixes
jdpedrie
left a comment
There was a problem hiding this comment.
This is looking great! Hope these comments aren't coming too early in your process.
| */ | ||
| public function __construct(array $options) | ||
| { | ||
| $this->projectId = $options['projectId']; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * @param TraceSpan[] $spans | ||
| */ | ||
| public function setSpans(array $spans) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param Trace[] $traces The trace logs to send. | ||
| * @return Trace[] Array of new or updated traces. | ||
| */ | ||
| public function patchTraces(array $traces) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * @return array | ||
| */ | ||
| public function info() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param \DateTime $when [optional] The end time of this span. | ||
| * **Defaults to** now. | ||
| */ | ||
| public function finish(\DateTime $when = null) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * @param array $labels Labels in the form of $label => $value | ||
| */ | ||
| public function addLabels($labels) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * limitations under the License. | ||
| */ | ||
|
|
||
| namespace Google\Cloud\Tests\Trace\Connection; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Can you provide an example of how the constants in Labels are used? Is it worth having a class dedicated to them entirely, or could they be contained in TraceClient? |
|
@jdpedrie I'll remove it for now as the design for it's use isn't solidified yet. Originally, TraceSpan had one labels collection object, but now the TraceSpan just manages the labels itself. Currently it's just a namespace for some constants. We can revisit when the user integration pieces are built. |
|
Make sure you rebase against |
|
@jdpedrie If you have a chance to review, the basic API endpoints are all working and tested (unit/snippet/system). For a sneak peek into how the developer integration piece might look, see: https://github.com/chingor13/google-cloud-php/pull/3/files and https://github.com/chingor13/laravel_blog/blob/master/app/Providers/GoogleCloudProvider.php |
| /** | ||
| * Retrieves the spans for this trace. | ||
| * | ||
| * @return array |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * @return string | ||
| */ | ||
| public function projectId() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| ]); | ||
|
|
||
| if (empty($trace)) { | ||
| throw new NotFoundException('Trace ID does not exist', 404); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
|
|
||
| /** | ||
| * Lazily find or instantiates a trace. There are no network requests made at this |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @type string $orderBy Field used to sort the returned traces. Can be one | ||
| * of 'traceId', 'name', 'duration', 'start'. Descending order | ||
| * } | ||
| * @return \Generator<Trace> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param \DateTime $when [optional] The start time of this span. | ||
| * **Defaults to** now. | ||
| */ | ||
| public function setStart(\DateTime $when = null) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * **Defaults to** now. | ||
| * @return string | ||
| */ | ||
| private function formatDate($when = null) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| $span2 = new TraceSpan(['name' => 'inner', 'parentSpanId' => $span->spanId()]); | ||
| $span2->setStart(); | ||
|
|
||
| usleep(20000); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * @param array $config [optional] Configuration options. See | ||
| * {@see Google\Cloud\ServiceBuilder::__construct()} for the available options. | ||
| * @return StorageClient |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @type string $orderBy Field used to sort the returned traces. Can be one | ||
| * of 'traceId', 'name', 'duration', 'start'. Descending order | ||
| * } | ||
| * @return \Generator<Trace> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @return Trace | ||
| * @throws ServiceException | ||
| */ | ||
| public function getTrace($traceId) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** | ||
| * Fetch all traces in the project | ||
| * | ||
| * @param array $options [optional] { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @type string $viewType Type of data returned for traces in the list. | ||
| * Can be one of 'VIEW_TYPE_UNSPECIFIED', 'MINIMAL', 'ROOTSPAN', or | ||
| * 'COMPLETE' | ||
| * @type integer $pageSize Maximum number of traces to return |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * 'COMPLETE' | ||
| * @type integer $pageSize Maximum number of traces to return | ||
| * @type string $pageToken Token identifying the page of results to return | ||
| * @type string $startTime Start of the time interval during which trace data |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * collected | ||
| * @type sring $filter An optional filter for the request | ||
| * @type string $orderBy Field used to sort the returned traces. Can be one | ||
| * of 'traceId', 'name', 'duration', 'start'. Descending order |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * | ||
| * @param TraceSpan[] $spans | ||
| */ | ||
| public function setSpans(array $spans) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Sorry for any overlapping items that @jdpedrie may have pointed out. I didn't notice his review items until after I had just posted. |
| * } | ||
| * @return ItemIterator<Trace> | ||
| */ | ||
| public function traces(array $options = []) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * Associative array containing all the fields representing this TraceSpan. | ||
| * @var array | ||
| */ | ||
| private $info; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 'kind' => self::SPAN_KIND_UNSPECIFIED | ||
| ]; | ||
|
|
||
| if (!array_key_exists('spanId', $this->info)) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| private function generateSpanName() | ||
| { | ||
| // FIXME: clean backtrace rather than guessing the stack depth |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| use Rize\UriTemplate; | ||
|
|
||
| /** | ||
| * @group translate |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| use Google\Cloud\Trace\TraceSpan; | ||
| use Google\Cloud\Trace\Trace; | ||
|
|
||
| class BasicTest extends \PHPUnit_Framework_TestCase |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| $micro = sprintf("%06d", $usec * 1000000); | ||
| $when = new \DateTime(date('Y-m-d H:i:s.' . $micro)); | ||
| } | ||
| return $when->format('Y-m-d\TH:i:s.u000\Z'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| use Google\Cloud\Trace\Connection\Rest; | ||
|
|
||
| /** | ||
| * Google Stackdriver Trace client. Allows you to collect latency data from |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param Trace[] $traces The trace logs to send. | ||
| * @param array $options [optional] Configuration Options | ||
| * @return bool | ||
| * @throws ServiceException |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * This plain PHP class represents a Trace resource. For more information see | ||
| * [TraceResource](https://cloud.google.com/trace/docs/reference/v1/rest/v1/projects.traces#resource-trace) | ||
| */ | ||
| class Trace |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| ] + $options); | ||
|
|
||
| if (empty($trace)) { | ||
| throw new NotFoundException('Trace ID does not exist', 404); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@dwsupplee @jdpedrie I'm working on part 2 (nice client context handling for building traces) in a separate branch with a PR into this branch here: chingor13#3. I'm not sure how you want to handle merging/releasing it - take the APIs first, then have a separate PR for part 2, or merge part 2 into the API branch and take it as one big PR. |
|
@dwsupplee @jdpedrie Is there anything else we need for the trace apis? |
|
The travis error seems to be a random failure to install php 7.1 |
|
@dwsupplee @jdpedrie Do we need anything else to proceed here? |
|
We should probably get a trace repo going so we can release this as an individual component as well. @bshaffer would you be able to assist with that? :) |
|
The ball was started on that. We will follow up on its creation this week. I wasn't envisioning releasing the trace library separately until the integration part 2 was ready (blocked by this PR as well as the AsyncBatchRunner) |
|
Sounds good. The code looks good to me, so ready to merge as long as everything looks good to @jdpedrie as well. |
|
That is fine by me. We need to temporarily remove |
…ce repo is available
This PR includes only the REST interface for the Google Cloud Trace. It does not include the nice context tracking integration points for developers to use.