Skip to content

Conversation

@liyanhui1228
Copy link
Contributor

@liyanhui1228 liyanhui1228 commented Jun 20, 2017

Implemented the veneer layer of the trace library based on the auto-generated code. This will provide the trace and span context managers and simplify the API for users who want to manually instrument their code. Sample usage in the gist: https://gist.github.com/liyanhui1228/20ac515d74e134ea39b0e63a9d0524bf

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 20, 2017
Copy link
Contributor

@theacodes theacodes left a comment

Choose a reason for hiding this comment

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

This looks mostly good to me from a design perspective, I defer to @dhermes for style review.

We'll also need some tests.

# limitations under the License.

from pkg_resources import get_distribution
__version__ = get_distribution('google-cloud-trace').version

This comment was marked as spam.

This comment was marked as spam.


"""GAX Wrapper for interacting with the Stackdriver Trace API."""

from google.cloud.gapic.trace.v1.trace_service_client import (

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.

This comment was marked as spam.

self,
name,
kind=Enum.SpanKind.SPAN_KIND_UNSPECIFIED,
parent_span_id=None,

This comment was marked as spam.

This comment was marked as spam.

@liyanhui1228 liyanhui1228 requested a review from dhermes June 20, 2017 16:46
from google.cloud.trace.trace_span import TraceSpan


__all__ = ['_TraceAPI', 'Client', 'Trace', 'TraceSpan']

This comment was marked as spam.

This comment was marked as spam.


"""GAX Wrapper for interacting with the Stackdriver Trace API."""

from google.cloud.gapic.trace.v1.trace_service_client import (

This comment was marked as spam.

return GAXIterator(self.client, page_iter, item_to_value)


def _parse_trace_pb(trace_pb):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

raise


def _item_to_mapping(iterator, trace_pb):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,65 @@
# Copyright 2017 Google Inc.

This comment was marked as spam.

This comment was marked as spam.

return int(span_id)


def format_span_json(span):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

:returns: Identifier for the span. Must be a 64-bit integer other
than 0 and unique within a trace. Converted to string.
"""
span_id = str(random.getrandbits(64))

This comment was marked as spam.

This comment was marked as spam.


from datetime import datetime

PROJECT = 'PROJECT'

This comment was marked as spam.

This comment was marked as spam.

None, None, None, None, None, None, None))


class _DummyTraceAPI(object):

This comment was marked as spam.

This comment was marked as spam.

self.assertIs(trace_api.client, client)


class _GAXTraceAPI(_GAXBaseAPI):

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.

@theacodes theacodes added the api: cloudtrace Issues related to the Cloud Trace API. label Jun 26, 2017
@liyanhui1228
Copy link
Contributor Author

Ready for another review.

return GAXIterator(self.client, page_iter, item_to_value)


def _parse_trace_pb(trace_pb):

This comment was marked as spam.

raise


def _item_to_mapping(iterator, trace_pb):

This comment was marked as spam.

def __init__(self, client, project_id=None, trace_id=None):
self.client = client

if project_id is None:

This comment was marked as spam.

@theacodes
Copy link
Contributor

@lukesneeringer @dhermes this mostly looks good to me. I have a few outstanding questions for you two and I would like one of y'all to do a final review.

@@ -1,5 +1,6 @@
include README.rst LICENSE
global-include *.json
recursive-include unit_tests *

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.

:rtype: str
:returns: 32 digits randomly generated trace ID.
"""
trace_id = str(uuid.uuid4()).replace('-', '')

This comment was marked as spam.

This comment was marked as spam.

:returns: Identifier for the span. Must be a 64-bit integer other
than 0 and unique within a trace. Converted to string.
"""
span_id = uuid.uuid4().int & (1 << 64)-1

This comment was marked as spam.

This comment was marked as spam.

return self._get_target_class()(*args, **kw)


class Test__TraceAPI(_Base, unittest.TestCase):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

self.assertIs(trace_api.client, client)


class _GAXTraceAPI(_GAXBaseAPI):

This comment was marked as spam.

@liyanhui1228
Copy link
Contributor Author

liyanhui1228 commented Jun 27, 2017

@duggelz Should be the first one, actually the order doesn't matter. As long as we patch a list of spans to the trace API, the cloud trace console will show the trace graph according to the parent_span_id in each span.

@liyanhui1228
Copy link
Contributor Author

Ready for another review.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Jun 29, 2017
@liyanhui1228 liyanhui1228 force-pushed the trace-manual branch 2 times, most recently from cd4a01e to 992c749 Compare June 30, 2017 00:54
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Jun 30, 2017
@liyanhui1228
Copy link
Contributor Author

@lukesneeringer Can I merge this to the auto-gen branch now? Or wait for the autogen code to be updated?

@lukesneeringer lukesneeringer merged commit 57160b2 into trace-autogen Jul 25, 2017
@dhermes dhermes deleted the trace-manual branch August 2, 2017 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: cloudtrace Issues related to the Cloud Trace API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants