Skip to content
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 and SpanContext implementation #58

Merged
merged 10 commits into from
Jul 25, 2019
Merged

Conversation

c24t
Copy link
Member

@c24t c24t commented Jul 18, 2019

Breaking this off of the larger tracer SDK PR for discussion. See the OC span definition and java Span implementations: DefaultSpan in the API and RecordEventsReadableSpan in the SDK.

@c24t c24t added the WIP Work in progress label Jul 18, 2019
from collections import Sequence


MAX_NUM_ATTRIBUTES = 32
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These might move to the exporters, see open-telemetry/opentelemetry-specification#182.

@c24t c24t mentioned this pull request Jul 19, 2019
return len(self._dq)

def __iter__(self):
return iter(self._dq)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we intend to handle RuntimeError: deque mutated during iteration or leave it as caller responsibility?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making a defensive copy? 7836995

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given most of the built-in collections throw exception when changes happened while iterating, it is fine to leave it. Unless we want this __iter__ to be bulletproof. I asked this question just to confirm this is what we intend.

BTW, what is 7836995?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7836995

Catching this in the exporter (where we'd iterate through these lists) would be odd since the spans should be finished at that point, but I think it's better to make these bulletproof than risk the unhandled exception later.

AttributeValue = typing.Union[str, bool, float]


class BoundedList(Sequence):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is likely to be used in metrics/logs as well, we might need to extract it to a common place. Probably not in this PR though.

MAX_NUM_ATTRIBUTES, attributes)

if events is None:
self.events = BoundedList(MAX_NUM_EVENTS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have concrete measurement today, but I suspect it could be pretty expensive if most spans have no attributes/events/links.
Consider create a class variable Span.copy_on_write_bounded_list/dict and assign it as the default value. Allocate the real object when there are actual write operation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 87cac92, although it's probably worth profiling before making too many optimizations like this.

import time

try:
time_ns = time.time_ns # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider this time_ns = getattr(time, 'time_ns', lambda: int(time.time() * 1e9).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you like that better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably due to my background in C++ where people generally believe that exceptions are much heavier than conditional statement. I don't have strong preference here (as performance won't have a noticeable difference, it is mainly a matter of personal taste), up to you.

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@reyang
Copy link
Member

reyang commented Jul 23, 2019

@Kami would be great to have your feedback here. Thanks.

@c24t c24t merged commit 8a453ee into open-telemetry:master Jul 25, 2019
@c24t c24t deleted the add-span branch July 25, 2019 00:19
@lzchen lzchen mentioned this pull request Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants