Skip to content
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

Span creation in tracer SDK #69

Merged
merged 12 commits into from
Aug 6, 2019
Merged

Conversation

c24t
Copy link
Member

@c24t c24t commented Jul 30, 2019

This PR adds span creation methods to the Tracer SDK. See test_start_span_implicit and test_start_span_explicit for examples of how this should work.

This uses a module-level context variable for now, I'll replace it with our own context API in a separate PR. It also sets a global module-level tracer which doesn't square with the existing loader logic, also to be replaced in a follow-up PR.

@c24t c24t added sdk Affects the SDK package. trace labels Jul 30, 2019
traceoptions: 'TraceOptions' = None,
tracestate: 'TraceState' = None
) -> None:
if traceoptions is None:
Copy link
Member

Choose a reason for hiding this comment

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

According to the current specification, we need to have traceOptions.

Copy link
Member

Choose a reason for hiding this comment

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

Or trace_options, either way looks weird though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the spec is meant to dictate internal names like this, especially since it's clear what this field represents. In any case we'll follow the W3C spec when the class gets serialized.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's more about "do we treat traceoptions as a single word or not" rather than "do we take the name strictly from the spec".
The W3C spec is using two words, having traceoptions is against Python naming convention.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair. I prefer traceoptions/state but agree it's more consistent to split the words up. Changed in 0f52732.

@c24t c24t force-pushed the span-creation-sdk branch 3 times, most recently from 9dc8118 to b64e873 Compare July 31, 2019 00:24
@c24t c24t force-pushed the span-creation-sdk branch from b64e873 to 89f1a0c Compare July 31, 2019 00:33
Returns:
A random 64-bit int for use as a span ID
"""
return random.getrandbits(64)
Copy link
Member

Choose a reason for hiding this comment

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

We might need to move this into API if we plan to support the "default behavior" in https://github.com/w3c/trace-context/blob/master/spec/20-http_header_format.md#mutating-the-traceparent-field.
We can explore this later, no need to block this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Besides what @reyang commented: I remember we kept this private in Java, to not have use this as a defacto standard for creating span ids. Something to consider?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have a strong opinion here, and think the bar for making things private is generally a lot lower in java than python. But since we don't have a convention for marking the SDK's "API", hiding everything we don't expect users to call may be a good idea.

That said, if someone is calling into the SDK package instead of just using the API they're already voiding the warranty...

@c24t c24t force-pushed the span-creation-sdk branch from 0f52732 to 7a796e1 Compare August 5, 2019 19:42
@toumorokoshi
Copy link
Member

LGTM!

trace_options: 'TraceOptions' = None,
trace_state: 'TraceState' = None
) -> None:
if trace_options is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

+1


import typing

AttributeValue = typing.Union[str, bool, float]
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Event = namedtuple('Event', ('name', 'attributes'))

Link = namedtuple('Link', ('context', 'attributes'))


class Span(trace_api.Span):
"""See `opentelemetry.trace.Span`.

Users should generally create `Span`s via the `Tracer` instead of this
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should highlight this in a stronger tone - I'd really disliked users creating Spans directly (unless you guys have a specific reason/case in mind).

Copy link
Member Author

Choose a reason for hiding this comment

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

No specific use case, how about removing "generally"?

return random.getrandbits(64)


def generate_trace_id():
Copy link
Contributor

Choose a reason for hiding this comment

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

(Same as generate_span_id)

"""

def __init__(self,
cv: 'contextvars.ContextVar' = _CURRENT_SPAN_CV
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using the context-propagation layer? Will that happen in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'll do that in another PR.

@carlosalberto
Copy link
Contributor

Hey @c24t !

Left a few comments - minor feedback, but overall it looks very neat!

@c24t c24t merged commit 42415ba into open-telemetry:master Aug 6, 2019
@c24t c24t deleted the span-creation-sdk branch August 6, 2019 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk Affects the SDK package.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants