Packages

Gleam Client for Sentry Error tracking

Current section

Files

Jump to
gleam_sentry gen docs index.html
Raw

gen/docs/index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>gleam_sentry</title>
<link rel="stylesheet" href="./index.css" type="text/css" />
<!-- The docs_config.js file is provided by HexDocs and shared
between multiple versions of the same package. -->
<script src="./docs_config.js"></script>
</head>
<body>
<header class="page-header">
<h2>
gleam_sentry
<span id="project-version"> - v0.1.0 </span>
</h2>
</header>
<div class="page">
<nav class="sidebar">
<a class="sidebar-toggle" href="#" tabindex="0">
<svg
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="bars"
class="svg-inline--fa fa-bars fa-w-14"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 448 512"
>
<path
fill="#fff"
d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"
>
</path>
</svg>
</a>
<h2>Pages</h2>
<ul>
<li><a href="./index.html">README</a></li>
</ul>
<h2>Modules</h2>
<ul>
<li><a href="./gleam_sentry&#x2f;">gleam_sentry</a></li>
</ul>
</nav>
<main class="content">
<h1>gleam_sentry</h1>
<p>Report runtime exceptions to https://sentry.io</p>
<h2>Usage</h2>
<h4>Intialise a client with your DSN and environment name.</h4>
<pre><code class="language-rust"> import gleam_sentry as sentry
let dsn = &quot;https://public_key@o0.ingest.sentry.io/123&quot;
let environment = &quot;production&quot;
assert Ok(client) = sentry.init(dsn, environment)
</code></pre>
<h4>Capture an exception</h4>
<pre><code class="language-rust">sentry.capture_exception(client, reason, stacktrace, timestamp)
</code></pre>
<p>The types for reason and stacktrace are defined in the <a href="https://github.com/midas-framework/beam">gleam/beam</a> project along with cast functions that allow you to get these values form logger events.</p>
<h4>Logger integration</h4>
<pre><code class="language-rust">// my_app/logger.gleam
import gleam/beam.{ExitReason, Stacktrace}
pub fn handle(client, reason: ExitReason, stacktrace: Stacktrace, timestamp) {
sentry.capture_exception(client, reason, stacktrace, timestamp)
Nil
}
</code></pre>
<pre><code class="language-rust">// During startup
import gleam/beam/logger
import my_app/logger as my_logger
pub fn start(){
logger.add_handler(my_logger.handle(client, _, _, _))
}
</code></pre>
<h2>Future</h2>
<p>gleam_sentry currently reports errors from the beam runtime system, and as such could be implemented as an erlang library.
I have not used existing projects (see prior art below) as only Elixir projects are based on the new logger.</p>
<p>I would like this project to be useful in erlang projects.
It would also be interesting to have a more general purpose span/context/error handling framework that this could plug in to.</p>
<h2>Prior Art</h2>
<h3>Raven</h3>
<p>https://github.com/artemeff/raven-erlang</p>
<p>erlang project, integrates with lager and error_logger.</p>
<ul>
<li>Has an empty supervisor, just so it can be started as an app which adds a logger handler.</li>
<li>Every capture results in a call to sentry. https://github.com/artemeff/raven-erlang/blob/master/src/raven.erl#L46</li>
<li>Uses httpc and manually calls zlib. https://github.com/artemeff/raven-erlang/blob/master/src/raven.erl#L76-L86</li>
<li>Has a bunch of hardcoded mappers from error types. https://github.com/artemeff/raven-erlang/blob/master/src/raven_error_logger.erl#L108-L184
<ul>
<li>NOTE: these are old format so not useful to reproduce</li>
</ul>
</li>
</ul>
<h3>Sparrow</h3>
<p>https://github.com/ExpressApp/sparrow/tree/master/lib/sparrow</p>
<p>Elixir project, uses new logger</p>
<ul>
<li>Starts a coordinator and task supervisor, is this necessary with the infrastructure that already exists in logger?</li>
<li>It has a Client behaviour module but only one implementation directly in the library.</li>
</ul>
</main>
</div>
<script>const pride = () => document.querySelector('body').classList.toggle('show-pride')</script>
<a class="pride-button" onclick="pride()"></a>
<footer class="pride" onclick="pride()">
<div class="blue">Lucy</div>
<div class="pink">says</div>
<div class="white">trans</div>
<div class="pink">rights</div>
<div class="blue"></div>
</footer>
<script>
if (typeof versionNodes !== 'undefined') {
const versionElement = document.getElementById('project-version')
const currentVersion = "v0.1.0"
if (!versionNodes.find(element => element.version === currentVersion)) {
versionNodes.unshift({ version: currentVersion, url: '#' })
}
const versionsDropdown = `
<form autocomplete="off">
<select onchange="window.location.href = this.value">
${versionNodes.map(element =>
`
<option value="${element.url}" ${element.version === currentVersion ? "selected disabled" : ""}>
${element.version}
</option>
`
).join('')}
</select>
</form>
`
versionElement.innerHTML = versionsDropdown
}
</script>
</body>
</html>