-
Notifications
You must be signed in to change notification settings - Fork 778
Span: add attribute, event, link setter to the API #83
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
Changes from all commits
8f4f3ee
a923472
ee756c8
19a6985
fd5f45e
4c40110
6091ad7
5aec9fa
cf6f4c4
02f258d
950f5aa
ca6a36f
f2a4674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,7 @@ | |||||
| import typing | ||||||
|
|
||||||
| from opentelemetry import loader | ||||||
| from opentelemetry import types | ||||||
|
|
||||||
| # TODO: quarantine | ||||||
| ParentSpan = typing.Optional[typing.Union['Span', 'SpanContext']] | ||||||
|
|
@@ -102,6 +103,35 @@ def get_context(self) -> 'SpanContext': | |||||
| A :class:`.SpanContext` with a copy of this span's immutable state. | ||||||
| """ | ||||||
|
|
||||||
| def set_attribute(self: 'Span', | ||||||
| key: str, | ||||||
| value: types.AttributeValue, | ||||||
| ) -> None: | ||||||
| """Sets an Attribute. | ||||||
|
|
||||||
| Sets a single Attribute with the key and value passed as arguments. | ||||||
| """ | ||||||
|
|
||||||
| def add_event(self: 'Span', | ||||||
| name: str, | ||||||
| attributes: types.Attributes = None, | ||||||
| ) -> None: | ||||||
| """Adds an Event. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One open question is whether the caller ever needs access to the events or links they create (in which case we need the classes in the API) or if we should treat them as part of the implementation of these methods.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's best to start out with the API that exposes as few details as possible.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two places where I've seen Makes me feel we should include these |
||||||
|
|
||||||
| Adds a single Event with the name and, optionally, attributes passed | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have an explicit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment, we don't. We have the following But that's in the SDK, not exposed in the API. |
||||||
| as arguments. | ||||||
| """ | ||||||
|
|
||||||
| def add_link(self: 'Span', | ||||||
| link_target_context: 'SpanContext', | ||||||
| attributes: types.Attributes = None, | ||||||
| ) -> None: | ||||||
| """Adds a Link to another span. | ||||||
|
|
||||||
| Adds a single Link from this Span to another Span identified by the | ||||||
| `SpanContext` passed as argument. | ||||||
| """ | ||||||
|
|
||||||
|
|
||||||
| class TraceOptions(int): | ||||||
| """A bitmask that represents options specific to the trace. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,27 +230,31 @@ def get_context(self): | |
|
|
||
| def set_attribute(self: 'Span', | ||
| key: str, | ||
| value: 'types.AttributeValue' | ||
| value: types.AttributeValue, | ||
| ) -> None: | ||
| if self.attributes is Span.empty_attributes: | ||
| self.attributes = BoundedDict(MAX_NUM_ATTRIBUTES) | ||
| self.attributes[key] = value | ||
|
|
||
| def add_event(self: 'Span', | ||
| name: str, | ||
| attributes: 'types.Attributes', | ||
| attributes: types.Attributes = None, | ||
| ) -> None: | ||
| if self.events is Span.empty_events: | ||
| self.events = BoundedList(MAX_NUM_EVENTS) | ||
| if attributes is None: | ||
| attributes = Span.empty_attributes | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It somewhat irks me that we can't use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially tried to use and I read recommendations to use |
||
| self.events.append(Event(name, attributes)) | ||
|
|
||
| def add_link(self: 'Span', | ||
| context: 'trace_api.SpanContext', | ||
| attributes: 'types.Attributes', | ||
| link_target_context: 'trace_api.SpanContext', | ||
| attributes: types.Attributes = None, | ||
| ) -> None: | ||
| if self.links is Span.empty_links: | ||
| self.links = BoundedList(MAX_NUM_LINKS) | ||
| self.links.append(Link(context, attributes)) | ||
| if attributes is None: | ||
| attributes = Span.empty_attributes | ||
| self.links.append(Link(link_target_context, attributes)) | ||
|
|
||
| def start(self): | ||
| if self.start_time is None: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.