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

Allow run a trace in a closure #273

Closed
wants to merge 2 commits into from

Conversation

cschneider
Copy link
Contributor

@cschneider cschneider commented Nov 11, 2016

See issue #270

Copy link
Member

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

I like the exploration, though not crazy about the impl, yet. I think looking at before/after in unit tests might make it more clear what we're gaining.

@@ -8,6 +8,9 @@
import zipkin.Constants;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.function.Function;
Copy link
Member

Choose a reason for hiding this comment

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

this is java 8 (and we are java 6)... I think this import will break animal sniffer unless it is excluded

startNewSpan(component, operation);
return callable.call();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
Copy link
Member

Choose a reason for hiding this comment

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

if something throws an exception, you should probably propagate it vs wrap

Copy link
Contributor 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 Callable.call throws Exception. If I propagate this I force people to catch it. I can improve this though to not wrap RuntimeException.

startNewSpan(component, operation);
runable.run();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
Copy link
Member

Choose a reason for hiding this comment

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

iirc Runnable doesn't have declared exceptions, so this will just wrap runtime exceptions in another runtime exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes .. This is wrong. I will remove the catch.

@cschneider
Copy link
Contributor Author

I pushed a new commit now that should fix the issues.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Dec 4, 2016 via email

@cschneider
Copy link
Contributor Author

I chose Callable and Runable as they are pre Java 8 interfaces. So people can already use closures if they run on Java8 but Brave itself does not have to depend on Java 8.
I think we could define a custom interface like Callable but without "throws Exception". If you prefer this then I can change the PR.
Typically I try to avoid creating new interfaces if there is an existing one as people then depend on something proprietary. In case of brave this should be no problem as people need to depend on brave core anyway.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Dec 5, 2016 via email

@cschneider
Copy link
Contributor Author

I dont think we need to support other lambda types. When you use lambdas java automatically detects if there is a compatble interface. Runnable supports the case when there is no return and Callable supports the case were there is one. Try it by using lambdas. It should work fine.

We could use composition but I fail to see how that makes things simpler.
Of course my change adds two methods to LocalTracer. Is that a problem?

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Dec 7, 2016 via email

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Dec 7, 2016 via email

codefromthecrypt pushed a commit that referenced this pull request Dec 7, 2016
There have been a number of issues where I've needed to clarify why a specific
change isn't ready or shouldn't be merged. The rules of engagement, and their
rationale, shouldn't require me, as I didn't start Brave and may not be around forever!

My hope is that by stating things like how change works in the root folder, we can
avoid some back and forth due to previously unwritten expectations.

Using rule-of-three for this change :) Here are five issues where I've basically restated the contents above manually. I'd really like to use my time and the time of contributors towards shared change, since in both cases it is a scarce resource.

#273 #265 #238  #226 #194
@codefromthecrypt
Copy link
Member

ps I opened this to hopefully help with things like this in the future #287

on this change specifically, key point is that we needs others vouching for this feature because elaborating it is expensive.

Elaboration is beyond just choices around types to expose and whether or not to play animal sniffer games to allow them. More importantly, it adds error handling to the scope of local tracer.. something it currently doesn't have because it doesn't attempt to trace closures.

A lot of change that I've asked folks to elaborate on eventually gets in, we owe it to the project to not add debt and rather add things that take it away.

@cschneider
Copy link
Contributor Author

That is fine. Thanks for explaining. Btw. I think it is very good to manage the API like you do. I see feature bloat a lot in apache projects and it is difficult to fight there.

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Dec 7, 2016 via email

@cschneider
Copy link
Contributor Author

Do you think about something like this?

Instead of using LocalTracer like this:
Runnable:
localtracer.runInSpan("MyCompoent", "Myoperation", () -> someCoede())
Callable:
myResult = localtracer.runInSpan("MyCompoent", "Myoperation", () -> { someCode(); return "result"})

We would have a separate class like this:
FunctionalTracer tracer = new FunctionalTracer(brave, "MyComponent");

Runnable:
tracer.span("MyOperation", () -> someCoede());
Callable:
myResult = tracer.span("Myoperation", () -> { someCode(); return "result"})

@codefromthecrypt
Copy link
Member

codefromthecrypt commented Dec 7, 2016 via email

@cschneider
Copy link
Contributor Author

I agreed with Adrian to first prototype the closure support in my own project. So if you are interested in this watch this repository.

I will close the PR and open a new one once there is a good protype and some interest from the brave community for it.

@cschneider cschneider closed this Dec 7, 2016
codefromthecrypt pushed a commit that referenced this pull request Dec 10, 2016
There have been a number of issues where I've needed to clarify why a specific
change isn't ready or shouldn't be merged. The rules of engagement, and their
rationale, shouldn't require me, as I didn't start Brave and may not be around forever!

My hope is that by stating things like how change works in the root folder, we can
avoid some back and forth due to previously unwritten expectations.

Using rule-of-three for this change :) Here are five issues where I've basically restated the contents above manually. I'd really like to use my time and the time of contributors towards shared change, since in both cases it is a scarce resource.

#273 #265 #238  #226 #194
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.

2 participants