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

standardize return types from strategies (and by proxy from Spandex) #62

Merged
merged 2 commits into from Aug 27, 2018

Conversation

zachdaniel
Copy link
Member

@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.

@zachdaniel
Copy link
Member Author

My auto formatter made a few changes, but they are trivial. This PR also changes opts[:tracer] to opts[:trace_key] which makes it a bit more informative (not much) as to what that key is for. Its really just a way to have multiple traces running at the same time. So if you wanted only one trace, and you didn't want to use a tracer, you could just do Spandex.start_trace("hello") and everything would work fine (the trace_key would just be nil). You only have to care about trace_key if you want more than one active trace at a time, at which point you'd say Spandex.start_trace("hello", trace_key: "foobar")

@zachdaniel
Copy link
Member Author

@GregMefford if you could take a look, that would be great!

Copy link
Member

@GregMefford GregMefford left a 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}
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Lets do it 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion :)

@zachdaniel
Copy link
Member Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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]
})
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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

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

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

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

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

@zachdaniel
Copy link
Member Author

@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).

@zachdaniel zachdaniel force-pushed the standardize-strategy-return-types branch from 45f3f38 to 29dd221 Compare August 27, 2018 15:40
@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 4 possible new issues (including those that may have been commented here).

You can see more details about this review at https://ebertapp.io/github/spandex-project/spandex/pulls/62.

@coveralls
Copy link

coveralls commented Aug 27, 2018

Pull Request Test Coverage Report for Build 317

  • 29 of 35 (82.86%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.3%) to 82.278%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/spandex.ex 25 31 80.65%
Totals Coverage Status
Change from base Build 313: -1.3%
Covered Lines: 195
Relevant Lines: 237

💛 - Coveralls

@zachdaniel zachdaniel merged commit d9e2040 into master Aug 27, 2018
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.

None yet

3 participants