diff --git a/lib/adapters/datadog.ex b/lib/adapters/datadog.ex index 8cecce0..ed78865 100644 --- a/lib/adapters/datadog.ex +++ b/lib/adapters/datadog.ex @@ -248,7 +248,7 @@ defmodule Spandex.Adapters.Datadog do """ @impl Spandex.Adapters.Adapter @spec continue_trace(String.t(), term, term, Keyword.t()) :: {:ok, term} | {:error, term} - def continue_trace(name, trace_id, span_id, opts) do + def continue_trace(name, trace_id, span_id, opts) when is_integer(trace_id) and is_integer(span_id) do trace = get_trace(:undefined) cond do @@ -306,8 +306,18 @@ defmodule Spandex.Adapters.Datadog do conn |> Plug.Conn.get_req_header(header_name) |> List.first() + |> parse_header() end + defp parse_header(header) when is_bitstring(header) do + case Integer.parse(header) do + {int, _} -> int + _ -> nil + end + end + + defp parse_header(_header), do: nil + @spec get_trace(term) :: term defp get_trace(default \\ nil) do Process.get(:spandex_trace, default) diff --git a/test/plug/start_trace_test.exs b/test/plug/start_trace_test.exs index 2b3f9c7..2c4bf39 100644 --- a/test/plug/start_trace_test.exs +++ b/test/plug/start_trace_test.exs @@ -99,9 +99,9 @@ defmodule Spandex.Plug.StartTraceTest do new_conn = StartTrace.call(conn, ignored_routes: [], ignored_methods: [], tracer: Tracer) - assert %{trace_id: "12345", parent_id: "67890"} = Tracer.current_span() + assert %{trace_id: 12345, parent_id: 67890} = Tracer.current_span() - refute Tracer.current_span_id() == "67890" + refute Tracer.current_span_id() == 67890 refute is_nil(Tracer.current_span_id()) assert new_conn.assigns[:spandex_trace_request?]