aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_tracer_h.erl10
-rw-r--r--test/tracer_SUITE.erl24
2 files changed, 26 insertions, 8 deletions
diff --git a/src/cowboy_tracer_h.erl b/src/cowboy_tracer_h.erl
index b69faf4..b527f7e 100644
--- a/src/cowboy_tracer_h.erl
+++ b/src/cowboy_tracer_h.erl
@@ -144,19 +144,19 @@ tracer_process(StreamID, Req=#{pid := Parent}, Opts=#{tracer_callback := Fun}) -
State = Fun(init, {StreamID, Req, Opts}),
tracer_loop(Parent, Fun, State).
-tracer_loop(Parent, Fun, State) ->
+tracer_loop(Parent, Fun, State0) ->
receive
Msg when element(1, Msg) =:= trace_ts ->
- Fun(Msg, State),
+ State = Fun(Msg, State0),
tracer_loop(Parent, Fun, State);
{'EXIT', Parent, Reason} ->
- tracer_terminate(Reason, Fun, State);
+ tracer_terminate(Reason, Fun, State0);
{system, From, Request} ->
- sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Fun, State});
+ sys:handle_system_msg(Request, From, Parent, ?MODULE, [], {Fun, State0});
Msg ->
error_logger:error_msg("~p: Tracer process received stray message ~9999p~n",
[?MODULE, Msg]),
- tracer_loop(Parent, Fun, State)
+ tracer_loop(Parent, Fun, State0)
end.
tracer_terminate(Reason, Fun, State) ->
diff --git a/test/tracer_SUITE.erl b/test/tracer_SUITE.erl
index 6f83fd3..0f7fc5f 100644
--- a/test/tracer_SUITE.erl
+++ b/test/tracer_SUITE.erl
@@ -98,12 +98,13 @@ do_tracer_callback(Pid) ->
fun
(Event, _) when Event =:= init; Event =:= terminate ->
Pid ! Event,
- undefined;
+ 0;
(Event={trace_ts, _, call, {cowboy_req, reply, _}, _}, State) ->
Pid ! Event,
- State;
+ Pid ! {state, State},
+ State + 1;
(_, State) ->
- State
+ State + 1
end.
%% Tests.
@@ -140,6 +141,23 @@ terminate(Config) ->
error(timeout)
end.
+state(Config) ->
+ doc("Ensure the returned state is used."),
+ Ref = config(ref, Config),
+ Opts = ranch:get_protocol_options(Ref),
+ ranch:set_protocol_options(Ref, Opts#{
+ tracer_callback => do_tracer_callback(self()),
+ tracer_match_specs => [fun(_,_,_) -> true end]
+ }),
+ do_get("/", Config),
+ receive
+ {state, St} ->
+ true = St > 0,
+ ok
+ after 100 ->
+ error(timeout)
+ end.
+
empty(Config) ->
doc("Empty match specs unconditionally enable tracing."),
Ref = config(ref, Config),