Compare commits

...

25 commits

Author SHA1 Message Date
Raphaël Proust
b6e81073be
Merge 7d090b16cc into 78d8d107ff 2026-04-23 06:49:19 +00:00
Simon Cruanes
78d8d107ff fix warning 2026-04-22 20:51:39 -04:00
Simon Cruanes
59ea628546 prepare for 0.91 2026-04-21 15:31:24 -04:00
Simon Cruanes
cf7dbaf66a fix test being in the wrong package 2026-04-21 15:31:24 -04:00
Simon Cruanes
a4d95409ee better error message for otlp http failures 2026-04-17 11:27:46 -04:00
Simon Cruanes
59e2e854e5 docs 2026-04-15 10:19:11 -04:00
Simon Cruanes
5f3b162290 bounded queue: provide a per-item measure function for better errors/metrics
we can now know how big the batches we drop are
2026-04-10 15:09:59 -04:00
Simon Cruanes
2401745f1a fix: retries are self_debug logged at warning level 2026-04-10 15:09:59 -04:00
Simon Cruanes
fd47118c51 fix 2026-04-10 15:09:59 -04:00
Simon Cruanes
9cb9c1081c config: better defaults in Sdk, have batching enabled by default 2026-04-10 15:09:59 -04:00
Simon Cruanes
7a93a2582b better warning in bounded_queue_sync 2026-04-10 14:28:50 -04:00
Simon Cruanes
e9bb76edd1
expose Self_debug.level_above 2026-04-09 09:24:13 -04:00
Simon Cruanes
b766f86019
CI 2026-04-06 15:56:41 -04:00
Simon Cruanes
78e44e916c
move from ocurl to curl 2026-04-06 15:48:16 -04:00
Simon Cruanes
755509893e
fix docker build 2026-04-06 15:47:39 -04:00
Simon Cruanes
5031be8d91
use docker images for CI (#130)
* use docker images for CI

* run gha as root in docker

using the opam user wouldn't work for actions like checkout

* make our own docker images from ubuntu LTS

* details

* fix eio step

* fix build issues in docker
2026-04-06 15:47:16 -04:00
Simon Cruanes
8ebc582a00
add gh-pages back (!) 2026-04-06 09:25:38 -04:00
Simon Cruanes
7691512ace fix dumb circular dep 2026-04-04 01:06:42 -04:00
Simon Cruanes
6a468594e0 preparing for 0.90 2026-04-03 09:26:04 -04:00
Simon Cruanes
7f9b7d7c83 fix opam 2026-04-03 09:26:03 -04:00
Simon Cruanes
31cc90abb4
more robust detection of lwt's version 2026-04-02 12:20:03 -04:00
Simon Cruanes
9c6245e88d
fix: compat with mtime < 2.1 2026-04-02 10:33:24 -04:00
Simon Cruanes
7b06ccb4e2 changelog+docs update 2026-04-01 16:45:10 -04:00
Simon Cruanes
d316e2a4f1 update opam files 2026-04-01 15:58:07 -04:00
Raphaël Proust
7d090b16cc
stricter version constraint for cohttp-lwt
see https://github.com/ocaml/opam-repository/pull/29157
2025-12-31 10:22:42 +01:00
48 changed files with 420 additions and 276 deletions

View file

@ -1,5 +1,3 @@
name: format
on:
@ -11,20 +9,10 @@ on:
jobs:
format:
name: format
strategy:
matrix:
ocaml-compiler:
- '5.3'
runs-on: 'ubuntu-latest'
runs-on: ubuntu-latest
container: ghcr.io/ocaml-tracing/ocaml-opentelemetry/ci-4.14:latest
steps:
- uses: actions/checkout@main
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: true
allow-prerelease-opam: true
- uses: actions/checkout@v6
- run: opam install ocamlformat.0.27.0 lwt.6.1.1
- run: opam exec -- make format-check

38
.github/workflows/gh-pages.yml vendored Normal file
View file

@ -0,0 +1,38 @@
name: github pages
on:
push:
branches:
- main
permissions:
contents: write
packages: read
jobs:
deploy:
runs-on: ubuntu-latest
container: ghcr.io/ocaml-tracing/ocaml-opentelemetry/ci-5.4:latest
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
- name: Install local packages
run: opam exec -- dune build @install && opam exec -- dune install
- name: Build documentation
run: |
opam exec -- odig odoc --cache-dir=_doc/ \
opentelemetry opentelemetry-client opentelemetry-lwt \
opentelemetry-cohttp-lwt opentelemetry-client-ocurl \
opentelemetry-client-ocurl-lwt opentelemetry-client-cohttp-lwt \
opentelemetry-client-cohttp-eio opentelemetry-logs
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_doc/html
enable_jekyll: false

View file

@ -11,65 +11,37 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
#- windows-latest
#- macos-latest
ocaml-compiler:
- 4.08.x
- 4.13.x
- 5.0.x
- 5.3.x
include:
- ocaml-version: "4.08"
container: ghcr.io/ocaml-tracing/ocaml-opentelemetry/ci-4.08:latest
eio: false
- ocaml-version: "4.14"
container: ghcr.io/ocaml-tracing/ocaml-opentelemetry/ci-4.14:latest
eio: false
- ocaml-version: "5.4"
container: ghcr.io/ocaml-tracing/ocaml-opentelemetry/ci-5.4:latest
eio: true
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
container: ${{ matrix.container }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
submodules: recursive
# needed for depext to work
- run: sudo apt-get update && sudo apt-get install mccs
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Build
run: opam exec -- dune build @install -p opentelemetry,opentelemetry-client,opentelemetry-lwt,opentelemetry-cohttp-lwt,opentelemetry-client-ocurl,opentelemetry-client-ocurl-lwt,opentelemetry-client-cohttp-lwt,opentelemetry-logs
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
opam-depext-flags: --with-test
dune-cache: true
allow-prerelease-opam: true
- name: Build eio packages
if: ${{ matrix.eio }}
run: opam exec -- dune build @install -p opentelemetry-client-cohttp-eio,opentelemetry,opentelemetry-client,opentelemetry-lwt,opentelemetry-cohttp-lwt,opentelemetry-client-ocurl,opentelemetry-client-ocurl-lwt,opentelemetry-client-cohttp-lwt,opentelemetry-logs
- run: |
opam install pbrt.4.0 -y
opam install ambient-context lwt.5.9.2
- name: Lint (protoc check)
run: opam exec -- dune build @lint
# We cannot install packages that need eio on ocaml versions before 5
- run: |
packages=$(ls ./*.opam | grep -v eio)
opam install $packages --deps-only --with-test --solver=mccs
if: ${{ ! (startsWith(matrix.ocaml-compiler, '5')) }}
- name: Check no generated files changed
run: git diff --exit-code
# We should be able to install all packages on ocaml 5
- run: opam install . --deps-only --with-test --solver=mccs
if: ${{ startsWith(matrix.ocaml-compiler, '5') }}
- run: opam exec -- dune build @install -p opentelemetry,opentelemetry-client,opentelemetry-lwt,opentelemetry-client-ocurl,opentelemetry-cohttp-lwt,opentelemetry-client-cohttp-lwt,opentelemetry-logs
- run: opam install trace
- run: opam exec -- dune build @install -p opentelemetry
- run: opam install lwt.6.1.1 -y
if: ${{ matrix.ocaml-compiler == '5.3.x' }}
- run: opam exec -- dune build @install -p opentelemetry,opentelemetry-client,opentelemetry-lwt,opentelemetry-client-cohttp-lwt
if: ${{ matrix.ocaml-compiler == '5.3.x' }}
- run: opam install ocaml-protoc
- run: opam exec -- dune build @lint
# check that nothing changed
- run: git diff --exit-code
- run: opam exec -- dune build @runtest
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Run tests
run: opam exec -- dune build @runtest

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ _opam
*.install
*.exe
*.tmp
/.env

View file

@ -1,5 +1,15 @@
## 0.20
## 0.91
- expose Self_debug.level_above
- config: better defaults in Sdk, have batching enabled by default
- better error message for otlp http failures
- bounded queue: provide a per-item measure function for better errors/metrics
- fix: retries are self_debug logged at warning level
- move from ocurl to curl as a dep
## 0.90
- major refactor: split library into `opentelemetry.core`, `opentelemetry`,
`opentelemetry.util`, `opentelemetry.emitter`, `opentelemetry.atomic`, revamp internals

View file

@ -36,6 +36,8 @@ WATCH ?= @all
watch:
@dune build $(WATCH) -w $(OPTS)
include deps/Makefile.ci
VERSION=$(shell awk '/^version:/ {print $$2}' opentelemetry.opam)
update_next_tag:
@echo "update version to $(VERSION)..."

View file

@ -75,9 +75,9 @@ let main () =
[`service_name`]: <https://v3.ocaml.org/p/opentelemetry/latest/doc/Opentelemetry/Globals/index.html#val-service_name>
[ambient-context]: now vendored as `opentelemetry.ambient-context`, formerly <https://v3.ocaml.org/p/ambient-context>
## Migration v012 → v0.13
## Migration 0.13 → v0.90
see `doc/migration_guide_v0.13.md`
see `doc/migration_guide_v0.90.md`
## Configuration

44
deps/Makefile.ci vendored Normal file
View file

@ -0,0 +1,44 @@
# CI Docker images — included by top-level Makefile
CI_REGISTRY = ghcr.io/ocaml-tracing/ocaml-opentelemetry
CI_VERSIONS = 4.08 4.14 5.4
# To update: curl -s https://api.github.com/repos/ocaml/opam-repository/commits/master | jq -r .sha
OPAM_REPO_COMMIT ?= 67472cd54293d750a62d6d4423024d55f77268b0
CI_BASE_OS_PACKAGES = pkg-config libcurl4-openssl-dev libgmp-dev mccs
CI_COMMON_PACKAGES = ptime hmap pbrt pbrt_yojson ambient-context mtime \
thread-local-storage lwt_ppx ambient-context-lwt \
cohttp cohttp-lwt cohttp-lwt-unix \
ezcurl ezcurl-lwt ocurl logs alcotest containers \
trace ocaml-protoc
CI_PACKAGES_408 = $(CI_COMMON_PACKAGES) lwt.5.9.2
CI_PACKAGES_414 = $(CI_COMMON_PACKAGES) lwt.5.9.2 ocamlformat.0.27.0
CI_PACKAGES_54 = $(CI_COMMON_PACKAGES) lwt.6.1.1 \
ambient-context-eio cohttp-eio tls-eio ca-certs mirage-crypto-rng eio_main odig
CI_BUILD = docker build -f deps/dockerfile.ocaml \
--build-arg OPAM_REPO_COMMIT=$(OPAM_REPO_COMMIT) \
--build-arg "BASE_OS_PACKAGES=$(CI_BASE_OS_PACKAGES)"
build-ci-docker:
$(CI_BUILD) --build-arg OCAML_VERSION=4.08.1 --build-arg "BASE_PACKAGES=$(CI_PACKAGES_408)" -t $(CI_REGISTRY)/ci-4.08:latest .
$(CI_BUILD) --build-arg OCAML_VERSION=4.14.2 --build-arg "BASE_PACKAGES=$(CI_PACKAGES_414)" -t $(CI_REGISTRY)/ci-4.14:latest .
$(CI_BUILD) --build-arg OCAML_VERSION=5.4.1 --build-arg "BASE_PACKAGES=$(CI_PACKAGES_54)" -t $(CI_REGISTRY)/ci-5.4:latest .
CI_NON_EIO_PACKAGES = opentelemetry,opentelemetry-client,opentelemetry-lwt,opentelemetry-cohttp-lwt,opentelemetry-client-ocurl,opentelemetry-client-ocurl-lwt,opentelemetry-client-cohttp-lwt,opentelemetry-logs
CI_RUN = docker run --pull=never --rm -t -v $(PWD):/src:z -w /src
run-ci:
@for v in $(CI_VERSIONS); do \
echo "=== OCaml $$v ===" ; \
$(CI_RUN) $(CI_REGISTRY)/ci-$$v:latest \
sh -c "opam exec -- dune build @install -p $(CI_NON_EIO_PACKAGES) && opam exec -- dune build @runtest" \
|| exit 1 ; \
done
$(CI_RUN) $(CI_REGISTRY)/ci-5.4:latest \
opam exec -- dune build @install -p opentelemetry-client-cohttp-eio
upload-ci-docker:
@for v in $(CI_VERSIONS); do \
docker push $(CI_REGISTRY)/ci-$$v:latest ; \
done || ( echo "to login: docker login ghcr.io -u <your-github-username>" ; exit 1 )

40
deps/dockerfile.ocaml vendored Normal file
View file

@ -0,0 +1,40 @@
ARG BASE_OS=ubuntu:24.04
# --- Stage 1: base (shared, no OCaml) ---
FROM $BASE_OS AS base
ARG BASE_OS_PACKAGES=""
ENV OPAMROOTISOK=1 OPAMYES=1 OPAMCONFIRMLEVEL=unsafe-yes
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl git unzip build-essential netbase $BASE_OS_PACKAGES
RUN curl -fsSL https://github.com/ocaml/opam/releases/download/2.5.0/opam-2.5.0-x86_64-linux -o /usr/local/bin/opam && \
chmod +x /usr/local/bin/opam && \
git config --system --add safe.directory '*'
WORKDIR /root/w
# --- Stage 2: opam-setup (builds the switch, discarded) ---
FROM base AS opam-setup
ARG OCAML_VERSION
ARG OPAM_REPO_COMMIT=master
ARG BASE_PACKAGES=""
RUN git init /tmp/opam-repo && cd /tmp/opam-repo && \
git remote add origin https://github.com/ocaml/opam-repository.git && \
git fetch --depth 1 origin $OPAM_REPO_COMMIT && \
git checkout FETCH_HEAD
RUN opam init --disable-sandboxing --bare --no-setup -k local /tmp/opam-repo && \
opam switch create /root/w --packages=ocaml-base-compiler.$OCAML_VERSION
RUN opam install --no-depexts $BASE_PACKAGES && \
opam clean -a -y && \
rm -rf /tmp/opam-repo
# --- Stage 3: final image (base + switch only) ---
FROM base
COPY --from=opam-setup /root/.opam /root/.opam
COPY --from=opam-setup /root/w/_opam /root/w/_opam
ENV OPAMROOT=/root/.opam OPAMSWITCH=/root/w PATH=/root/w/_opam/bin:$PATH
WORKDIR /root/w

View file

@ -1,23 +1,23 @@
# Migration guide: v0.12 → v0.13
# Migration guide: v0.13 → v0.90
This guide covers breaking changes when upgrading from v0.12.
This guide covers breaking changes when upgrading from v0.13.
## 1. Backend setup: `Collector``Sdk` + `Exporter`
v0.12 used a first-class module `BACKEND` installed into a global slot via
`Collector.set_backend`. v0.13 replaces this with a plain record `Exporter.t`
v0.13 used a first-class module `BACKEND` installed into a global slot via
`Collector.set_backend`. v0.90 replaces this with a plain record `Exporter.t`
installed via `Sdk.set`.
The `with_setup` helper in each client library still exists, so if you use that
you mainly need to rename the module.
```ocaml
(* v0.12 *)
(* v0.13 *)
Opentelemetry_client_ocurl.with_setup ~config () (fun () ->
(* your code *)
())
(* v0.13: same call, internals changed; ~stop removed, ~after_shutdown added *)
(* v0.90: same call, internals changed; ~stop removed, ~after_shutdown added *)
Opentelemetry_client_ocurl.with_setup
~after_shutdown:(fun _exp -> ())
~config () (fun () ->
@ -28,12 +28,12 @@ Opentelemetry_client_ocurl.with_setup
If you called `setup`/`remove_backend` manually:
```ocaml
(* v0.12 *)
(* v0.13 *)
Opentelemetry_client_ocurl.setup ~config ()
(* ... *)
Opentelemetry_client_ocurl.remove_backend ()
(* v0.13 *)
(* v0.90 *)
Opentelemetry_client_ocurl.setup ~config ()
(* ... *)
Opentelemetry_client_ocurl.remove_exporter ()
@ -48,14 +48,14 @@ The most common migration. The module is renamed and the callback argument type
changes from `Scope.t` to `Span.t`.
```ocaml
(* v0.12 *)
(* v0.13 *)
Trace.with_ "my-op" ~attrs:["k", `String "v"] (fun (scope : Scope.t) ->
Scope.add_event scope (fun () -> Event.make "something happened");
Scope.add_attrs scope (fun () -> ["extra", `Int 42]);
do_work ()
)
(* v0.13 *)
(* v0.90 *)
Tracer.with_ "my-op" ~attrs:["k", `String "v"] (fun (span : Span.t) ->
Span.add_event span (Event.make "something happened");
Span.add_attrs span ["extra", `Int 42];
@ -67,7 +67,7 @@ Tracer.with_ "my-op" ~attrs:["k", `String "v"] (fun (span : Span.t) ->
Key differences on the callback argument:
| v0.12 (`Scope.t`) | v0.13 (`Span.t`) |
| v0.13 (`Scope.t`) | v0.90 (`Span.t`) |
|--------------------------------------------|--------------------------------------|
| `scope.trace_id` | `Span.trace_id span` |
| `scope.span_id` | `Span.id span` |
@ -82,10 +82,10 @@ Key differences on the callback argument:
The `~scope` parameter of `Trace.with_` is renamed to `~parent`:
```ocaml
(* v0.12 *)
(* v0.13 *)
Trace.with_ "child" ~scope:parent_scope (fun child -> ...)
(* v0.13 *)
(* v0.90 *)
Tracer.with_ "child" ~parent:parent_span (fun child -> ...)
```
@ -100,7 +100,7 @@ Direct construction of log records and batch-emit is replaced by convenience
functions.
```ocaml
(* v0.12 *)
(* v0.13 *)
Logs.emit [
Logs.make_str ~severity:Severity_number_warn "something went wrong"
]
@ -109,22 +109,22 @@ Logs.emit [
Logs.make_strf ~severity:Severity_number_info "processed %d items" n
]
(* v0.13: simple string *)
(* v0.90: simple string *)
Logger.log ~severity:Severity_number_warn "something went wrong"
(* v0.13: formatted *)
(* v0.90: formatted *)
Logger.logf ~severity:Severity_number_info (fun k -> k "processed %d items" n)
```
If you need to keep the trace/span correlation:
```ocaml
(* v0.12 *)
(* v0.13 *)
Logs.emit [
Logs.make_str ~trace_id ~span_id ~severity:Severity_number_info "ok"
]
(* v0.13 *)
(* v0.90 *)
Logger.log ~trace_id ~span_id ~severity:Severity_number_info "ok"
```
@ -133,17 +133,17 @@ records manually and emit them via a `Logger.t`.
## 4. `Metrics.emit` → emit via a `Meter`
In v0.12 `Metrics.emit` was a top-level function that sent directly to the
collector. In v0.13 metrics go through a `Meter.t`. For most code the change
In v0.13 `Metrics.emit` was a top-level function that sent directly to the
collector. In v0.90 metrics go through a `Meter.t`. For most code the change
is mechanical:
```ocaml
(* v0.12 *)
(* v0.13 *)
Metrics.emit [
Metrics.gauge ~name:"queue.depth" [ Metrics.int ~now depth ]
]
(* v0.13: Meter.default emits to the global provider *)
(* v0.90: Meter.default emits to the global provider *)
Meter.emit1 Meter.default
(Metrics.gauge ~name:"queue.depth" [ Metrics.int ~now depth ])
```
@ -151,11 +151,11 @@ Meter.emit1 Meter.default
`now` is now obtained from the meter's clock rather than `Timestamp_ns.now_unix_ns ()`:
```ocaml
(* v0.12 *)
(* v0.13 *)
let now = Timestamp_ns.now_unix_ns () in
Metrics.emit [ Metrics.sum ~name:"counter" [ Metrics.int ~now n ] ]
(* v0.13 *)
(* v0.90 *)
let now = Clock.now Meter.default.clock in
Meter.emit1 Meter.default
(Metrics.sum ~name:"counter" [ Metrics.int ~now n ])
@ -164,11 +164,11 @@ Meter.emit1 Meter.default
## 5. `Metrics_callbacks.register``Meter.add_cb`
```ocaml
(* v0.12 *)
(* v0.13 *)
Metrics_callbacks.register (fun () ->
[ Metrics.gauge ~name:"foo" [ Metrics.int ~now:... 42 ] ])
(* v0.13: callback now receives a clock *)
(* v0.90: callback now receives a clock *)
Meter.add_cb (fun ~clock () ->
let now = Clock.now clock in
[ Metrics.gauge ~name:"foo" [ Metrics.int ~now 42 ] ])
@ -177,11 +177,11 @@ Meter.add_cb (fun ~clock () ->
After registering callbacks you must tell the SDK to drive them:
```ocaml
(* v0.13: call once after setup to schedule periodic emission *)
(* v0.90: call once after setup to schedule periodic emission *)
Meter.add_to_main_exporter Meter.default
```
In v0.12 this was automatic once `Metrics_callbacks.register` was called.
In v0.13 this was automatic once `Metrics_callbacks.register` was called.
## 6. `GC_metrics.basic_setup` signature unchanged, `setup` changed
@ -191,12 +191,12 @@ to `Gc_metrics`, but the former name persists as a deprecated alias.
If you called the lower-level `GC_metrics.setup exp` directly:
```ocaml
(* v0.12 *)
(* v0.13 *)
GC_metrics.setup exporter
(* or *)
GC_metrics.setup_on_main_exporter ()
(* v0.13 *)
(* v0.90 *)
Gc_metrics.setup () (* uses Meter.default *)
(* or with a specific meter: *)
Gc_metrics.setup ~meter:my_meter ()
@ -207,10 +207,10 @@ Gc_metrics.setup ~meter:my_meter ()
## 7. `Collector.on_tick``Sdk.add_on_tick_callback`
```ocaml
(* v0.12 *)
(* v0.13 *)
Collector.on_tick (fun () -> do_background_work ())
(* v0.13 *)
(* v0.90 *)
Sdk.add_on_tick_callback (fun () -> do_background_work ())
```
@ -220,10 +220,10 @@ Sdk.add_on_tick_callback (fun () -> do_background_work ())
override. This is no longer supported per-call; set it once globally:
```ocaml
(* v0.12 *)
(* v0.13 *)
Trace.with_ "op" ~service_name:"my-svc" (fun _ -> ...)
(* v0.13: set globally before setup *)
(* v0.90: set globally before setup *)
Opentelemetry.Globals.service_name := "my-svc"
Tracer.with_ "op" (fun _ -> ...)
```
@ -233,13 +233,13 @@ Tracer.with_ "op" (fun _ -> ...)
If you held a reference to a backend module:
```ocaml
(* v0.12 *)
(* v0.13 *)
let (module B : Collector.BACKEND) =
Opentelemetry_client_ocurl.create_backend ~config ()
in
Collector.set_backend (module B)
(* v0.13 *)
(* v0.90 *)
let exp : Exporter.t =
Opentelemetry_client_ocurl.create_exporter ~config ()
in
@ -258,7 +258,7 @@ Sdk.set exp
## Quick checklist
- [ ] `Trace.with_` → `Tracer.with_`; callback argument `Scope.t``Span.t`
- [ ] `Otel.Trace.with_` → `Otel.Tracer.with_`; callback argument `Scope.t``Span.t`
- [ ] `Scope.add_event`/`add_attrs``Span.add_event`/`add_attrs` (no thunk wrapper)
- [ ] `~scope:``~parent:` in nested `with_` calls
- [ ] `Logs.emit [Logs.make_str ...]``Logger.log`/`Logger.logf`

View file

@ -5,18 +5,17 @@
(generate_opam_files true)
(source
(github imandra-ai/ocaml-opentelemetry))
(github ocaml-tracing/ocaml-opentelemetry))
(version 0.12)
(version 0.91)
(implicit_transitive_deps false)
(authors "the Imandra team and contributors")
(authors "ocaml-tracing"
"ELLIOTTCABLE <opam@ell.io>"
"the imandra team")
(maintainers
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>")
(maintainers "ocaml-tracing")
(license MIT)
@ -95,7 +94,7 @@
(name opentelemetry-client-ocurl)
(depends
(ocaml
(>= "4.08"))
(>= "4.11"))
(mtime
(>= "1.4"))
; for spans
@ -107,15 +106,18 @@
(odoc :with-doc)
(ezcurl
(>= 0.2.3))
ocurl
(alcotest :with-test))
curl
(alcotest :with-test)
(cohttp-lwt-unix :with-test)
(containers :with-test)
(logs :with-test))
(synopsis "Collector client for opentelemetry, using http + ezcurl"))
(package
(name opentelemetry-client-ocurl-lwt)
(depends
(ocaml
(>= "4.08"))
(>= "4.11"))
(mtime
(>= "1.4"))
(opentelemetry
@ -127,10 +129,14 @@
(>= 0.2.3))
ocurl
(lwt
(>= "5.3"))
(>= "5.7.3"))
(lwt_ppx
(>= "2.0"))
(alcotest :with-test))
ambient-context-lwt
(alcotest :with-test)
(cohttp-lwt-unix :with-test)
(containers :with-test)
(logs :with-test))
(synopsis "Collector client for opentelemetry, using ezcurl-lwt"))
(package
@ -172,7 +178,7 @@
(cohttp
(>= "6.0.0"))
(cohttp-lwt
(>= "6.0.0"))
(and (>= "6.0.0") (< "6.2.0")))
(alcotest :with-test))
(synopsis "Opentelemetry tracing for Cohttp HTTP servers"))
@ -199,11 +205,7 @@
cohttp-lwt
cohttp-lwt-unix
(alcotest :with-test)
(containers :with-test)
(opentelemetry-lwt
(and
:with-test
(= :version))))
(containers :with-test))
(synopsis "Collector client for opentelemetry, using cohttp + lwt"))
(package
@ -228,5 +230,10 @@
(>= 2.0.1))
(alcotest :with-test)
(containers :with-test)
(cohttp-lwt-unix :with-test))
(cohttp-lwt-unix :with-test)
(logs :with-test)
(opentelemetry-lwt
(and
:with-test
(= :version))))
(synopsis "Collector client for opentelemetry, using cohttp + eio"))

View file

@ -1,16 +1,12 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Collector client for opentelemetry, using cohttp + eio"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "5.00"}
@ -27,6 +23,8 @@ depends: [
"alcotest" {with-test}
"containers" {with-test}
"cohttp-lwt-unix" {with-test}
"logs" {with-test}
"opentelemetry-lwt" {with-test & = version}
]
build: [
["dune" "subst"] {dev}
@ -42,4 +40,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,16 +1,12 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Collector client for opentelemetry, using cohttp + lwt"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
@ -26,7 +22,6 @@ depends: [
"cohttp-lwt-unix"
"alcotest" {with-test}
"containers" {with-test}
"opentelemetry-lwt" {with-test & = version}
]
build: [
["dune" "subst"] {dev}
@ -42,4 +37,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,28 +1,28 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Collector client for opentelemetry, using ezcurl-lwt"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
"ocaml" {>= "4.11"}
"mtime" {>= "1.4"}
"opentelemetry" {= version}
"opentelemetry-client" {= version}
"odoc" {with-doc}
"ezcurl-lwt" {>= "0.2.3"}
"ocurl"
"lwt" {>= "5.3"}
"lwt" {>= "5.7.3"}
"lwt_ppx" {>= "2.0"}
"ambient-context-lwt"
"alcotest" {with-test}
"cohttp-lwt-unix" {with-test}
"containers" {with-test}
"logs" {with-test}
]
build: [
["dune" "subst"] {dev}
@ -38,4 +38,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,26 +1,25 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Collector client for opentelemetry, using http + ezcurl"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
"ocaml" {>= "4.11"}
"mtime" {>= "1.4"}
"opentelemetry" {= version}
"opentelemetry-client" {= version}
"odoc" {with-doc}
"ezcurl" {>= "0.2.3"}
"ocurl"
"curl"
"alcotest" {with-test}
"cohttp-lwt-unix" {with-test}
"containers" {with-test}
"logs" {with-test}
]
build: [
["dune" "subst"] {dev}
@ -36,4 +35,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,17 +1,13 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Client SDK for https://opentelemetry.io"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
tags: ["tracing" "opentelemetry" "sdk"]
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"opentelemetry" {= version}
@ -33,4 +29,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,16 +1,12 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Opentelemetry tracing for Cohttp HTTP servers"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
@ -37,4 +33,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,16 +1,12 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Opentelemetry-based reporter for Logs"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
@ -37,4 +33,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,17 +1,13 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis: "Lwt-compatible instrumentation for https://opentelemetry.io"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
tags: ["instrumentation" "tracing" "opentelemetry" "datadog" "lwt"]
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
@ -37,4 +33,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -1,18 +1,14 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.12"
version: "0.91"
synopsis:
"Core library for instrumentation and serialization for https://opentelemetry.io"
maintainer: [
"Simon Cruanes <simon.cruanes.2007@m4x.org>"
"Matt Bray <mattjbray@gmail.com>"
"ELLIOTTCABLE <opam@ell.io>"
]
authors: ["the Imandra team and contributors"]
maintainer: ["ocaml-tracing"]
authors: ["ocaml-tracing" "ELLIOTTCABLE <opam@ell.io>" "the imandra team"]
license: "MIT"
tags: ["instrumentation" "tracing" "opentelemetry" "datadog" "jaeger"]
homepage: "https://github.com/imandra-ai/ocaml-opentelemetry"
bug-reports: "https://github.com/imandra-ai/ocaml-opentelemetry/issues"
homepage: "https://github.com/ocaml-tracing/ocaml-opentelemetry"
bug-reports: "https://github.com/ocaml-tracing/ocaml-opentelemetry/issues"
depends: [
"dune" {>= "3.11"}
"ocaml" {>= "4.08"}
@ -45,4 +41,4 @@ build: [
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/imandra-ai/ocaml-opentelemetry.git"
dev-repo: "git+https://github.com/ocaml-tracing/ocaml-opentelemetry.git"

View file

@ -169,6 +169,7 @@ let create_exporter ?(config = Config.make ()) ~sw ~env () =
let consumer = create_consumer ~config ~sw ~env () in
let bq =
Opentelemetry_client_sync.Bounded_queue_sync.create
~measure:Any_signal_l.length
~high_watermark:Bounded_queue.Defaults.high_watermark ()
in
Exporter_queued.create ~clock:Clock.ptime_clock ~q:bq ~consumer ()

View file

@ -102,6 +102,7 @@ let create_exporter ?(config = Config.make ()) () =
let consumer = create_consumer ~config () in
let bq =
Opentelemetry_client_sync.Bounded_queue_sync.create
~measure:OTEL.Any_signal_l.length
~high_watermark:Bounded_queue.Defaults.high_watermark ()
in
Exporter_queued.create ~clock:Clock.ptime_clock ~q:bq ~consumer ()

View file

@ -79,6 +79,7 @@ let create_exporter ?(config = Config.make ()) () =
let consumer = create_consumer ~config () in
let bq =
Opentelemetry_client_sync.Bounded_queue_sync.create
~measure:OTEL.Any_signal_l.length
~high_watermark:Bounded_queue.Defaults.high_watermark ()
in
Exporter_queued.create ~clock:Clock.ptime_clock ~q:bq ~consumer ()

View file

@ -24,7 +24,7 @@ val setup : ?config:Config.t -> ?enable:bool -> unit -> unit
val remove_backend : unit -> unit Lwt.t
(** Shutdown current backend
@since NEXT_RELEASE *)
@since 0.90 *)
val with_setup :
?after_shutdown:(Opentelemetry.Exporter.t -> unit) ->

View file

@ -81,6 +81,7 @@ let create_exporter ?(config = Config.make ()) () : OTEL.Exporter.t =
let consumer = consumer ~config () in
let bq =
Opentelemetry_client_sync.Bounded_queue_sync.create
~measure:OTEL.Any_signal_l.length
~high_watermark:OTELC.Bounded_queue.Defaults.high_watermark ()
in

View file

@ -10,7 +10,7 @@ val consumer :
(** Consumer that pulls from a queue *)
val create_exporter : ?config:Config.t -> unit -> Opentelemetry.Exporter.t
(** @since NEXT_RELEASE *)
(** @since 0.90 *)
val create_backend : ?config:Config.t -> unit -> Opentelemetry.Exporter.t
[@@deprecated "use create_exporter"]
@ -26,7 +26,7 @@ val setup : ?config:Config.t -> ?enable:bool -> unit -> unit
after a little while. *)
val remove_exporter : unit -> unit
(** @since NEXT_RELEASE *)
(** @since 0.90 *)
val remove_backend : unit -> unit
[@@deprecated "use remove_exporter"]

View file

@ -10,7 +10,7 @@
than [add_batching (limit_interval ~min_interval e)], because in the later
case we might be dismissing a whole large batch at ine
@since NEXT_RELEASE *)
@since 0.90 *)
open Common_.OTEL

View file

@ -12,10 +12,12 @@ let str_to_hex (s : string) : string =
Opentelemetry_util.Util_bytes_.bytes_to_hex (Bytes.unsafe_of_string s)
(** Report the error on stderr. *)
let report_err ~level:(provided_level : [ `Debug | `Auto ]) (err : t) : unit =
let report_err ~level:(provided_level : [ `Debug | `Warning | `Auto ]) (err : t)
: unit =
let compute_level lvl =
match provided_level with
| `Debug -> Opentelemetry.Self_debug.Debug
| `Warning -> Opentelemetry.Self_debug.Warning
| `Auto -> lvl
in
match err with
@ -24,7 +26,7 @@ let report_err ~level:(provided_level : [ `Debug | `Auto ]) (err : t) : unit =
"opentelemetry: ctrl-c captured, stopping")
| `Failure msg ->
Opentelemetry.Self_debug.log (compute_level Error) (fun () ->
Printf.sprintf "opentelemetry: export failed: %s" msg)
Printf.sprintf "opentelemetry: export failed:\n%s" msg)
| `Status
( code,
{
@ -57,8 +59,9 @@ let decode_invalid_http_response ~attempt_descr ~code ~url (body : string) : t =
let bt = Printexc.get_backtrace () in
`Failure
(Printf.sprintf
"httpc: decoding of status (url=%S, code=%d) failed with:\n\
"http server at %s returned code %d;\n\
trying to decode the body as protobuf failed:\n\
%s\n\
HTTP body: %s\n\
raw HTTP body (hex): %s\n\
%s"
url code (Printexc.to_string e) (str_to_hex body) bt)

View file

@ -75,12 +75,12 @@ type t = {
self_metrics: bool;
(** If true, the OTEL library will regularly emit metrics about itself.
Default [false].
@since NEXT_RELEASE *)
@since 0.90 *)
http_concurrency_level: int option;
(** How many HTTP requests can be done simultaneously (at most)? This can
be used to represent the size of a pool of workers where each worker
gets a batch to send, send it, and repeats.
@since NEXT_RELEASE *)
@since 0.90 *)
retry_max_attempts: int;
(** Maximum number of retry attempts for failed exports. 0 means no retry,
1 means one retry after initial failure. Default 3. *)

View file

@ -82,7 +82,7 @@ end = struct
| Error err
when should_retry err && attempt < self.config.retry_max_attempts ->
let delay_s = delay_ms /. 1000. in
Export_error.report_err ~level:`Debug err;
Export_error.report_err ~level:`Warning err;
let* () = sleep_s delay_s in
let next_delay =

View file

@ -9,6 +9,7 @@
Opentelemetry_client
-open
Opentelemetry_atomic)
(modules :standard \ gen_types_)
(optional) ; lwt
(libraries
opentelemetry.util
@ -26,18 +27,13 @@
lwt.unix)
(synopsis "Lwt-specific helpers for opentelemetry-client"))
(rule
(enabled_if
(and
%{lib-available:lwt}
(>= %{version:lwt} 6.0)))
(action
(copy types_.ml.6 types_.ml)))
(executable
(name gen_types_)
(modules gen_types_))
(rule
(enabled_if
(and
%{lib-available:lwt}
(< %{version:lwt} 6.0)))
(enabled_if %{lib-available:lwt})
(deps types_.ml.5 types_.ml.6)
(target types_.ml)
(action
(copy types_.ml.5 types_.ml)))
(run ./gen_types_.exe %{version:lwt})))

View file

@ -0,0 +1,23 @@
let copy_file src dst =
let ic = open_in src in
let oc = open_out dst in
let buf = Bytes.create 1024 in
(try
while true do
let n = input ic buf 0 (Bytes.length buf) in
if n = 0 then raise End_of_file;
output oc buf 0 n
done
with End_of_file -> ());
close_in ic;
close_out oc
let () =
let version = Sys.argv.(1) in
let major =
try Scanf.sscanf version "%d.%s" (fun maj _ -> maj) with _ -> 0
in
if major >= 6 then
copy_file "types_.ml.6" "types_.ml"
else
copy_file "types_.ml.5" "types_.ml"

View file

@ -88,21 +88,27 @@ type 'a state = {
high_watermark: int;
q: 'a Q.t;
on_non_empty: Cb_set.t;
measure: 'a -> int;
}
let measure_all_ measure xs = List.fold_left (fun acc x -> acc + measure x) 0 xs
let push (self : _ state) x =
if x <> [] then (
match
Q.push_while_not_full self.q ~high_watermark:self.high_watermark x
with
| Closed ->
ignore (Atomic.fetch_and_add self.n_discarded (List.length x) : int)
let n = measure_all_ self.measure x in
ignore (Atomic.fetch_and_add self.n_discarded n : int)
| Pushed { num_discarded } ->
if num_discarded > 0 then (
ignore (Atomic.fetch_and_add self.n_discarded num_discarded : int);
let n_signals = measure_all_ self.measure x in
let total = Atomic.fetch_and_add self.n_discarded n_signals in
Opentelemetry.Self_debug.log Warning (fun () ->
Printf.sprintf "otel: dropped %d signals (exporter queue full)"
num_discarded)
Printf.sprintf
"otel: dropped %d signals (queue full: %d/%d, total dropped: %d)"
n_signals (Q.size self.q) self.high_watermark (total + n_signals))
);
(* wake up potentially asleep consumers *)
Cb_set.trigger self.on_non_empty
@ -129,13 +135,14 @@ let to_bounded_queue (self : 'a state) : 'a BQ.t =
recv = { try_pop; on_non_empty; common };
}
let create ~high_watermark () : _ BQ.t =
let create ?(measure = fun _ -> 1) ~high_watermark () : _ BQ.t =
let st =
{
high_watermark;
q = Q.create ();
n_discarded = Atomic.make 0;
on_non_empty = Cb_set.create ();
measure;
}
in
to_bounded_queue st

View file

@ -2,6 +2,11 @@
This is not the fastest queue but it should be versatile. *)
val create : high_watermark:int -> unit -> 'a Bounded_queue.t
val create :
?measure:('a -> int) -> high_watermark:int -> unit -> 'a Bounded_queue.t
(** [create ~high_watermark ()] creates a new bounded queue based on
{!Sync_queue} *)
{!Sync_queue}.
@param measure
maps each item to its signal count (e.g. number of spans in a batch). Used
to report accurate signal counts when items are dropped. Default:
[fun _ -> 1]. *)

View file

@ -19,6 +19,11 @@ let pp out = function
| Metrics m -> pp_list Proto.Metrics.pp_metric out m
| Logs l -> pp_list Proto.Logs.pp_log_record out l
let length = function
| Spans l -> List.length l
| Metrics l -> List.length l
| Logs l -> List.length l
let of_logs_or_empty = function
| [] -> []
| l -> [ Logs l ]

View file

@ -128,4 +128,4 @@ val default_kind : Span_kind.t ref
val k_ambient : t Context.key
(** Context key to carry around a {!Span.t} in ambient context.
@since NEXT_RELEASE *)
@since 0.90 *)

View file

@ -1,3 +1,5 @@
(** Hooks to add attributes to every span or log *)
type t = unit -> Key_value.t list
(** A dynamic enricher is a callback that produces high-cardinality attributes
at span/log-record creation time. This enables "wide events". *)

View file

@ -5,7 +5,7 @@
generally very fast (amortized), in most cases; the slow path is only when
the batch needs to be emitted.
@since NEXT_RELEASE *)
@since 0.90 *)
open Opentelemetry_emitter

View file

@ -20,7 +20,7 @@ let service_instance_id = ref None
@since 0.12 *)
let service_version = ref None
(** @since NEXT_RELEASE *)
(** @since 0.90 *)
let sdk_version : string = Version.version
let instrumentation_library =

View file

@ -57,7 +57,7 @@ let minimum_min_interval_ = Mtime.Span.(100 * ms)
let default_min_interval_ = Mtime.Span.(4 * s)
let clamp_interval_ interval =
if Mtime.Span.is_shorter interval ~than:minimum_min_interval_ then
if Mtime.Span.compare interval minimum_min_interval_ < 0 then
minimum_min_interval_
else
interval

View file

@ -5,7 +5,7 @@ module Core = Opentelemetry_core
module Interval_limiter = Interval_limiter
(** Utility to limit the frequency of some event
@since NEXT_RELEASE *)
@since 0.90 *)
(** {2 Wire format} *)
@ -27,15 +27,15 @@ module Exporter = struct
include Exporter
(** Get a tracer from this exporter.
@since NEXT_RELEASE *)
@since 0.90 *)
let get_tracer (self : t) : Tracer.t = Tracer.of_exporter self
(** Get a meter from this exporter.
@since NEXT_RELEASE *)
@since 0.90 *)
let get_meter (self : t) : Meter.t = Meter.of_exporter self
(** Get a logger from this exporter.
@since NEXT_RELEASE *)
@since 0.90 *)
let get_logger (self : t) : Logger.t = Logger.of_exporter self
end
@ -43,17 +43,17 @@ module Sdk = struct
include Sdk
(** Get a tracer forwarding to the current main exporter.
@since NEXT_RELEASE *)
@since 0.90 *)
let get_tracer ?name ?version ?attrs ?__MODULE__ () =
Trace_provider.get_tracer ?name ?version ?attrs ?__MODULE__ ()
(** Get a meter forwarding to the current main exporter.
@since NEXT_RELEASE *)
@since 0.90 *)
let get_meter ?name ?version ?attrs ?__MODULE__ () =
Meter_provider.get_meter ?name ?version ?attrs ?__MODULE__ ()
(** Get a logger forwarding to the current main exporter.
@since NEXT_RELEASE *)
@since 0.90 *)
let get_logger ?name ?version ?attrs ?__MODULE__ () =
Log_provider.get_logger ?name ?version ?attrs ?__MODULE__ ()
@ -165,7 +165,7 @@ module Trace_context = Trace_context
module Gc_metrics = Gc_metrics
module Aswitch = Aswitch
(** @since NEXT_RELEASE *)
(** @since 0.90 *)
module Alist = Alist
(** Atomic list, for internal usage

View file

@ -54,8 +54,9 @@ let run_tick_callbacks : unit -> unit = Globals.run_tick_callbacks
from their ticker. *)
let tick : unit -> unit = Globals.run_tick_callbacks
let set ?(traces = Provider_config.default) ?(metrics = Provider_config.default)
?(logs = Provider_config.default) (exp : Exporter.t) : unit =
let set ?(traces = Provider_config.make ~batch:400 ())
?(metrics = Provider_config.make ~batch:200 ())
?(logs = Provider_config.make ~batch:400 ()) (exp : Exporter.t) : unit =
Self_debug.log Info (fun () -> "opentelemetry: SDK set up");
Atomic.set exporter (Some exp);
let tracer : Tracer.t =

View file

@ -16,17 +16,21 @@ let string_of_level = function
| Warning -> "warning"
| Error -> "error"
let to_stderr ?(min_level = Warning) () : unit =
open struct
let[@inline] int_of_level_ = function
| Debug -> 0
| Info -> 1
| Warning -> 2
| Error -> 3
in
let threshold = int_of_level_ min_level in
end
let level_above ~min_level level : bool =
int_of_level_ level >= int_of_level_ min_level
let to_stderr ?(min_level = Warning) () : unit =
logger :=
fun level mk_msg ->
if int_of_level_ level >= threshold then (
if level_above ~min_level level then (
let msg = mk_msg () in
Printf.eprintf "[otel:%s] %s\n%!" (string_of_level level) msg
)

View file

@ -8,7 +8,7 @@
Self_debug.log Info (fun () -> Printf.sprintf "batch flushed %d items" n)
]}.
@since NEXT_RELEASE *)
@since 0.90 *)
type level =
| Debug
@ -25,6 +25,11 @@ val logger : logger ref
val string_of_level : level -> string
(** String representation of a level. *)
val level_above : min_level:level -> level -> bool
(** [level_above ~min_level lvl] is true if messages at level [lvl] should be
logged.
@since NEXT_RELEASE *)
val log : level -> (unit -> string) -> unit
(** [log level mk_msg] emits a diagnostic message if the current logger is
active. [mk_msg] is called lazily only if the message will be emitted. *)

View file

@ -1,6 +1,9 @@
open Common_
module Extensions = struct
(* extend [Trace]'s types with OTEL specific variants, eg to have a
[Trace.span] be a wrapper around [OTEL.Span.t], or to declare custom actions
to link spans together, or to be able to use [OTEL]-specific metrics types *)
type Trace.span += Span_otel of OTEL.Span.t
type Trace.extension_event +=
@ -21,6 +24,14 @@ end
open Extensions
(* Inject ambient span into [Trace], relying on the [Ambient_context]
library. We use the generic ambient context to carry a [Hmap.t] around with
possible the current [Trace.span], and it is also used by [OTEL] itself
(ambient [OTEL.Span_ctx.t]).
This mechanism is used by [Trace] so that nested [Trace.with_span] can infer
the correct parent-child relation from implicit context, and produce OTEL
spans accordingly; without it every span would be parentless. *)
module Ambient_span_provider_ = struct
let get_current_span () =
match OTEL.Ambient_span.get () with

View file

@ -72,13 +72,13 @@ val link_spans : Otrace.span -> Otrace.span -> unit
val link_span_to_otel_ctx : Otrace.span -> OTEL.Span_ctx.t -> unit
(** [link_spans sp1 sp_ctx2] modifies [sp1] by adding a span link to [sp_ctx2].
It must be the case that [sp1] is a currently active span.
@since NEXT_RELEASE *)
@since 0.90 *)
val set_span_kind : Otrace.span -> OTEL.Span.kind -> unit
(** [set_span_kind sp k] sets the span's kind. *)
val set_span_status : Otrace.span -> OTEL.Span_status.t -> unit
(** @since NEXT_RELEASE *)
(** @since 0.90 *)
val record_exception : Otrace.span -> exn -> Printexc.raw_backtrace -> unit
(** Record exception in the current span. *)

View file

@ -1,4 +1,4 @@
(tests
(names test_client_lib)
(package opentelemetry)
(package opentelemetry-client)
(libraries alcotest opentelemetry-client))

View file

@ -19,7 +19,11 @@ let test_exporter : Otel.Exporter.t =
let with_test_exporter f =
(* uncomment for eprintf debugging: *)
(* let test_exporter = Opentelemetry_client.Exporter_debug.debug test_exporter in*)
Otel.Sdk.set test_exporter;
Otel.Sdk.set
~traces:(Otel.Provider_config.make ())
~metrics:(Otel.Provider_config.make ())
~logs:(Otel.Provider_config.make ())
test_exporter;
Fun.protect f ~finally:(fun () ->
let sq = Opentelemetry_client_sync.Sync_queue.create () in
Otel.Sdk.remove