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

Adds activeSpanSource #22

Closed
wants to merge 2 commits into from
Closed

Adds activeSpanSource #22

wants to merge 2 commits into from

Conversation

jcchavezs
Copy link
Owner

@jcchavezs jcchavezs commented Jun 15, 2017

CONTINUE THE DISCUSSION in opentracing/opentracing-php#2

This is related to the in_process_propagation from: opentracing/opentracing-python#52

The specification context is "In-process propagation" discussed in this issue opentracing/specification#23, already for Java and in PR for Python.

Ping @jcchavezs @felixfbecker @tedsuo @beberlei

@jcchavezs jcchavezs force-pushed the in_process_propagation branch from 0d5d912 to e983dfc Compare June 15, 2017 10:55
* @param string|array $threads Use only in case of async operations. Allows you to keep
* an span as active in different threads.
*/
public function activate(Span $span, $threads = self::THREAD_DEFAULT);
Copy link
Owner Author

@jcchavezs jcchavezs Jun 15, 2017

Choose a reason for hiding this comment

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

I was not so sure about this. I thought about having this interface and then two implementations: AsyncActiveSpanSource and ActiveSpanSource but they are conceptually two different use cases and consequently two different method signatures which is not allowed for interfaces.

We can of course cheat by using func_get_args but I am not so sure about that being a good idea. I'd like the code to be more descriptive.

Choose a reason for hiding this comment

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

Putting the concepts of threads into this sounds weird given that PHP is completely single-threaded and there is no reliable cross-platform thread extension as far as I know.

Copy link
Owner Author

Choose a reason for hiding this comment

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

$thread is actually an identificator, nothing to do with runtime concept. My initial idea was to use something like tag but that concept is already in use.

Choose a reason for hiding this comment

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

@jcchavezs but how do independent third party libraries coordinate on what identification to use? That is unsolved, but it is actually solved by the ActiveSpanSource itself, providing $threads from outside into API just breaks that encapsulation.

