-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
0d5d912
to
e983dfc
Compare
src/OpenTracing/ActiveSpanSource.php
Outdated
* @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); |
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.
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.
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.
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.
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.
$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.
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.
@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.
src/OpenTracing/NoopTracer.php
Outdated
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function startActiveSpan( | ||
$operationName, | ||
SpanReference $parentReference = null, |
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.
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.
src/OpenTracing/ActiveSpanSource.php
Outdated
* @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); |
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.
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.
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.
$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.
src/OpenTracing/SpanOptions.php
Outdated
@@ -33,6 +43,14 @@ public static function create(array $options) | |||
|
|||
foreach ($options as $key => $value) { | |||
switch ($key) { | |||
case 'is_active': |
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.
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(); |
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.
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.
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.
I tried to avoid all get
s in the code. If there is any around I will open a PR changing them.
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.
@jcchavezs you mentioned you consider get/set anti patterns, I'm curious why? It certainly is common in PHP libraries
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.
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')
.
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.
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?)
1d004e4
to
f78fd8e
Compare
@beberlei @felixfbecker I just addressed your comments. |
b174bf3
to
d7d4b97
Compare
src/OpenTracing/Span.php
Outdated
@@ -15,10 +15,13 @@ public function operationName(); | |||
public function context(); | |||
|
|||
/** | |||
* Finishes the span and locks it so it becomes immutable. As an implementor, make |
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.
I believe this is a necessary recommendation, does it make sense?
@beberlei @felixfbecker
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.
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.
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.
That was the intention, how would you reword it?
d6e206c
to
b8a3ec3
Compare
README.md
Outdated
use OpenTracing\SpanReference\ChildOf; | ||
use OpenTracing\SpanReference\ChildOf; | ||
|
||
$parent = GlobalTracer::globalTracer()->startManualSpan('parent'); $child = GlobalTracer::globalTracer()->startManualSpan('child', [ |
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.
theres a weird line break here
... | ||
$child->finish(); | ||
... | ||
$parent->finish(); |
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.
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'); ... |
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.
indentation
src/OpenTracing/ActiveSpanSource.php
Outdated
* | ||
* @return Span | ||
*/ | ||
public function activeSpan(); |
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.
should be getActiveSpan()
b8a3ec3
to
307a5fa
Compare
@@ -25,6 +25,13 @@ | |||
const FORMAT_HTTP_HEADERS = 3; | |||
|
|||
/** | |||
* @deprecated use either startActiveSpan or startManualSpan instead. |
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.
Imo the initial official version shouldn't have anything deprecated.
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.
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.
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.
what is the reason for that?
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 |
I don't fully understand what is referred to by "refcounting". Does that apply to PHP? |
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 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 What do you think @felixfbecker, @beberlei & @tedsuo? PS: I am not sure if we might mention the |
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. |
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? |
PLEASE CONTINUE THE DISCUSSION AT opentracing/opentracing-php#2 |
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