Browse Source

Don't supervise the tracer process

If we do then we end up killing the tracer after the stream
terminates and this is not what we want. This prevents us from
getting useful information from requests that are still ongoing
(when they run concurrently) and completely prevents us from
tracing Websocket handlers.

I'm not the biggest fan of having unsupervised modules but if
this is properly documented there should be no problem.
Loïc Hoguin 7 years ago
parent
commit
a1ad482eb4
1 changed files with 6 additions and 10 deletions
  1. 6 10
      src/cowboy_tracer_h.erl

+ 6 - 10
src/cowboy_tracer_h.erl

@@ -43,12 +43,8 @@
 -spec init(cowboy_stream:streamid(), cowboy_req:req(), cowboy:opts())
 -spec init(cowboy_stream:streamid(), cowboy_req:req(), cowboy:opts())
 	-> {cowboy_stream:commands(), any()}.
 	-> {cowboy_stream:commands(), any()}.
 init(StreamID, Req, Opts) ->
 init(StreamID, Req, Opts) ->
-	Result = init_tracer(StreamID, Req, Opts),
-	{Commands, Next} = cowboy_stream:init(StreamID, Req, Opts),
-	case Result of
-		no_tracing -> {Commands, Next};
-		{tracing, TracerPid} -> {[{spawn, TracerPid, 5000}|Commands], Next}
-	end.
+	init_tracer(StreamID, Req, Opts),
+	cowboy_stream:init(StreamID, Req, Opts).
 
 
 -spec data(cowboy_stream:streamid(), cowboy_stream:fin(), cowboy_req:resp_body(), State)
 -spec data(cowboy_stream:streamid(), cowboy_stream:fin(), cowboy_req:resp_body(), State)
 	-> {cowboy_stream:commands(), State} when State::any().
 	-> {cowboy_stream:commands(), State} when State::any().
@@ -75,14 +71,14 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) ->
 init_tracer(StreamID, Req, Opts=#{tracer_match_specs := List, tracer_callback := _}) ->
 init_tracer(StreamID, Req, Opts=#{tracer_match_specs := List, tracer_callback := _}) ->
 	case match(List, StreamID, Req, Opts) of
 	case match(List, StreamID, Req, Opts) of
 		false ->
 		false ->
-			no_tracing;
+			ok;
 		true ->
 		true ->
 			start_tracer(StreamID, Req, Opts)
 			start_tracer(StreamID, Req, Opts)
 	end;
 	end;
 %% When the options tracer_match_specs or tracer_callback
 %% When the options tracer_match_specs or tracer_callback
 %% are not provided we do not enable tracing.
 %% are not provided we do not enable tracing.
 init_tracer(_, _, _) ->
 init_tracer(_, _, _) ->
-	no_tracing.
+	ok.
 
 
 match([], _, _, _) ->
 match([], _, _, _) ->
 	true;
 	true;
@@ -129,9 +125,9 @@ start_tracer(StreamID, Req, Opts) ->
 				send, 'receive', call, return_to, procs, ports,
 				send, 'receive', call, return_to, procs, ports,
 				monotonic_timestamp, set_on_spawn, {tracer, TracerPid}
 				monotonic_timestamp, set_on_spawn, {tracer, TracerPid}
 			]),
 			]),
-			{tracing, TracerPid};
+			ok;
 		_ ->
 		_ ->
-			no_tracing
+			ok
 	end.
 	end.
 
 
 %% Tracer process.
 %% Tracer process.