/**
* {@inheritdoc}
*/
public function startActiveSpan(
$operationName,
SpanReference $parentReference = null,

Choose a reason for hiding this comment

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

Active Span needs no reference anymore, and this being the second argument will lead to users having startActiveSpan('op1', null, ...);

Why is there no array of options anymore? Ruby and Python have a list of arguments as well, but both languages support named arguments, so they could do startActiveSpan('op1', tags=['foo' => 'bar']); which PHP cannot do.

* @param string|array $threads Use only in case of async operations. Allows you to keep
* an span as active in different threads.
*/
public function activate(Span $span, $threads = self::THREAD_DEFAULT);

Choose a reason for hiding this comment

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

The use of $threads make no sense to me, because you assume that at every location in the code, it knows what its own thread id is. You cannot guarantee this.

In addition it puts the responsibility for the thread selection to the client, but the client doesn't necessary know what kind of threading context it is in. The ActiveSpanSource should now and the python implementation PR has examples how custom ActiveSpanSources handle this internally, not expose this to the client.

I am against this approach.

Copy link
Owner Author

Choose a reason for hiding this comment

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

$thread is actually an identificator, nothing to do with runtime concept. My initial idea was to use something like tag but that concept is already in use. Anyways this was just a try to deal with asynchronous difficulties. Thanks for the feedback tho.

@@ -33,6 +43,14 @@ public static function create(array $options)

foreach ($options as $key => $value) {
switch ($key) {
case 'is_active':

Choose a reason for hiding this comment

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

The SpanOptions are for creating spans from the client POV. In that context is active or not is implicitly set by the call to either startActiveSpan or startManualSPan, so having this flag on options is redundant.

/**
* @return ActiveSpanSource
*/
public function activeSpanSource();

Choose a reason for hiding this comment

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

the coding style is inconsistent, some places use get*, this place here does not. It looks like a direct translation from python, where this is a coding convention.

Copy link
Owner Author

@jcchavezs jcchavezs Jun 15, 2017

Choose a reason for hiding this comment

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

I tried to avoid all gets in the code. If there is any around I will open a PR changing them.

Choose a reason for hiding this comment

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

@jcchavezs you mentioned you consider get/set anti patterns, I'm curious why? It certainly is common in PHP libraries

Copy link
Owner Author

@jcchavezs jcchavezs Jul 6, 2017

Choose a reason for hiding this comment

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

Based on the changes on #30 I will change the methods here to use get prefixes. About setters, as I expressed before (somewhere) I prefer meaningful methods like $object->doSomethingYouUnderstand() rather than $object->setYourStateTo($whatever) (for example, ->activate() over ->setStatus('active').

Copy link

@felixfbecker felixfbecker Jul 6, 2017

Choose a reason for hiding this comment

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

yeah, totally agree with meaningful method names like activate(), as long as they are verbs. E.g. activeSpanSource is not a verb and therefor gives no real indication what it does (does it return the value? or does it set it? or both, like jQuery?)

@jcchavezs jcchavezs force-pushed the in_process_propagation branch 2 times, most recently from 1d004e4 to f78fd8e Compare June 15, 2017 14:13
@jcchavezs
Copy link
Owner Author

@beberlei @felixfbecker I just addressed your comments.

@jcchavezs jcchavezs force-pushed the in_process_propagation branch 2 times, most recently from b174bf3 to d7d4b97 Compare June 15, 2017 17:06
@@ -15,10 +15,13 @@ public function operationName();
public function context();

/**
* Finishes the span and locks it so it becomes immutable. As an implementor, make
Copy link
Owner Author

Choose a reason for hiding this comment

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

I believe this is a necessary recommendation, does it make sense?
@beberlei @felixfbecker

Choose a reason for hiding this comment

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

I don't think it has to "lock" it (as in all methods now throw exceptions), but I read that after finish() you should not use the Span anymore.

Copy link
Owner Author

Choose a reason for hiding this comment

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

That was the intention, how would you reword it?

@jcchavezs jcchavezs force-pushed the in_process_propagation branch 2 times, most recently from d6e206c to b8a3ec3 Compare June 15, 2017 21:17
README.md Outdated
use OpenTracing\SpanReference\ChildOf;
use OpenTracing\SpanReference\ChildOf;

$parent = GlobalTracer::globalTracer()->startManualSpan('parent'); $child = GlobalTracer::globalTracer()->startManualSpan('child', [

Choose a reason for hiding this comment

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

theres a weird line break here

...
$child->finish();
...
$parent->finish();

Choose a reason for hiding this comment

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

shouldn't finish() always be called in a finally?

README.md Outdated
Every new span will take the active span as parent and it will take its spot.

```php
$parent = GlobalTracer::globalTracer()->startManualSpan('parent'); ...

Choose a reason for hiding this comment

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

indentation

*
* @return Span
*/
public function activeSpan();

Choose a reason for hiding this comment

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

should be getActiveSpan()

@jcchavezs jcchavezs force-pushed the in_process_propagation branch from b8a3ec3 to 307a5fa Compare July 12, 2017 07:39
@@ -25,6 +25,13 @@
const FORMAT_HTTP_HEADERS = 3;

/**
* @deprecated use either startActiveSpan or startManualSpan instead.

Choose a reason for hiding this comment

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

Imo the initial official version shouldn't have anything deprecated.

Copy link
Owner Author

Choose a reason for hiding this comment

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

The problem is that we'd prefer the python one to be released before merging this one so either we wait or either we release the library without the active span record.

Choose a reason for hiding this comment

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

what is the reason for that?

@tedsuo
Copy link

tedsuo commented Jul 15, 2017

There is some discussion of ActiveSpan API in Java right now, might want to hold off and coordinate with where that is going: opentracing/specification#80

@felixfbecker
Copy link

I don't fully understand what is referred to by "refcounting". Does that apply to PHP?

@jcchavezs
Copy link
Owner Author

As pointed out by @tedsuo there are some discussions about this feature in opentracing/specification#80. After a long read through the issue and its replies, my thoughts are that the reference counting is not an issue for us because in PHP everything happens in one request and there is no way to modify the context by other requests so whether we implement refcounting for auto-finishing or not, that won't be a big problem for us. What is true is that auto-finishing is something desirable by some implementors.

In the other hand I do believe there is not a consensus about this among implementations. @bhs might come up with a solution for this (according to opentracing/specification#80 (comment)) but my feeling is that this concept is not defined enough so I would hold for that meaning that I'd launch the library without including ActiveSpanSource for now.

What do you think @felixfbecker, @beberlei & @tedsuo?

PS: I am not sure if we might mention the Continuation and capture concepts that come up in the Java and python implementation. This is something we don't need (IMO) since there is only one thread and the span lifecycle is scoped on the request but I think that should be written somewhere so a developer coming from one of this libraries is aware of that.\

@felixfbecker
Copy link

felixfbecker commented Jul 15, 2017

in PHP everything happens in one request and there is no way to modify the context by other requests

that is not entirely true, please keep in mind that PHP can be used in more contexts than just as a SAPI module (i.e. not just as an Apache/nginx request handler). PHP can be used to build long-running RPC server processes, for example with an event loop. However, the event loop use case can be solved by integrating into the event loop. PHP is single-threaded, so there is no chance of two pieces of code running at the same time and modifying the active span.

Not sure if that is what "refcounting" does, but PHP has destructors. I.e. Span can have a method __destruct() that can call finish() when the GC destroys the span cause there are no references to it anymore. Not sure whether we would want that cause the time GC run is not guaranteed and therefor destructors are really bad for time-relevant operations like finishing a span.

@jcchavezs
Copy link
Owner Author

Agree @felixfbecker but even in that case, every thread of PHP is closed to the others.

As far as I understand, the main point with the refcounting (and I think it is not the refcounting itself but the way the refcounting is being done) is the possibility of an span to be kept opened by other thread without doing anything, that is not our case (I think) so as I said, this is not something that would concern us but I do believe we should wait on this PR until there is an agreement, does it makes sense to you?

@jcchavezs
Copy link
Owner Author

PLEASE CONTINUE THE DISCUSSION AT opentracing/opentracing-php#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants