feat(cohttp): trace post_form

This commit is contained in:
Matt Bray 2022-03-24 23:10:11 +00:00
parent 5e8affe508
commit 0ad2d3f641

View file

@ -147,8 +147,7 @@ end = struct
end
let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client) =
let module Traced : Cohttp_lwt.S.Client = struct
include C
let module Traced = struct
open Lwt.Syntax
let attrs_for ~uri ~meth () =
@ -168,6 +167,8 @@ let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client)
Header.add headers Traceparent.name
(Traceparent.to_value ~trace_id:scope.trace_id ~parent_id:scope.span_id ())
type ctx = C.ctx
let call ?ctx ?headers ?body ?chunked meth (uri : Uri.t) : (Response.t * Cohttp_lwt.Body.t) Lwt.t =
let (trace_id, parent, attrs) = context_for ~uri ~meth in
Otel_lwt.Trace.with_ "request"
@ -200,6 +201,27 @@ let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client)
call ?ctx ?headers ?body ?chunked `PUT uri
let patch ?ctx ?body ?chunked ?headers uri =
call ?ctx ?headers ?body ?chunked `PATCH uri end
call ?ctx ?headers ?body ?chunked `PATCH uri
let post_form ?ctx ?headers ~params uri =
let (trace_id, parent, attrs) = context_for ~uri ~meth:`POST in
Otel_lwt.Trace.with_ "request"
~kind:Span_kind_client
?trace_id
?parent
~attrs
(fun scope ->
let headers = add_traceparent scope headers in
let* (res, body) =
C.post_form ?ctx ~headers ~params uri
in
Otel.Trace.add_attrs scope (fun () ->
let code = Response.status res in
let code = Code.code_of_status code in
[ ("http.status_code", `Int code) ]) ;
Lwt.return (res, body))
let callv = C.callv (* TODO *)
end
in
(module Traced : Cohttp_lwt.S.Client)