From 894158339eed4ac779b1ba761bf393b4a4319731 Mon Sep 17 00:00:00 2001 From: Shon Feder Date: Sun, 25 May 2025 21:36:09 -0400 Subject: [PATCH] Update to support cohttp 6 Preparation for Cohttp 6 started in 2022 (https://github.com/mirage/ocaml-cohttp/blob/main/CHANGES.md#v600alpha0-2022-10-24) and 6 has been stable and released since Nov of 2024. See https://github.com/mirage/ocaml-cohttp/blob/main/CHANGES.md#v600-2024-11-21 Removal of the `open Cohttp_lwt` solves deprecation warnings issued by Cohttp 6, since everything we were using from the open has been moved into `Cohttp`. --- dune-project | 4 +--- opentelemetry-cohttp-lwt.opam | 2 +- .../cohttp/opentelemetry_cohttp_lwt.ml | 14 +++++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dune-project b/dune-project index 60b778fd..ec273074 100644 --- a/dune-project +++ b/dune-project @@ -101,9 +101,7 @@ (lwt (>= "5.3")) (cohttp-lwt - (and - (>= "4.0.0") - (< "6"))) + (>= "6.0.0")) (alcotest :with-test)) (synopsis "Opentelemetry tracing for Cohttp HTTP servers")) diff --git a/opentelemetry-cohttp-lwt.opam b/opentelemetry-cohttp-lwt.opam index 4d3fd0da..ad66a0ef 100644 --- a/opentelemetry-cohttp-lwt.opam +++ b/opentelemetry-cohttp-lwt.opam @@ -18,7 +18,7 @@ depends: [ "opentelemetry-lwt" {= version} "odoc" {with-doc} "lwt" {>= "5.3"} - "cohttp-lwt" {>= "4.0.0" & < "6"} + "cohttp-lwt" {>= "6.0.0"} "alcotest" {with-test} ] build: [ diff --git a/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml b/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml index fd2ff1a4..67272d36 100644 --- a/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml +++ b/src/integrations/cohttp/opentelemetry_cohttp_lwt.ml @@ -1,7 +1,6 @@ module Otel = Opentelemetry module Otel_lwt = Opentelemetry_lwt open Cohttp -open Cohttp_lwt module Server : sig val trace : @@ -144,6 +143,17 @@ let client ?(scope : Otel.Scope.t option) (module C : Cohttp_lwt.S.Client) = let module Traced = struct open Lwt.Syntax + (* These types and values are not customized by our client, but are required to satisfy + [Cohttp_lwt.S.Client]. *) + include (C : sig + type ctx = C.ctx + type 'a io = 'a C.io + type 'a with_context = 'a C.with_context + type body = C.body + val map_context : 'a with_context -> ('a -> 'b) -> 'b with_context + val set_cache : Cohttp_lwt.S.call -> unit + end) + let attrs_for ~uri ~meth:_ () = [ "http.method", `String (Code.string_of_method `GET); @@ -175,8 +185,6 @@ let client ?(scope : Otel.Scope.t option) (module C : Cohttp_lwt.S.Client) = (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