-
Notifications
You must be signed in to change notification settings - Fork 666
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
Implementations MUST NOT allow callers to create Spans directly #1000
Comments
Do we provide any APIs other than the tracer to create spans currently? I'd be nice to point that out for anyone taking this on as the first issue. |
Hi, can I take this issue? |
I believe the most Pythonic way would be to simply document that the caller does not instantiate Spans themselves and have them face the consequences of breaking the trust rather than strictly enforcing it in this case. The sdk Span already documents this. We could also add this to the Span api docstring or just close this issue outright? |
Hmm it won't strictly enforce it, but it would definitely make it almost impossible to unintentionally instantiate Span directly. Sounds good to me. |
Looking at the implementation now, I'm wondering if we would have to add this for all classes that we'd expect to instantiate via the api rather than directly the constructor (all classes in metrics pretty much). Would it be worth it to do all that or should we simply go with the documentation route? Thoughts? @codeboten @aabmass |
I just want to raise another alternative of using Python "private" underscores (which is essentially documentation) to tell the user not to instantiate directly, but still allow easily overriding this for our testing purposes. For type annotations, we can expose a # opentelemetry/sdk/trace/__init__.py
from typing import NewType
# make it "private"
class _Span(trace_api.Span):
# everything the same as before
# ...
pass
# "public" API for typing purposes
Span = NewType('Span', _Span)
class Tracer(trace_api.Tracer):
def start_span(self, ...) -> Span:
# .. same as before except
return Span(_Span(...)) A user trying to call |
@aabmass |
There is a problem with handling typing with NewType. An instance of type |
Looking at that pylint issue, it looks like it gives false positives for all NewTypes? By casting do you mean
Hmm that sounds like a deal breaker for NewType 🙁 |
Another option might be to have the import abc
class Span(trace_api.Span, ABC):
# current span class we have + this to make it uninstantiable
@abc.abstractmethod
def __dummy(self):
pass
# This one is used internally and for tests, can actually be instantiated
class _Span(Span):
def __dummy(self):
pass |
That could work, the abstract |
If you move the implementation of those methods to |
To be compliant with the tracing spec, implementations MUST NOT allow callers to create Spans directly
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#span
The text was updated successfully, but these errors were encountered: