-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
standardize return types from strategies (and by proxy from Spandex) #62
Conversation
c05087b
to
7397212
Compare
My auto formatter made a few changes, but they are trivial. This PR also changes |
@GregMefford if you could take a look, that would be great! |
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.
This looks good other than the proposal/question about splitting out another @callback
in the Strategy
behaviour. 👍
I'm surprised that your formatter did something different than mine, unless you're not using plain old mix format
. Maybe I forgot to run mine after the last round of tweaks.
lib/strategy.ex
Outdated
@@ -6,7 +6,7 @@ defmodule Spandex.Strategy do | |||
|
|||
alias Spandex.Trace | |||
|
|||
@callback get_trace(tracer) :: Trace.t() | nil | |||
@callback get_trace(tracer) :: {:ok, Trace.t() | nil} | {:error, term} |
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 do you think about adding another @callback trace_active?(tracer)
function that would return a true
/false
, since that's mostly what Spandex
ends up doing with the return value of this function. It might be possible to more-efficiently implement that function and avoid a little work in many cases where the result ends up not getting used.
If we were to do that, I'd propose that we return {:error, :no_trace_context}
here instead of {:ok, nil}
when there's no active trace, given that you'd only call this function when you actually expect to use the result.
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.
Lets do it 👍
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.
Great suggestion :)
I'm pretty sure it should just be the plain mix format + the .formatter.exs of the project. If not, it would have shortened the lines. Would be nice to get travis figured out and just check formatting in PR. Still haven't figured out how on earth to actually get the github apps/marketplace version of travis CI running against this org. |
|
||
trace -> | ||
{:error, _} = error -> | ||
error |
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.
Since this kind of error would be up to the Strategy
, maybe we should have something like:
{:error, reason} ->
Logger.error("Failed to start span: #{reason}")
{:error, reason}
do_update_span(trace, opts, top?) | ||
|
||
{:error, _} = error -> | ||
error |
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.
Same thing about logging an error here.
strategy.put_trace(opts[:trace_key], %{trace | stack: new_stack, spans: new_spans}) | ||
|
||
{:error, _} = error -> | ||
error |
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.
Same thing about logging an error here.
strategy.delete_trace(opts[:trace_key]) | ||
|
||
{:error, _} = error -> | ||
error |
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.
Same thing about logging an error here.
{:ok, finished_span} | ||
|
||
{:error, _} = error -> | ||
error |
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.
Same thing about logging an error here.
lib/spandex.ex
Outdated
trace | ||
| stack: tail, | ||
spans: [finished_span | spans] | ||
}) |
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 see the purpose of having _ = ...
at the beginning of the line here.
Also, this formatting seems kind of weird to me, but it might only be doing that because of the _ =
making it want to use multiple lines.
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 have a really strict dialyzer configuration in my work projects, which includes "no unmatched returns" so thats just a holdover from the way I'm used to working. I didn't mean to add it back in after you removed them, it just happened from resolving merge conflicts I think.
lib/spandex.ex
Outdated
@@ -289,7 +320,8 @@ defmodule Spandex do | |||
adapter = opts[:adapter] | |||
|
|||
with {:ok, span} <- Span.child_of(current_span, name, adapter.span_id(), adapter.now(), opts), | |||
{:ok, _trace} <- strategy.put_trace(opts[:tracer], %{trace | stack: [span | trace.stack]}) do | |||
{:ok, _trace} <- | |||
strategy.put_trace(opts[:trace_key], %{trace | stack: [span | trace.stack]}) do |
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.
When I pull this branch and run mix format
, it puts this line back to the way it was before this PR. Maybe your formatter isn't picking up the config file that allows 120 characters?
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, I think something is up with my editor.
span | ||
|
||
{:error, _} -> | ||
# TODO: Alter the return type of this interface to allow for returning |
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.
TODO found
id | ||
|
||
{:error, _} -> | ||
# TODO: Alter the return type of this interface to allow for returning |
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.
TODO found
span | ||
|
||
{:error, _} -> | ||
# TODO: Alter the return type of this interface to allow for returning |
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.
Found a TODO tag in a comment: # TODO: Alter the return type of this interface to allow for returning
id | ||
|
||
{:error, _} -> | ||
# TODO: Alter the return type of this interface to allow for returning |
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.
Found a TODO tag in a comment: # TODO: Alter the return type of this interface to allow for returning
@GregMefford WRT to the logging, I’m not sure we should favor having logging in place at the moment. At least not without a toggle for the level and/or a toggle to turn it on/off. At scale, logging can be a significant bottleneck for many applications, and if there is a problem with their spandex configuration, we don’t want to have a bunch of log statements. Basically we just need some way to ensure that spandex isn’t going to log 10 additional times per request (which is a pretty conservative number of spans that a lot of people might have in a given request). |
45f3f38
to
29dd221
Compare
Ebert has finished reviewing this Pull Request and has found:
You can see more details about this review at https://ebertapp.io/github/spandex-project/spandex/pulls/62. |
Pull Request Test Coverage Report for Build 317
💛 - Coveralls |
@GregMefford mentioned that a lot of the return types in the inner parts (and some of the public interface) were not conventional. This updates the ones from the strategy behaviour to follow that convention, and adapts much of the spandex code to handle that.