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 integration test #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
use Mix.Config

if Mix.env() == :test do
config :opencensus,
send_interval_ms: 1,
reporters: [{Opencensus.Absinthe.TestSupport.SpanCaptureReporter, []}]
end

config :logger,
backends: [:console],
level: :warn
13 changes: 13 additions & 0 deletions lib/opencensus/absinthe/middleware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@ defmodule Opencensus.Absinthe.Middleware do
end

@doc false
@spec on_complete(Resolution.t(), span_ctx: :opencensus.span_ctx()) :: Resolution.t()
def on_complete(%{state: :resolved} = resolution, span_ctx: span_ctx) do
# credo:disable-for-next-line
error_count = length(resolution.errors)
status = if error_count == 0, do: "ok", else: "error"

:oc_trace.put_attributes(
%{
"absinthe.field.resolution_error_count" => error_count,
"absinthe.field.resolution_status" => status
},
span_ctx
)

:oc_trace.finish_span(span_ctx)
resolution
end
Expand Down
23 changes: 22 additions & 1 deletion lib/opencensus/absinthe/phase/pop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,32 @@ defmodule Opencensus.Absinthe.Phase.Pop do

alias Absinthe.Blueprint
alias Absinthe.Phase
alias Opencensus.Absinthe.Acc

@impl true
@spec run(Blueprint.t(), keyword()) :: Phase.result_t()
def run(blueprint, _opts \\ []) do
:ocp.finish_span()
acc = Acc.get(blueprint)

{status, error_count} =
case blueprint do
%{result: %{errors: errors}} -> {:error, length(errors)}
_ -> {:ok, 0}
end

:oc_trace.put_attributes(
%{
"absinthe.blueprint.error_count" => error_count,
"absinthe.blueprint.status" => Atom.to_string(status)
},
acc.span_ctx
)

# Finish our span, even if it isn't current:
:oc_trace.finish_span(acc.span_ctx)
# Restore our parent span:
:ocp.with_span_ctx(acc.parent_span_ctx)

{:ok, blueprint}
end
end
11 changes: 9 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Opencensus.Absinthe.MixProject do
dialyzer: dialyzer(),
docs: docs(),
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
package: package(),
preferred_cli_env: [
coveralls: :test,
Expand All @@ -36,6 +37,9 @@ defmodule Opencensus.Absinthe.MixProject do
]
end

defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

defp package() do
[
licenses: ["Apache 2.0"],
Expand All @@ -54,13 +58,16 @@ defmodule Opencensus.Absinthe.MixProject do
{:absinthe_plug, "~> 1.4.0", optional: true},
{:credo, "~> 1.1.0", only: :test},
{:dialyxir, "~> 1.0.0-rc.6", only: :dev, runtime: false},
{:ex_doc, ">= 0.0.0", only: :docs},
{:ex_doc, ">= 0.0.0", only: [:docs, :test]},
{:excoveralls, "~> 0.11.1", only: :test},
{:inch_ex, "~> 2.0.0", only: :docs},
{:jason, "~> 1.0", only: [:docs, :test]},
{:licensir, "~> 0.4.0", only: :test},
{:mix_test_watch, "~> 0.8", only: :test},
{:opencensus, "~> 0.9.2"},
{:opencensus_elixir, "~> 0.4.0"}
{:opencensus_elixir, "~> 0.4.0"},
Copy link
Contributor

Choose a reason for hiding this comment

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

In general I prefer to rely on Erlang library itself, as a way to avoid dependency problems, like opencensus_elixir lagging behind.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm with you, but I'm also averse to copy-paste maintenance. The only alternative is dragging the responsibility to the core package, which has had response time problems in the past and excludes any help from Elixir developers. Strikes me as especially odd to do when the problem is had by the Elixir developers e.g. Logger.metadata sync and friendlier ways to get to the contents of the records. Some of that'll go away depending on @tsloughter's new behaviour design. Some won't.

{:opencensus_plug, "~> 0.3", only: :test},
{:telemetry, "~> 0.4"}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"opencensus": {:hex, :opencensus, "0.9.2", "ab36b0c4e4500b976180bd088cea7520d345711a72df2d7188e2d7b9573a8728", [:rebar3], [{:counters, "~> 0.2.1", [hex: :counters, repo: "hexpm", optional: false]}, {:ctx, "~> 0.5", [hex: :ctx, repo: "hexpm", optional: false]}, {:wts, "~> 0.3", [hex: :wts, repo: "hexpm", optional: false]}], "hexpm"},
"opencensus_elixir": {:hex, :opencensus_elixir, "0.4.0", "ac00f3b027841ba47ad8a9205c442c2e5473c1ffeb45e9c2569cccd5d35fa814", [:mix], [{:opencensus, "~> 0.9", [hex: :opencensus, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"opencensus_plug": {:hex, :opencensus_plug, "0.3.0", "ff04bdd59c39dee66fc56086e9300818325afe184a2e8919a8bb47912ad5164c", [:mix], [{:opencensus, "~> 0.9", [hex: :opencensus, repo: "hexpm", optional: false]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"plug": {:hex, :plug, "1.8.2", "0bcce1daa420f189a6491f3940cc77ea7fb1919761175c9c3b59800d897440fc", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
Expand Down
Loading