-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLATFORM-991]: graphql.request.query and graphql.request.variables a…
…re not extracted (#83)
- Loading branch information
Showing
11 changed files
with
347 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule OpentelemetryAbsintheTest.Configuration do | ||
use OpentelemetryAbsintheTest.Case | ||
|
||
alias OpentelemetryAbsintheTest.Support.GraphQL.Queries | ||
alias OpentelemetryAbsintheTest.Support.Query | ||
|
||
doctest OpentelemetryAbsinthe.Instrumentation | ||
|
||
describe "trace configuration" do | ||
test "records all graphql stuff in attributes by default" do | ||
OpentelemetryAbsinthe.Instrumentation.setup() | ||
|
||
attributes = Query.query_for_attrs(Queries.query(), variables: %{"isbn" => "A1"}) | ||
|
||
assert [ | ||
"graphql.request.query", | ||
"graphql.request.selections", | ||
"graphql.request.variables", | ||
"graphql.response.errors", | ||
"graphql.response.result" | ||
] = attributes |> Map.keys() |> Enum.sort() | ||
end | ||
|
||
test "gives options provided via application env have precedence over defaults" do | ||
Application.put_env(:opentelemetry_absinthe, :trace_options, | ||
trace_request_query: false, | ||
trace_response_result: false | ||
) | ||
|
||
OpentelemetryAbsinthe.Instrumentation.setup() | ||
attributes = Query.query_for_attrs(Queries.query(), variables: %{"isbn" => "A1"}) | ||
|
||
assert [ | ||
"graphql.request.selections", | ||
"graphql.request.variables", | ||
"graphql.response.errors" | ||
] = attributes |> Map.keys() |> Enum.sort() | ||
end | ||
|
||
test "gives options provided to setup() precedence over defaults and application env" do | ||
Application.put_env(:opentelemetry_absinthe, :trace_options, | ||
trace_request_query: false, | ||
trace_response_result: false | ||
) | ||
|
||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_query: true) | ||
attributes = Query.query_for_attrs(Queries.query(), variables: %{"isbn" => "A1"}) | ||
|
||
assert [ | ||
"graphql.request.query", | ||
"graphql.request.selections", | ||
"graphql.request.variables", | ||
"graphql.response.errors" | ||
] = attributes |> Map.keys() |> Enum.sort() | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
defmodule OpentelemetryAbsintheTest.Extraction do | ||
use OpentelemetryAbsintheTest.Case | ||
|
||
alias OpentelemetryAbsintheTest.Support.GraphQL.Queries | ||
alias OpentelemetryAbsintheTest.Support.Query | ||
|
||
describe "extracts" do | ||
test "request query" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_query: true) | ||
query = Queries.query() | ||
|
||
assert ^query = query |> Query.query_for_attrs() |> Map.fetch!("graphql.request.query") | ||
end | ||
|
||
test "request variables" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_variables: true) | ||
variables = %{"isbn" => "A1", "author" => "Mara Bos"} | ||
|
||
assert ^variables = | ||
Queries.query() | ||
|> Query.query_for_attrs(variables: variables) | ||
|> Map.fetch!("graphql.request.variables") | ||
|> Jason.decode!() | ||
end | ||
|
||
test "request selections" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_selections: true) | ||
|
||
assert ["book"] = | ||
Queries.query() | ||
|> Query.query_for_attrs(variables: %{"isbn" => "A1"}) | ||
|> Map.fetch!("graphql.request.selections") | ||
|> Jason.decode!() | ||
end | ||
|
||
test "request selections on a mutation" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_selections: true) | ||
|
||
assert ["create_book"] = | ||
Queries.mutation() | ||
|> Query.query_for_attrs(variables: %{"isbn" => "A1"}) | ||
|> Map.fetch!("graphql.request.selections") | ||
|> Jason.decode!() | ||
end | ||
|
||
test "aliased request selections as their un-aliased name" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_selections: true) | ||
|
||
assert ["book"] = | ||
Queries.aliased_query() | ||
|> Query.query_for_attrs(variables: %{"isbn" => "A1"}) | ||
|> Map.fetch!("graphql.request.selections") | ||
|> Jason.decode!() | ||
end | ||
|
||
test "request selections on multiple queries" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_request_selections: true) | ||
|
||
assert ["book"] = | ||
Queries.batch_queries() | ||
|> Query.query_for_attrs(variables: %{"isbn" => "A1"}, operation_name: "OperationOne") | ||
|> Map.fetch!("graphql.request.selections") | ||
|> Jason.decode!() | ||
|
||
assert ["books"] = | ||
Queries.batch_queries() | ||
|> Query.query_for_attrs(variables: %{"isbn" => "A1"}, operation_name: "OperationTwo") | ||
|> Map.fetch!("graphql.request.selections") | ||
|> Jason.decode!() | ||
end | ||
|
||
test "response result" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_response_results: true) | ||
|
||
result = | ||
Queries.query() | ||
|> Query.query_for_attrs(variables: %{"isbn" => "A1"}) | ||
|> Map.fetch!("graphql.response.result") | ||
|> Jason.decode!() | ||
|
||
assert %{"data" => %{"book" => %{"author" => %{"age" => 18, "name" => "Ale Ali"}, "title" => "Fire"}}} = result | ||
end | ||
|
||
test "response errors" do | ||
OpentelemetryAbsinthe.Instrumentation.setup(trace_response_errors: true) | ||
|
||
errors = | ||
Queries.query() | ||
|> Query.query_for_attrs() | ||
|> Map.fetch!("graphql.response.errors") | ||
|> Jason.decode!() | ||
|
||
assert [ | ||
%{ | ||
"locations" => [%{"column" => 8, "line" => 2}], | ||
"message" => "In argument \"isbn\": Expected type \"String!\", found null." | ||
}, | ||
%{ | ||
"locations" => [%{"column" => 7, "line" => 1}], | ||
"message" => "Variable \"isbn\": Expected non-null, found null." | ||
} | ||
] = errors | ||
end | ||
end | ||
end |
Oops, something went wrong.