Skip to content

Commit

Permalink
feat: lwt backend
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Sep 6, 2024
1 parent faa0808 commit 1bcea95
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 47 deletions.
14 changes: 10 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@
ptime
hmap
atomic
(thread-local-storage (and (>= 0.2) (< 0.3)))
(thread-local-storage
(and
(>= 0.2)
(< 0.3)))
(odoc :with-doc)
(alcotest :with-test)
(pbrt
(and (>= 3.0) (< 4.0)))
(and
(>= 3.0)
(< 4.0)))
(ocaml-lsp-server :with-dev-setup)
(ocamlformat
(and
:with-dev-setup
(>= 0.24)
(< 0.25))))
(depopts trace)
(depopts trace lwt eio)
(conflicts
(trace (< 0.7)))
(trace
(< 0.7)))
(tags
(instrumentation tracing opentelemetry datadog jaeger)))

Expand Down
5 changes: 3 additions & 2 deletions opentelemetry.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ depends: [
"ocaml" {>= "4.08"}
"ptime"
"hmap"
"ambient-context"
"atomic"
"thread-local-storage" {>= "0.2" & < "0.3"}
"odoc" {with-doc}
"alcotest" {with-test}
"pbrt" {>= "3.0" & < "4.0"}
"ocaml-lsp-server" {with-dev-setup}
"ocamlformat" {with-dev-setup & >= "0.24" & < "0.25"}
]
depopts: ["trace"]
depopts: ["trace" "lwt" "eio"]
conflicts: [
"trace" {< "0.7"}
]
Expand Down
35 changes: 0 additions & 35 deletions src/ambient-context/lwt/ambient_context_lwt.ml

This file was deleted.

7 changes: 7 additions & 0 deletions src/ambient-context/lwt/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(library
(name opentelemetry_ambient_context_lwt)
(public_name opentelemetry.ambient-context.lwt)
(optional) ; lwt
(synopsis
"Storage backend for ambient-context using Lwt's sequence-associated storage")
(libraries lwt opentelemetry.ambient-context thread-local-storage))
6 changes: 0 additions & 6 deletions src/ambient-context/lwt/dune.tmp

This file was deleted.

37 changes: 37 additions & 0 deletions src/ambient-context/lwt/opentelemetry_ambient_context_lwt.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
open struct
let _internal_key : Hmap.t Lwt.key = Lwt.new_key ()

let ( let* ) = Option.bind
end

module M = struct
let name = "Storage_lwt"

let[@inline] get_map () = Lwt.get _internal_key

let[@inline] with_map m cb = Lwt.with_value _internal_key (Some m) cb

let create_key = Hmap.Key.create

let get k =
let* context = get_map () in
Hmap.find k context

let with_binding k v cb =
let new_context =
match get_map () with
| None -> Hmap.singleton k v
| Some old_context -> Hmap.add k v old_context
in
with_map new_context cb

let without_binding k cb =
let new_context =
match get_map () with
| None -> Hmap.empty
| Some old_context -> Hmap.rem k old_context
in
with_map new_context cb
end

let storage () : Opentelemetry_ambient_context.storage = (module M)
2 changes: 2 additions & 0 deletions src/ambient-context/lwt/opentelemetry_ambient_context_lwt.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val storage : unit -> Opentelemetry_ambient_context.storage
(** Storage using Lwt keys *)

0 comments on commit 1bcea95

Please sign in to comment.