ocaml-opentelemetry/opentelemetry-logs/Opentelemetry_logs/index.html
2026-04-06 19:57:49 +00:00

20 lines
5.4 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Opentelemetry_logs (opentelemetry-logs.Opentelemetry_logs)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">Index</a> &#x00BB; <a href="../index.html">opentelemetry-logs</a> &#x00BB; Opentelemetry_logs</nav><header class="odoc-preamble"><h1>Module <code><span>Opentelemetry_logs</span></code></h1></header><div class="odoc-content"><div class="odoc-spec"><div class="spec value anchored" id="val-emit_telemetry_tag"><a href="#val-emit_telemetry_tag" class="anchor"></a><code><span><span class="keyword">val</span> emit_telemetry_tag : <span>bool <a href="../../logs/Logs/Tag/index.html#type-def">Logs.Tag.def</a></span></span></code></div><div class="spec-doc"><p><code>emit_telemetry_tag</code> is a logging tag that when applied to a log, determines if a log will be emitted by the tracing/telemetry backend.</p><p>Since some OTel backends can cause deadlocks if used during a GC alarm, this is useful for when you may want logging during a GC alarm. It is also useful if you want to log sensitive information, but not report it via Opentelemetry.</p><p>If this tag is not set on a log, said log will be emitted by default if the otel reporter is registered.</p><p>Example:</p><pre class="language-ocaml"><code> let tags =
Logs.Tag.(add Opentelemetry_logs.emit_telemetry_tag false other_tags)
in
Logs.info (fun m -&gt;
m ~tags &quot;This log will not be sent to the telemetry backend&quot;)</code></pre></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-emit_telemetry"><a href="#val-emit_telemetry" class="anchor"></a><code><span><span class="keyword">val</span> emit_telemetry : <span>bool <span class="arrow">&#45;&gt;</span></span> <a href="../../logs/Logs/Tag/index.html#type-set">Logs.Tag.set</a></span></code></div><div class="spec-doc"><p><code>emit_telemetry emit_or_not</code> creates a tag set with the <a href="#val-emit_telemetry_tag"><code>emit_telemetry_tag</code></a> as its only member</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-otel_reporter"><a href="#val-otel_reporter" class="anchor"></a><code><span><span class="keyword">val</span> otel_reporter :
<span><span class="optlabel">?attributes</span>:<span><span>(string * <a href="../../opentelemetry/Opentelemetry/index.html#type-value">Opentelemetry.value</a>)</span> list</span> <span class="arrow">&#45;&gt;</span></span>
<span>unit <span class="arrow">&#45;&gt;</span></span>
<a href="../../logs/Logs/index.html#type-reporter">Logs.reporter</a></span></code></div><div class="spec-doc"><p><code>otel_reporter ?tag_value_pp_buffer_size ?attrs ()</code> creates a <code>Logs.reporter</code> that will create and emit an OTel log with the following info:</p><ul><li><p>Log severity is converted to OTel severity as follows:</p><pre class="language-ocaml"><code> module Otel = Opentelemetry
match level with
| Logs.App -&gt; Otel.Logs.Severity_number_info (* like info, but less severe *)
| Logs.Info -&gt; Otel.Logs.Severity_number_info2
| Logs.Error -&gt; Otel.Logs.Severity_number_error
| Logs.Warning -&gt; Otel.Logs.Severity_number_warn
| Logs.Debug -&gt; Otel.Logs.Severity_number_debug</code></pre></li><li>message is the formatted with the given <code>fmt</code> and <code>msgf</code> function, and emitted as the log body</li><li><code>header</code> and <code>src</code> will be added as attributes <code>(&quot;header&quot;, `String header)</code> and <code>(&quot;src&quot;, `String (Logs.Src.name src))</code> respectively</li><li><code>tags</code> will be also added as attributes, with the tag name as the key, and the value formatted via its formatter as the value.</li><li><code>attributes</code> will also be added as attributes, and are useful for setting static attributes such as a library name</li></ul><p>Example use: <code>Logs.set_reporter (Opentelemetery_logs.otel_reporter ())</code></p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-attach_otel_reporter"><a href="#val-attach_otel_reporter" class="anchor"></a><code><span><span class="keyword">val</span> attach_otel_reporter :
<span><span class="optlabel">?attributes</span>:<span><span>(string * <a href="../../opentelemetry/Opentelemetry/index.html#type-value">Opentelemetry.value</a>)</span> list</span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../../logs/Logs/index.html#type-reporter">Logs.reporter</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../../logs/Logs/index.html#type-reporter">Logs.reporter</a></span></code></div><div class="spec-doc"><p><code>attach_otel_reporter ?attributes reporter</code> will create a reporter that first calls the reporter passed as an argument, then an otel report created via <a href="#val-otel_reporter"><code>otel_reporter</code></a>, for every log. This is useful for if you want to emit logs to stderr and to OTel at the same time.</p><p>Example:</p><pre class="language-ocaml"><code> let reporter = Logs_fmt.reporter () in
Logs.set_reporter
(Opentelemetry_logs.attach_otel_reporter ?attributes reporter)</code></pre></div></div></div></body></html>