lwt library

This commit is contained in:
Simon Cruanes 2022-03-18 11:06:36 -04:00
parent 097436f907
commit aea549862b
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
4 changed files with 85 additions and 0 deletions

View file

@ -20,6 +20,17 @@
(tags
(instrumentation tracing opentelemetry datadog jaeger)))
(package
(name opentelemetry-lwt)
(synopsis "Lwt-compatible instrumentation for https://opentelemetry.io")
(depends
(ocaml (>= "4.08"))
(dune (>= "2.3"))
(opentelemetry (= :version))
lwt)
(tags
(instrumentation tracing opentelemetry datadog lwt)))
(package
(name opentelemetry-client-ocurl)
(depends

32
opentelemetry-lwt.opam Normal file
View file

@ -0,0 +1,32 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Lwt-compatible instrumentation for https://opentelemetry.io"
maintainer: ["the Imandra team"]
authors: ["the Imandra team"]
license: "MIT"
tags: ["instrumentation" "tracing" "opentelemetry" "datadog" "lwt"]
homepage: "https://github.com/aestheticintegration/ocaml-opentelemetry"
bug-reports:
"https://github.com/aestheticintegration/ocaml-opentelemetry/issues"
depends: [
"ocaml" {>= "4.08"}
"dune" {>= "2.3"}
"opentelemetry" {= version}
"lwt"
]
build: [
["dune" "subst"] {pinned}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo:
"git+https://github.com/aestheticintegration/ocaml-opentelemetry.git"

5
src/lwt/dune Normal file
View file

@ -0,0 +1,5 @@
(library
(name opentelemetry_lwt)
(public_name opentelemetry-lwt)
(synopsis "Lwt frontend for opentelemetry")
(libraries lwt opentelemetry))

View file

@ -0,0 +1,37 @@
open Opentelemetry
module Span_id = Span_id
module Trace_id = Trace_id
module Span = Span
module Trace = struct
open Proto.Trace
include Trace
(** Emit asynchronously *)
let emit (spans:span list) : unit Lwt.t =
let fut, wake = Lwt.wait() in
let ils =
default_instrumentation_library_spans ~spans () in
let rs = default_resource_spans ~instrumentation_library_spans:[ils] () in
Collector.send_trace [rs]
~over:(fun () -> Lwt.wakeup_later wake ())
~ret:(fun () -> fut)
end
module Metrics = struct
open Proto.Metrics
include Metrics
(** Emit some metrics to the collector. *)
let emit (l:t list) : unit Lwt.t =
let fut, wake = Lwt.wait() in
let lm =
default_instrumentation_library_metrics ~metrics:l () in
let rm = default_resource_metrics
~instrumentation_library_metrics:[lm] () in
Collector.send_metrics [rm]
~over:(fun () -> Lwt.wakeup_later wake ())
~ret:(fun () -> fut)
end