-
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
Make span attributes inaccessible except when needed [WIP] #1501
Make span attributes inaccessible except when needed [WIP] #1501
Conversation
@Oberon00 I attempted to apply your suggestion in issue to store the current ReadWrite Span inside the _data property of a new Span class and only give access to attributes when needed after collection has ended in an export cycle in the PR linked above. This solution works great to allows the span_processor and exporters to access attributes without exposing them to the public, but there are very large amount of tests that create spans using the |
I think there is no way around touching all tests here, as preventing easy access is the whole point of the PR. |
@@ -411,6 +411,104 @@ def __new__(cls, *args, **kwargs): | |||
raise TypeError("Span must be instantiated via a tracer.") | |||
return super().__new__(cls) | |||
|
|||
def __init__( |
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.
Maybe construct the _ReadWriteSpan
at the call site and only pass that one in to avoid duplicating the long parameter list.
I left a comment in the other issue, but if the discussion is happening here:
There really isn't a great solution to only exposing interface attributes to some consumers (exporters) but not others (application consumers). In addition, I think that distinction doesn't really matter practically speaking, as owners of opentelemetry exporters or other components that interoperate with the SDK need some sort of API to retrieve values for non-application related operations. So I'd suggest just exposing getters. Really I'd go a step further and remove the ReadWrite span class altogether, and just modify sdk.Span to be the ReadWrite span (add getter methods, make variables protected). |
Wouldn't adding getters to the existing Span defeat the purpose of limiting access to span attributes in normal use cases? Getters is essentially signalling that span attributes are meant to be accessed. The current implementation without any of my change already allows users to access read/write 'span.attributes' as they please which seems to be the issue highlighted. |
Yes. Although I would argue that no matter what, you're giving code that is outside of the core package access to span attributes. And not having that access method match idiomatic python would be an issue. I understand the spec is effectively trying to say that such getters should only be available to those who want to extend the instrumentation (via exporters, for example), and not to the "application" author. So I believe there are three cases:
The current PR IIUC does:
So how does one determine attributes on _data that are private to the package? In addition, the current mechanism of accessing such attributes (using a protected (underscore) variable name) is unidiomatic, and it can lead to SDK extenders thinking that any such attribute on the span is usable by SDK extenders in this fashion. I worry that setting the precedent means that further difficulties in modifying the SDK, since they will start to rely on other protected variables in the span. |
Without looking at the PR in full: My idea was that the access to So exporters/span processors are handed the value of |
The exception to this would be unit tests (unless we want to go a more complex route and switch them to use an in-memory exporter or capture the ReadWriteSpan in on_start in a SpanProcessor). That's why I'd suggest providing a underscore-less method in some test package that gets the |
Would it be better if I leave the issue as is for now for further discussion or if I manually update the tests? My internship will be ending tomorrow, and I did not want to leave the remaining issue I had assigned hanging. |
I do agree with yusuke that having a span with different access writes come out start_span and end_span and accessing |
Description
Attempting to discourage accessing Span Attributes outside the SDK using the method suggested by @Oberon00.
Fixes #1001
How Has This Been Tested?
This is currently failing tests and is a work in progress. The pull request has only been opened as a draft for feedback on the method.