mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-08 20:07:55 -04:00
feat(cohttp): trace post_form
This commit is contained in:
parent
5e8affe508
commit
0ad2d3f641
1 changed files with 25 additions and 3 deletions
|
|
@ -147,8 +147,7 @@ end = struct
|
||||||
end
|
end
|
||||||
|
|
||||||
let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client) =
|
let client ?(scope : Otel.Trace.scope option) (module C : Cohttp_lwt.S.Client) =
|
||||||
let module Traced : Cohttp_lwt.S.Client = struct
|
let module Traced = struct
|
||||||
include C
|
|
||||||
open Lwt.Syntax
|
open Lwt.Syntax
|
||||||
|
|
||||||
let attrs_for ~uri ~meth () =
|
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
|
Header.add headers Traceparent.name
|
||||||
(Traceparent.to_value ~trace_id:scope.trace_id ~parent_id:scope.span_id ())
|
(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 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
|
let (trace_id, parent, attrs) = context_for ~uri ~meth in
|
||||||
Otel_lwt.Trace.with_ "request"
|
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
|
call ?ctx ?headers ?body ?chunked `PUT uri
|
||||||
|
|
||||||
let patch ?ctx ?body ?chunked ?headers 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
|
in
|
||||||
(module Traced : Cohttp_lwt.S.Client)
|
(module Traced : Cohttp_lwt.S.Client)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue