-
Notifications
You must be signed in to change notification settings - Fork 652
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: add is_recording_events #141
Changes from all commits
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 |
---|---|---|
|
@@ -284,6 +284,8 @@ def get_context(self): | |
|
||
def set_attribute(self, key: str, value: types.AttributeValue) -> None: | ||
with self._lock: | ||
if not self.is_recording_events(): | ||
return | ||
has_ended = self.end_time is not None | ||
if not has_ended: | ||
if self.attributes is Span.empty_attributes: | ||
|
@@ -302,6 +304,8 @@ def add_event( | |
|
||
def add_lazy_event(self, event: trace_api.Event) -> None: | ||
with self._lock: | ||
if not self.is_recording_events(): | ||
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. As long as we always return 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. Well, I just wanted to put that logic in place regardless the value that is returned by I am not sure if we can move those checks outside the lock, so I preferred to stay in the safe side and leave them inside. |
||
return | ||
has_ended = self.end_time is not None | ||
if not has_ended: | ||
if self.events is Span.empty_events: | ||
|
@@ -322,6 +326,8 @@ def add_link( | |
|
||
def add_lazy_link(self, link: "trace_api.Link") -> None: | ||
with self._lock: | ||
if not self.is_recording_events(): | ||
return | ||
has_ended = self.end_time is not None | ||
if not has_ended: | ||
if self.links is Span.empty_links: | ||
|
@@ -333,6 +339,8 @@ def add_lazy_link(self, link: "trace_api.Link") -> None: | |
|
||
def start(self): | ||
with self._lock: | ||
if not self.is_recording_events(): | ||
return | ||
has_started = self.start_time is not None | ||
if not has_started: | ||
self.start_time = util.time_ns() | ||
|
@@ -343,6 +351,8 @@ def start(self): | |
|
||
def end(self): | ||
with self._lock: | ||
if not self.is_recording_events(): | ||
return | ||
if self.start_time is None: | ||
raise RuntimeError("Calling end() on a not started span.") | ||
has_ended = self.end_time is not None | ||
|
@@ -362,6 +372,9 @@ def update_name(self, name: str) -> None: | |
return | ||
self.name = name | ||
Oberon00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def is_recording_events(self) -> bool: | ||
return True | ||
|
||
|
||
def generate_span_id(): | ||
"""Get a new random span ID. | ||
|
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.
You should return a boolean value (most likely
False
) here too. I wonder why mypy didn't catch this. 🤔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.
mmm, so what about
opentelemetry-python/opentelemetry-api/src/opentelemetry/trace/__init__.py
Line 136 in be7577d
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.
Seems also wrong.
EDIT: I created #142.