Skip to content

Stackdriver Trace API - #388

Merged
dwsupplee merged 40 commits into
googleapis:masterfrom
chingor13:trace_only_api
Apr 18, 2017
Merged

Stackdriver Trace API#388
dwsupplee merged 40 commits into
googleapis:masterfrom
chingor13:trace_only_api

Conversation

@chingor13

Copy link
Copy Markdown
Contributor

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.

Implements basic Trace and TraceSpan resources.

TraceClient tests

Fix tests. Connection needed to be protected

Code style fixes
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 7, 2017

@jdpedrie jdpedrie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! Hope these comments aren't coming too early in your process.

Comment thread src/Trace/Trace.php Outdated
*/
public function __construct(array $options)
{
$this->projectId = $options['projectId'];

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/Trace/Trace.php
*
* @param TraceSpan[] $spans
*/
public function setSpans(array $spans)

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php Outdated
* @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.

Comment thread src/Trace/TraceSpan.php
*
* @return array
*/
public function info()

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/Trace/TraceSpan.php Outdated
* @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.

Comment thread src/Trace/TraceSpan.php Outdated
*
* @param array $labels Labels in the form of $label => $value
*/
public function addLabels($labels)

This comment was marked as spam.

* limitations under the License.
*/

namespace Google\Cloud\Tests\Trace\Connection;

This comment was marked as spam.

This comment was marked as spam.

@jdpedrie jdpedrie added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 8, 2017
@jdpedrie

jdpedrie commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

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?

@chingor13

Copy link
Copy Markdown
Contributor Author

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

@jdpedrie

Copy link
Copy Markdown
Contributor

Make sure you rebase against upstream/master to get the component split changes. Most of the classes that moved are going to be in Google\Cloud\Core.

@chingor13 chingor13 changed the title WIP: Stackdriver Trace API Stackdriver Trace API Mar 16, 2017
@chingor13

chingor13 commented Mar 16, 2017

Copy link
Copy Markdown
Contributor Author

@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

Comment thread src/Trace/Trace.php Outdated
/**
* Retrieves the spans for this trace.
*
* @return array

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php Outdated
*
* @return string
*/
public function projectId()

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php Outdated
]);

if (empty($trace)) {
throw new NotFoundException('Trace ID does not exist', 404);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php
}

/**
* 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.

Comment thread src/Trace/TraceClient.php Outdated
* @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.

Comment thread src/Trace/TraceSpan.php Outdated
* @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.

Comment thread src/Trace/TraceSpan.php Outdated
* **Defaults to** now.
* @return string
*/
private function formatDate($when = null)

This comment was marked as spam.

Comment thread tests/system/Trace/BasicTest.php Outdated
$span2 = new TraceSpan(['name' => 'inner', 'parentSpanId' => $span->spanId()]);
$span2->setStart();

usleep(20000);

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/ServiceBuilder.php Outdated
*
* @param array $config [optional] Configuration options. See
* {@see Google\Cloud\ServiceBuilder::__construct()} for the available options.
* @return StorageClient

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php Outdated
* @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.

Comment thread src/Trace/TraceClient.php Outdated
* @return Trace
* @throws ServiceException
*/
public function getTrace($traceId)

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php
/**
* Fetch all traces in the project
*
* @param array $options [optional] {

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php Outdated
* @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.

Comment thread src/Trace/TraceClient.php
* '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.

Comment thread src/Trace/TraceClient.php Outdated
* 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.

Comment thread src/Trace/Trace.php
*
* @param TraceSpan[] $spans
*/
public function setSpans(array $spans)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dwsupplee

Copy link
Copy Markdown
Contributor

Sorry for any overlapping items that @jdpedrie may have pointed out. I didn't notice his review items until after I had just posted.

@dwsupplee dwsupplee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Comment thread src/Trace/TraceClient.php
* }
* @return ItemIterator<Trace>
*/
public function traces(array $options = [])

This comment was marked as spam.

Comment thread src/Trace/TraceSpan.php
* Associative array containing all the fields representing this TraceSpan.
* @var array
*/
private $info;

This comment was marked as spam.

Comment thread src/Trace/TraceSpan.php
'kind' => self::SPAN_KIND_UNSPECIFIED
];

if (!array_key_exists('spanId', $this->info)) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread src/Trace/TraceSpan.php Outdated
*/
private function generateSpanName()
{
// FIXME: clean backtrace rather than guessing the stack depth

This comment was marked as spam.

use Rize\UriTemplate;

/**
* @group translate

This comment was marked as spam.

use Google\Cloud\Trace\TraceSpan;
use Google\Cloud\Trace\Trace;

class BasicTest extends \PHPUnit_Framework_TestCase

This comment was marked as spam.

Comment thread src/Trace/TraceSpan.php
$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.

Comment thread src/Trace/TraceClient.php Outdated
use Google\Cloud\Trace\Connection\Rest;

/**
* Google Stackdriver Trace client. Allows you to collect latency data from

This comment was marked as spam.

Comment thread src/Trace/TraceClient.php Outdated
* @param Trace[] $traces The trace logs to send.
* @param array $options [optional] Configuration Options
* @return bool
* @throws ServiceException

This comment was marked as spam.

Comment thread src/Trace/Trace.php
* 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.

Comment thread src/Trace/Trace.php
] + $options);

if (empty($trace)) {
throw new NotFoundException('Trace ID does not exist', 404);

This comment was marked as spam.

@chingor13

Copy link
Copy Markdown
Contributor Author

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

@chingor13

Copy link
Copy Markdown
Contributor Author

@dwsupplee @jdpedrie Is there anything else we need for the trace apis?

@chingor13

Copy link
Copy Markdown
Contributor Author

The travis error seems to be a random failure to install php 7.1

@chingor13

Copy link
Copy Markdown
Contributor Author

@dwsupplee @jdpedrie Do we need anything else to proceed here?

@dwsupplee

Copy link
Copy Markdown
Contributor

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? :)

@chingor13

chingor13 commented Apr 18, 2017

Copy link
Copy Markdown
Contributor Author

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)

@dwsupplee

Copy link
Copy Markdown
Contributor

Sounds good. The code looks good to me, so ready to merge as long as everything looks good to @jdpedrie as well.

@jdpedrie

Copy link
Copy Markdown
Contributor

That is fine by me. We need to temporarily remove src/Trace/composer.json (or rename it, perhaps, composer.json.temp?) in order to prevent the release build from attempting to push to a repository that does not exist. After that, I'm fine with it being merged!

@dwsupplee dwsupplee removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 18, 2017
@dwsupplee
dwsupplee merged commit 5e1320f into googleapis:master Apr 18, 2017
@chingor13
chingor13 deleted the trace_only_api branch April 18, 2017 18:40
tmatsuo pushed a commit that referenced this pull request Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants