Initial support for explicit Span parent support.#33
Initial support for explicit Span parent support.#33reyang merged 7 commits intoopen-telemetry:masterfrom
Conversation
| """Constant used to represent the current span being used as a parent. | ||
| This is the default behavior when creating spans. | ||
| """ | ||
| CURRENT_SPAN = object() |
There was a problem hiding this comment.
Consider _CURRENT_SPAN if this is meant to be used inside this file.
There was a problem hiding this comment.
I think exposing this constant is fine, but maybe the name may be a bit misleading in a broader context. Maybe name it CURRENT_SPAN_AS_PARENT?
Actually we need to expose it, as API implementations will need to compare against it.
There was a problem hiding this comment.
One more point: This will not typecheck (CURRENT_SPAN does not have type Span). We should use typing.NewType to create a dummy type for this object and then accept that type in the functions that support CURRENT_SPAN (in a typing.Union).
There was a problem hiding this comment.
Actually we need to expose it, as API implementations will need to compare against it.
Correct. My initial thought had been to hide it but we have to expose it ;)
And yes, we can use typing.NewType for this. But I'm actually thinking we could simply try to use the Java approach here, by having a specific default/no-op Span that will effectively act as such dummy. Will update the PR ;)
c24t
left a comment
There was a problem hiding this comment.
Using a sentinel for the span kwarg is a great solution, and does make for a nice API.
It took me a few passes to understand that CURRENT_SPAN wasn't meant to be the actual span, if other people find this confusing we might want to call it something else.
|
|
||
| """Constant used to represent the current span being used as a parent. | ||
| This is the default behavior when creating spans. | ||
| """ |
There was a problem hiding this comment.
| """ | |
| # Constant used to represent the current span being used as a parent. This | |
| # is the default behavior when creating spans. | |
There was a problem hiding this comment.
The Sphinx syntax for documentation comments uses #:
|
|
||
| """Constant used to represent the current span being used as a parent. | ||
| This is the default behavior when creating spans. | ||
| """ |
There was a problem hiding this comment.
The Sphinx syntax for documentation comments uses #:
| """Constant used to represent the current span being used as a parent. | ||
| This is the default behavior when creating spans. | ||
| """ | ||
| CURRENT_SPAN = object() |
There was a problem hiding this comment.
I think exposing this constant is fine, but maybe the name may be a bit misleading in a broader context. Maybe name it CURRENT_SPAN_AS_PARENT?
Actually we need to expose it, as API implementations will need to compare against it.
| def start_span(self, name: str, parent: 'Span') -> Iterator['Span']: | ||
| def start_span(self, | ||
| name: str, | ||
| parent: 'Span' = CURRENT_SPAN) -> Iterator['Span']: |
There was a problem hiding this comment.
Nit: Normally you don't put spaces around the = in a default argument, but I don't know how the situation is with type annotations.
There was a problem hiding this comment.
Same, was not sure about how things work with annotations (had barely used them before ;) )
Hope we can get a linter enabled soon :)
There was a problem hiding this comment.
This is right! And pylint actually does report on this if you remove the spaces:
opentelemetry/trace/__init__.py:95:33: C0326: Exactly one space required around keyword argument assignment
parent: 'Span'=CURRENT_SPAN) -> Iterator['Span']:
^ (bad-whitespace)
| Applications that need to create spans detached from the tracer's | ||
| context should use this method. | ||
|
|
||
| with tracer.start_span(name) as span: |
There was a problem hiding this comment.
I think this sample code is a copy & paste error. It should probably not be here (although it made more sense when the paragraph talking about use_span was directly before it).
There was a problem hiding this comment.
Was wondering the same.
| """Constant used to represent the current span being used as a parent. | ||
| This is the default behavior when creating spans. | ||
| """ | ||
| CURRENT_SPAN = object() |
There was a problem hiding this comment.
One more point: This will not typecheck (CURRENT_SPAN does not have type Span). We should use typing.NewType to create a dummy type for this object and then accept that type in the functions that support CURRENT_SPAN (in a typing.Union).
Agreed. |
|
Hey hey - I've updated the PR, but the part regarding My initial idea was to move |
|
I vote for keeping them in the same module and moving Some other benefits:
We had the opposite experience in OC. One of the original sins of OC-python was that some features were transliterated straight from java, including a bunch of classes that (as in java) each got their own file. As the implementations drifted apart to better suit each language, the fact that the two projects had similar structure became more confusing than helpful since assumptions from one project didn't always carry over to the other. I may be biased in seeing single-class modules as "java-like" and multiple-class modules as pythonic, but in my experience modules -- like namespaces -- are one of the nice features of the language, and make for a more easily comprehensible project. |
Lets use this one for now then. If/when we feel we need a different way, we can go for it.
Interesting point. In any case, lets then keep what we have now ;) |
Co-Authored-By: Chris Kleinknecht <libc@google.com>
Co-Authored-By: Chris Kleinknecht <libc@google.com>
Specifically for CURRENT_SPAN usage.
|
Hey, I've updated the code so now Two items remain, and they should do as separated PRs in my opinion:
Let me know. If all is fine, I will go ahead and merge this PR. |
Addresses #23
It uses a new public constant
CURRENT_SPANto signal that the default parent is the currentSpan.I applied the same logic to
create_span, to have uniformity. OC Java, for example, allows users to start aSpanas either the current instance or not, and both implicitly used the previous currentSpanas parent. We also had this in OT Python and it worked fine.Opinions on this last change?