From 919aa6cfb6d2c99781d5043643d55b95dbdafc69 Mon Sep 17 00:00:00 2001 From: "JG.Kim" <379460+newmind@users.noreply.github.com> Date: Tue, 20 Jun 2023 19:02:52 +0900 Subject: [PATCH] Set span kind to SERVER (#103) --- lib/instrumentation.ex | 2 +- test/span_kind_test.exs | 11 +++++++++++ test/support/query.ex | 22 ++++++++++++++-------- 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 test/span_kind_test.exs diff --git a/lib/instrumentation.ex b/lib/instrumentation.ex index 118ca29..99b7de9 100644 --- a/lib/instrumentation.ex +++ b/lib/instrumentation.ex @@ -83,7 +83,7 @@ defmodule OpentelemetryAbsinthe.Instrumentation do save_parent_ctx() span_name = span_name(nil, nil, config.span_name) - new_ctx = Tracer.start_span(span_name, %{attributes: attributes}) + new_ctx = Tracer.start_span(span_name, %{kind: :server, attributes: attributes}) Tracer.set_current_span(new_ctx) end diff --git a/test/span_kind_test.exs b/test/span_kind_test.exs new file mode 100644 index 0000000..0501cd1 --- /dev/null +++ b/test/span_kind_test.exs @@ -0,0 +1,11 @@ +defmodule OpentelemetryAbsintheTest.SpanKind do + use OpentelemetryAbsintheTest.Case + + alias OpentelemetryAbsintheTest.Support.GraphQL.Queries + alias OpentelemetryAbsintheTest.Support.Query + + test "span kind is server" do + OpentelemetryAbsinthe.Instrumentation.setup() + :server = Query.query_for_span_kind(Queries.invalid_query()) + end +end diff --git a/test/support/query.ex b/test/support/query.ex index 72d3923..5614f86 100644 --- a/test/support/query.ex +++ b/test/support/query.ex @@ -9,23 +9,29 @@ defmodule OpentelemetryAbsintheTest.Support.Query do @fields Record.extract(:span, from: "deps/opentelemetry/include/otel_span.hrl") Record.defrecordp(:span, @fields) - def query_for_attrs(query, opts \\ []) do + def query_for_span(query, opts \\ []) do :otel_simple_processor.set_exporter(:otel_exporter_pid, self()) {:ok, data} = Absinthe.run(query, Schema, opts) Logger.debug("Absinthe query returned: #{inspect(data)}") - assert_receive {:span, span(attributes: {_, _, _, _, attributes})}, 5000 + assert_receive {:span, span}, 5000 + Logger.debug("Recieved span: #{inspect(span)}") + span + end + + def query_for_attrs(query, opts \\ []) do + span(attributes: {_, _, _, _, attributes}) = query_for_span(query, opts) attributes end def query_for_span_name(query, opts \\ []) do - :otel_simple_processor.set_exporter(:otel_exporter_pid, self()) - - {:ok, data} = Absinthe.run(query, Schema, opts) - Logger.debug("Absinthe query returned: #{inspect(data)}") - - assert_receive {:span, span(name: name)}, 5000 + span(name: name) = query_for_span(query, opts) name end + + def query_for_span_kind(query, opts \\ []) do + span(kind: kind) = query_for_span(query, opts) + kind + end end