From 3e46458499b0a23a36685db60ec74f1a59bc6350 Mon Sep 17 00:00:00 2001 From: Elliott Cable Date: Tue, 13 Jun 2023 22:50:52 +0000 Subject: [PATCH 1/2] (style lwt ppx dep) Use try%lwt over Lwt.catch --- src/client-cohttp-lwt/common_.ml | 1 - src/client-cohttp-lwt/dune | 1 + .../opentelemetry_client_cohttp_lwt.ml | 10 +++++----- src/lwt/dune | 2 ++ src/lwt/opentelemetry_lwt.ml | 15 +++++++-------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/client-cohttp-lwt/common_.ml b/src/client-cohttp-lwt/common_.ml index a082ff1f..091896aa 100644 --- a/src/client-cohttp-lwt/common_.ml +++ b/src/client-cohttp-lwt/common_.ml @@ -1,4 +1,3 @@ -open Lwt.Syntax module Atomic = Opentelemetry_atomic.Atomic let[@inline] ( let@ ) f x = f x diff --git a/src/client-cohttp-lwt/dune b/src/client-cohttp-lwt/dune index 5faafe1a..12d79702 100644 --- a/src/client-cohttp-lwt/dune +++ b/src/client-cohttp-lwt/dune @@ -2,5 +2,6 @@ (name opentelemetry_client_cohttp_lwt) (public_name opentelemetry-client-cohttp-lwt) (synopsis "Opentelemetry collector using cohttp+lwt+unix") + (preprocess (pps lwt_ppx)) (libraries opentelemetry lwt cohttp-lwt cohttp-lwt-unix pbrt mtime mtime.clock.os)) diff --git a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml index 11e93aed..c1005413 100644 --- a/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml +++ b/src/client-cohttp-lwt/opentelemetry_client_cohttp_lwt.ml @@ -105,11 +105,11 @@ end = struct let body = Cohttp_lwt.Body.of_string bod in let* r = - Lwt.catch - (fun () -> - let+ r = Httpc.post ~headers ~body uri in - Ok r) - (fun e -> Lwt.return @@ Error e) + try%lwt + let+ r = Httpc.post ~headers ~body uri in + Ok r + with e -> + Lwt.return @@ Error e in match r with | Error e -> diff --git a/src/lwt/dune b/src/lwt/dune index e547e931..24fbdf22 100644 --- a/src/lwt/dune +++ b/src/lwt/dune @@ -2,4 +2,6 @@ (name opentelemetry_lwt) (public_name opentelemetry-lwt) (synopsis "Lwt frontend for opentelemetry") + (preprocess + (pps lwt_ppx)) (libraries lwt opentelemetry)) diff --git a/src/lwt/opentelemetry_lwt.ml b/src/lwt/opentelemetry_lwt.ml index 8e8524cf..a67ec938 100644 --- a/src/lwt/opentelemetry_lwt.ml +++ b/src/lwt/opentelemetry_lwt.ml @@ -47,14 +47,13 @@ module Trace = struct in emit ?service_name [ span ] in - Lwt.catch - (fun () -> - let* x = f scope in - let () = finally (Ok ()) in - Lwt.return x) - (fun e -> - let () = finally (Error (Printexc.to_string e)) in - Lwt.fail e) + try%lwt + let* x = f scope in + let () = finally (Ok ()) in + Lwt.return x + with e -> + let () = finally (Error (Printexc.to_string e)) in + Lwt.fail e end module Metrics = struct From 9e6c0ee433440301b7ba31023b567aa3bf5cd688 Mon Sep 17 00:00:00 2001 From: Elliott Cable Date: Tue, 13 Jun 2023 22:56:09 +0000 Subject: [PATCH 2/2] (dep fix) Add dependencies for lwt_ppx --- dune-project | 5 +++-- opentelemetry-client-cohttp-lwt.opam | 2 +- opentelemetry-lwt.opam | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dune-project b/dune-project index 6d660768..ad4b1b40 100644 --- a/dune-project +++ b/dune-project @@ -32,7 +32,8 @@ (opentelemetry (= :version)) (cohttp-lwt-unix :with-test) (odoc :with-doc) - (lwt (>= "5.3"))) + (lwt (>= "5.3")) + lwt_ppx) (tags (instrumentation tracing opentelemetry datadog lwt))) @@ -68,7 +69,7 @@ (pbrt (>= 2.2)) (odoc :with-doc) (lwt (>= "5.3")) - (lwt_ppx :with-test) + lwt_ppx cohttp-lwt cohttp-lwt-unix) (synopsis "Collector client for opentelemetry, using cohttp + lwt")) diff --git a/opentelemetry-client-cohttp-lwt.opam b/opentelemetry-client-cohttp-lwt.opam index e04b086a..9ef83e7c 100644 --- a/opentelemetry-client-cohttp-lwt.opam +++ b/opentelemetry-client-cohttp-lwt.opam @@ -15,7 +15,7 @@ depends: [ "pbrt" {>= "2.2"} "odoc" {with-doc} "lwt" {>= "5.3"} - "lwt_ppx" {with-test} + "lwt_ppx" "cohttp-lwt" "cohttp-lwt-unix" ] diff --git a/opentelemetry-lwt.opam b/opentelemetry-lwt.opam index a7490975..f739e701 100644 --- a/opentelemetry-lwt.opam +++ b/opentelemetry-lwt.opam @@ -15,6 +15,7 @@ depends: [ "cohttp-lwt-unix" {with-test} "odoc" {with-doc} "lwt" {>= "5.3"} + "lwt_ppx" ] build: [ ["dune" "subst"] {dev}