Skip to content

Commit

Permalink
Config flag controlling if additional spans are emitted (queue, run_q…
Browse files Browse the repository at this point in the history
…uery, decode)
  • Loading branch information
Artur Sulej committed Feb 29, 2024
1 parent d2c9e47 commit 35eb4a6
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions lib/spandex_ecto/ecto_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule SpandexEcto.EctoLogger do
tracer = config[:tracer] || raise "tracer is a required option for #{inspect(__MODULE__)}"
service = config[:service] || :ecto
truncate = config[:truncate] || 5000
emit_detailed_spans = Keyword.get(config, :emit_detailed_spans, true)

if tracer.current_trace_id() do
now = :os.system_time(:nano_seconds)
Expand Down Expand Up @@ -58,34 +59,36 @@ defmodule SpandexEcto.EctoLogger do

report_error(tracer, log_entry)

if queue_time != 0 do
tracer.start_span("queue")
tracer.update_span(service: service, start: start, completion_time: start + queue_time)
tracer.finish_span()
end
if emit_detailed_spans do
if queue_time != 0 do
tracer.start_span("queue")
tracer.update_span(service: service, start: start, completion_time: start + queue_time)
tracer.finish_span()
end

if query_time != 0 do
tracer.start_span("run_query")
if query_time != 0 do
tracer.start_span("run_query")

tracer.update_span(
service: service,
start: start + queue_time,
completion_time: start + queue_time + query_time
)
tracer.update_span(
service: service,
start: start + queue_time,
completion_time: start + queue_time + query_time
)

tracer.finish_span()
end
tracer.finish_span()
end

if decoding_time != 0 do
tracer.start_span("decode")
if decoding_time != 0 do
tracer.start_span("decode")

tracer.update_span(
service: service,
start: start + queue_time + query_time,
completion_time: now
)
tracer.update_span(
service: service,
start: start + queue_time + query_time,
completion_time: now
)

tracer.finish_span()
tracer.finish_span()
end
end

tracer.finish_span()
Expand Down

0 comments on commit 35eb4a6

Please sign in to comment.