-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implemented trace library based on the autogen, gax only #3513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
theacodes
left a comment
There was a problem hiding this 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.
trace/google/cloud/trace/__init__.py
Outdated
| # 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
trace/google/cloud/trace/_gax.py
Outdated
|
|
||
| """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.
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.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self, | ||
| name, | ||
| kind=Enum.SpanKind.SPAN_KIND_UNSPECIFIED, | ||
| parent_span_id=None, |
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.
trace/google/cloud/trace/__init__.py
Outdated
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
trace/google/cloud/trace/_gax.py
Outdated
|
|
||
| """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.
Sorry, something went wrong.
| 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.
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.
| raise | ||
|
|
||
|
|
||
| def _item_to_mapping(iterator, trace_pb): |
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.
trace/google/cloud/trace/_helper.py
Outdated
| @@ -0,0 +1,65 @@ | |||
| # Copyright 2017 Google Inc. | |||
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 int(span_id) | ||
|
|
||
|
|
||
| def format_span_json(span): |
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.
| :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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
trace/tests/unit/test__gax.py
Outdated
|
|
||
| from datetime import datetime | ||
|
|
||
| PROJECT = 'PROJECT' |
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.
trace/tests/unit/test_client.py
Outdated
| None, None, None, None, None, None, None)) | ||
|
|
||
|
|
||
| class _DummyTraceAPI(object): |
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.
trace/tests/unit/test__gax.py
Outdated
| self.assertIs(trace_api.client, client) | ||
|
|
||
|
|
||
| class _GAXTraceAPI(_GAXBaseAPI): |
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.
|
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.
This comment was marked as spam.
Sorry, something went wrong.
| raise | ||
|
|
||
|
|
||
| def _item_to_mapping(iterator, trace_pb): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| def __init__(self, client, project_id=None, trace_id=None): | ||
| self.client = client | ||
|
|
||
| if project_id is None: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@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. |
trace/MANIFEST.in
Outdated
| @@ -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.
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.
trace/google/cloud/trace/trace.py
Outdated
| :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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| :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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
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.
trace/tests/unit/test__gax.py
Outdated
| self.assertIs(trace_api.client, client) | ||
|
|
||
|
|
||
| class _GAXTraceAPI(_GAXBaseAPI): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@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. |
|
Ready for another review. |
|
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 |
cd4a01e to
992c749
Compare
|
CLAs look good, thanks! |
|
@lukesneeringer Can I merge this to the auto-gen branch now? Or wait for the autogen code to be updated? |
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