Skip to content

Commit

Permalink
Set span kind to SERVER (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
newmind authored Jun 20, 2023
1 parent 6e96867 commit 919aa6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/instrumentation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/span_kind_test.exs
Original file line number Diff line number Diff line change
@@ -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
22 changes: 14 additions & 8 deletions test/support/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 919aa6c

Please sign in to comment.