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

[#60] Changes the API for the In process context propagation #61

Merged
merged 2 commits into from
Apr 13, 2018

Conversation

jcchavezs
Copy link
Collaborator

@jcchavezs jcchavezs commented Apr 12, 2018

Read #61 for more context

Short description of what this PR does:

  • Changes the Tracer::startActiveSpan signature to return a scope.
  • Changes the ScopeManager to not to be aware of spans

This is a breaking change but since we are still in beta, it is OK.

Checklist

  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the [Contribution Guide] and my PR follows them.
  • I updated my branch with the master branch.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation about the functionality in the appropriate .md file
  • I have added in line documentation to the code I modified

Fixes #61

Ping @beberlei @yurishkuro @ellisv @tedsuo

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

overall looks reasoanable

README.md Outdated
@@ -112,10 +112,11 @@ $root = $tracer->startActiveSpan('php');

$http = $tracer->startActiveSpan('http');
file_get_contents('http://php.net');
Copy link
Member

Choose a reason for hiding this comment

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

I think this example is promoting bad naming practice. root and http should really be called scope, and they should be in different syntax scopes (not sure if php allows that - if not, best to introduce a function in the example)

README.md Outdated
@@ -246,6 +247,8 @@ SpanOptions wrapper object. The following keys are valid:
- `child_of` is an object of type `OpenTracing\SpanContext` or `OpenTracing\Span`.
- `references` is an array of `OpenTracing\Reference`.
- `tags` is an array with string keys and scalar values that represent OpenTracing tags.
- `finish_span_on_close` is a boolean that determines whether a span should be finished when the
scope is closed or not.
Copy link
Member

Choose a reason for hiding this comment

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

move "or not" after "finished"

{
$this->scopes[] = new MockScope($this, $span);
$scope = new MockScope($this, $span, $finishSpanOnClose);
$this->scopes[] = $scope;
Copy link
Member

Choose a reason for hiding this comment

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

not familiar with php syntax - what does this mean? looks like assigning scalar to array.

Copy link
Contributor

Choose a reason for hiding this comment

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

This means to append entry to an array

@@ -20,7 +20,7 @@ public function getScopeManager();
* Tracer::getScopeManager()->getActive()->getSpan(),
* and null will be returned if {@link Scope#active()} is null.
*
* @return Span|null
* @return ScopedSpan|null
Copy link
Contributor

Choose a reason for hiding this comment

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

ScopedSpan class does not exist. It should return a Span.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Totally. I was playing around with the idea of having such a thing but I decided to not to in the end.

@jcchavezs
Copy link
Collaborator Author

@yurishkuro @ellisv I fixed your comments.

@jcchavezs jcchavezs merged commit 19591d4 into master Apr 13, 2018
@jcchavezs jcchavezs deleted the 60_changes_in_ipcp branch April 13, 2018 13:38
@beberlei
Copy link
Contributor

beberlei commented Apr 18, 2018

Sorry for commenting so late. I actually proposed the previous API, because i feel returning the scope makes for a bad API. You always grab the span from it to call additional stuff and its a constant law of demeter violation with complicated code.

PHP is single threaded, request based shared nothing. This is different to all other OT languages so far. So i felt it warranted a different API. In addition PHP doesn't have a with keyword like python/java, making the scope so weird, and $scope->close() is not called automatically.

The default, 90% use case for clients of this library would be the API:

$span = $tracer->startActiveSpan(...);
$span->annotate(...);
//..
$span->annotate(...);
$span->finish($closeOnFinish = true);

now its going to be:

$scope = $tracer->startActiveSpan(...);
$scope->getSpan()->annotate(...);
//..
$scope->getSpan()->annotate(...);
$scope->close($finishOnClose = true);

@ellisv
Copy link
Contributor

ellisv commented Apr 19, 2018

In previous case having a scope was unecessary at all in my opinion as it was never exposed to the user and may confuse implementors. That is why I opened #55. Instead we could have removed scope concept at all and left Tracer::getActiveSpan() for implementors to implement in which ever way they want. Or something like

interface SpanManager
{
    public function activate(Span $span): void;
    public function getActive(): Span;
}

Or put activateSpan() on Tracer itself.

So in my opinion we can turn two ways:

  • Implement the way it is done on Java and Python by exposing Scope to the user
  • Do not have Scopes at all

@jcchavezs
Copy link
Collaborator Author

So I did this implementation three times under three different vendors (mock tracer, datadog and zipkin) I can share my experiences with this:

  1. The previous API (that I endorsed) had a circular dependency between Span and Scope (both being aware of each other).
  2. It was confusing who had the responsibility to finish a span after a scope.
  3. ScopeManager was quite useless.

In the other hand, I agree with most of @beberlei's points as returning a Scope has some inconveniences.

At some point I came up with this approach of having a ScopedSpan which would be wrapping both a Scope and Span and implement both interfaces. That approach felt quite good until you did ScopeManager::activate which forced you to create a new object:

$scopedSpan = $tracer->getScopeManager()->activate($span);
$scopedSpan->tag(....)

So I backed off. To be honest this is not an inconvenience because ScopeSpan would carry the existing span + when doing activating you always need to keep track of the scope if you want to avoid the circular dependency.

I would go for the ScopedSpan, feels more natural for me.

Thoughts @beberlei @yurishkuro @ellisv

@yurishkuro
Copy link
Member

I just opened this issue as it was on my mind recently. If it's decided in favor of ScopeContext then the notion of the Scope will probably need to be preserved.

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