|
@@ -102,7 +102,10 @@
|
|
%% Length of the request and response bodies. This does
|
|
%% Length of the request and response bodies. This does
|
|
%% not include the framing.
|
|
%% not include the framing.
|
|
req_body_length => non_neg_integer(),
|
|
req_body_length => non_neg_integer(),
|
|
- resp_body_length => non_neg_integer()
|
|
|
|
|
|
+ resp_body_length => non_neg_integer(),
|
|
|
|
+
|
|
|
|
+ %% Additional metadata set by the user.
|
|
|
|
+ user_data => map()
|
|
}.
|
|
}.
|
|
-export_type([metrics/0]).
|
|
-export_type([metrics/0]).
|
|
|
|
|
|
@@ -126,7 +129,8 @@
|
|
procs = #{} :: proc_metrics(),
|
|
procs = #{} :: proc_metrics(),
|
|
informational = [] :: [informational_metrics()],
|
|
informational = [] :: [informational_metrics()],
|
|
req_body_length = 0 :: non_neg_integer(),
|
|
req_body_length = 0 :: non_neg_integer(),
|
|
- resp_body_length = 0 :: non_neg_integer()
|
|
|
|
|
|
+ resp_body_length = 0 :: non_neg_integer(),
|
|
|
|
+ user_data = #{} :: map()
|
|
}).
|
|
}).
|
|
|
|
|
|
-spec init(cowboy_stream:streamid(), cowboy_req:req(), cowboy:opts())
|
|
-spec init(cowboy_stream:streamid(), cowboy_req:req(), cowboy:opts())
|
|
@@ -255,6 +259,14 @@ fold([{data, fin, Data}|Tail], State=#state{resp_body_length=RespBodyLen}) ->
|
|
resp_end=RespEnd,
|
|
resp_end=RespEnd,
|
|
resp_body_length=RespBodyLen + resp_body_length(Data)
|
|
resp_body_length=RespBodyLen + resp_body_length(Data)
|
|
});
|
|
});
|
|
|
|
+fold([{set_options, SetOpts}|Tail], State0=#state{user_data=OldUserData}) ->
|
|
|
|
+ State = case SetOpts of
|
|
|
|
+ #{metrics_user_data := NewUserData} ->
|
|
|
|
+ State0#state{user_data=maps:merge(OldUserData, NewUserData)};
|
|
|
|
+ _ ->
|
|
|
|
+ State0
|
|
|
|
+ end,
|
|
|
|
+ fold(Tail, State);
|
|
fold([_|Tail], State) ->
|
|
fold([_|Tail], State) ->
|
|
fold(Tail, State).
|
|
fold(Tail, State).
|
|
|
|
|
|
@@ -263,7 +275,7 @@ terminate(StreamID, Reason, #state{next=Next, callback=Fun,
|
|
req=Req, resp_status=RespStatus, resp_headers=RespHeaders, ref=Ref,
|
|
req=Req, resp_status=RespStatus, resp_headers=RespHeaders, ref=Ref,
|
|
req_start=ReqStart, req_body_start=ReqBodyStart,
|
|
req_start=ReqStart, req_body_start=ReqBodyStart,
|
|
req_body_end=ReqBodyEnd, resp_start=RespStart, resp_end=RespEnd,
|
|
req_body_end=ReqBodyEnd, resp_start=RespStart, resp_end=RespEnd,
|
|
- procs=Procs, informational=Infos,
|
|
|
|
|
|
+ procs=Procs, informational=Infos, user_data=UserData,
|
|
req_body_length=ReqBodyLen, resp_body_length=RespBodyLen}) ->
|
|
req_body_length=ReqBodyLen, resp_body_length=RespBodyLen}) ->
|
|
Res = cowboy_stream:terminate(StreamID, Reason, Next),
|
|
Res = cowboy_stream:terminate(StreamID, Reason, Next),
|
|
ReqEnd = erlang:monotonic_time(),
|
|
ReqEnd = erlang:monotonic_time(),
|
|
@@ -284,7 +296,8 @@ terminate(StreamID, Reason, #state{next=Next, callback=Fun,
|
|
procs => Procs,
|
|
procs => Procs,
|
|
informational => lists:reverse(Infos),
|
|
informational => lists:reverse(Infos),
|
|
req_body_length => ReqBodyLen,
|
|
req_body_length => ReqBodyLen,
|
|
- resp_body_length => RespBodyLen
|
|
|
|
|
|
+ resp_body_length => RespBodyLen,
|
|
|
|
+ user_data => UserData
|
|
},
|
|
},
|
|
Fun(Metrics),
|
|
Fun(Metrics),
|
|
Res.
|
|
Res.
|