@@ -53,12 +53,17 @@ defmodule SpandexDatadog.Adapter do
5353 """
5454 @ impl Spandex.Adapter
5555 @ spec inject_context ( [ { term ( ) , term ( ) } ] , SpanContext . t ( ) , Tracer . opts ( ) ) :: [ { term ( ) , term ( ) } ]
56- def inject_context ( headers , % SpanContext { trace_id: trace_id , parent_id: parent_id , priority: priority } , _opts ) do
57- [
58- { "x-datadog-trace-id" , to_string ( trace_id ) } ,
59- { "x-datadog-parent-id" , to_string ( parent_id ) } ,
60- { "x-datadog-sampling-priority" , to_string ( priority ) }
61- ] ++ headers
56+ def inject_context ( headers , % SpanContext { } = span_context , _opts ) when is_list ( headers ) do
57+ span_context
58+ |> tracing_headers ( )
59+ |> Kernel . ++ ( headers )
60+ end
61+
62+ def inject_context ( headers , % SpanContext { } = span_context , _opts ) when is_map ( headers ) do
63+ span_context
64+ |> tracing_headers ( )
65+ |> Enum . into ( % { } )
66+ |> Map . merge ( headers )
6267 end
6368
6469 # Private Helpers
@@ -79,4 +84,12 @@ defmodule SpandexDatadog.Adapter do
7984 end
8085
8186 defp parse_header ( _header ) , do: nil
87+
88+ defp tracing_headers ( % SpanContext { trace_id: trace_id , parent_id: parent_id , priority: priority } ) do
89+ [
90+ { "x-datadog-trace-id" , to_string ( trace_id ) } ,
91+ { "x-datadog-parent-id" , to_string ( parent_id ) } ,
92+ { "x-datadog-sampling-priority" , to_string ( priority ) }
93+ ]
94+ end
8295end
0 commit comments