Skip to content

Commit fae50e0

Browse files
committed
Automatically continue tracing in Task processes
Get the caller from the process dictionary, and if the caller was tracing, continue that trace.
1 parent 87afbf9 commit fae50e0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/aws_ex_ray.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,15 @@ defmodule AwsExRay do
354354
{:ok, subsegment}
355355

356356
{:error, :not_found} ->
357-
{:error, :out_of_xray}
357+
case Process.get(:"$callers") do
358+
[caller_pid | _] when is_pid(caller_pid) and tracing_pid == nil ->
359+
# If the tracing pid was not explicitly specified, and the
360+
# current process is not tracing but it was started as a
361+
# Task from a process that is tracing, continue that trace.
362+
start_subsegment(name, Keyword.put(opts, :tracing_pid, caller_pid))
363+
_ ->
364+
{:error, :out_of_xray}
365+
end
358366

359367
end
360368
end

0 commit comments

Comments
 (0)