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

Add inject_context and current_context #78

Merged
merged 4 commits into from
Sep 15, 2018
Merged

Add inject_context and current_context #78

merged 4 commits into from
Sep 15, 2018

Conversation

GregMefford
Copy link
Member

@GregMefford GregMefford commented Sep 14, 2018

Adds APIs for current_context (to allow people to get access to a SpanContext based on the current span context) and inject_context to simplify adding distributed tracing headers to HTTP calls.

This somewhat-unfortunately also required an update to the Adapter behaviour, so I've also got a PR to SpandexDatadog queued up (spandex-project/spandex_datadog#6).

@@ -622,8 +646,10 @@ defmodule Spandex.Test.SpandexTest do
|> Plug.Test.conn("/")
|> Plug.Conn.put_req_header("x-test-trace-id", "1234")
|> Plug.Conn.put_req_header("x-test-parent-id", "5678")
|> Plug.Conn.put_req_header("x-test-sampling-priority", "10")

Choose a reason for hiding this comment

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

Nested modules could be aliased at the top of the invoking module.

opts = @base_opts ++ @span_opts
assert {:ok, %Trace{id: trace_id}} = Spandex.start_trace("root_span", opts)
assert {:ok, %Span{id: span_id}} = Spandex.start_span("span_name", @base_opts)
assert {:ok, %SpanContext{trace_id: ^trace_id, parent_id: ^span_id}} = Spandex.current_context(@base_opts)

Choose a reason for hiding this comment

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

Line is too long (max is 100, was 112).

lib/spandex.ex Outdated
def current_context(opts) do
strategy = opts[:strategy]
case strategy.get_trace(opts[:trace_key]) do
{:ok, %Trace{id: trace_id, priority: priority, baggage: baggage, stack: [%Span{id: span_id} | _]}} ->

Choose a reason for hiding this comment

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

Line is too long (max is 100, was 107).

lib/spandex.ex Outdated
strategy = opts[:strategy]
case strategy.get_trace(opts[:trace_key]) do
{:ok, %Trace{id: trace_id, priority: priority, baggage: baggage, stack: [%Span{id: span_id} | _]}} ->
{:ok, %SpanContext{trace_id: trace_id, priority: priority, baggage: baggage, parent_id: span_id}}

Choose a reason for hiding this comment

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

Line is too long (max is 100, was 105).

@@ -6,6 +6,7 @@ defmodule Spandex.Adapter do
@callback distributed_context(Plug.Conn.t(), Keyword.t()) ::
{:ok, Spandex.SpanContext.t()}
| {:error, atom()}
@callback inject_context(Spandex.headers(), Spandex.SpanContext.t(), Keyword.t()) :: Spandex.headers()

Choose a reason for hiding this comment

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

Line is too long (max is 100, was 104).

@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).
  • 1 fixed issue! 🎉

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


case strategy.get_trace(opts[:trace_key]) do
{:ok, %Trace{id: trace_id, priority: priority, baggage: baggage, stack: [%Span{id: span_id} | _]}} ->
{:ok, %SpanContext{trace_id: trace_id, priority: priority, baggage: baggage, parent_id: span_id}}

Choose a reason for hiding this comment

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

Line is too long (max is 100, was 105).

@coveralls
Copy link

coveralls commented Sep 14, 2018

Pull Request Test Coverage Report for Build 348

  • 8 of 9 (88.89%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 82.329%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/support/adapter.ex 4 5 80.0%
Totals Coverage Status
Change from base Build 340: 0.2%
Covered Lines: 205
Relevant Lines: 249

💛 - Coveralls

@GregMefford
Copy link
Member Author

Ok, I think this PR is ready to merge. If you think these last commits are good, I can hit the button and then work on a release-prep PR for 2.3.0 so that I can bump the version requirement in spandex_datadog.

@zachdaniel zachdaniel merged commit bfe65b5 into master Sep 15, 2018
@GregMefford GregMefford deleted the inject_context branch September 15, 2018 16:31
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.

3 participants