rust.json 12 KB

123456
  1. {
  2. "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>Sentry-Rust is distributed as a normal crate from crates.io. You can add\nit to your project as a dependency in your <cite>Cargo.toml</cite> file:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">[dependencies]</span>\n<span style=\"color: #111111\">sentry</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #e8535a\">&quot;0.3&quot;</span>\n</pre></div>\n</div>\n<p>Additionally you can configure a bunch of features to enable or disable\nfunctionality in the crate. By default the most common features are\ncompiled into the crate. For a list of features that are available refer\nto the <a class=\"reference external\" href=\"https://docs.rs/sentry\">API Documentation</a>.</p>\n</div>\n\n\n<div class=\"section\" id=\"configuring-the-client\">\n<h2>Configuring the Client</h2>\n<p>The client is configured by calling <code class=\"docutils literal\"><span class=\"pre\">sentry::init</span></code> with a value that can\nbe converted into a configuration object. These are the most common\nvalues:</p>\n<ul class=\"simple\">\n<li><em>an empty tuple</em>: in that case the client is configured from the\n<span class=\"target\" id=\"index-0\"></span><code class=\"xref std std-envvar docutils literal\"><span class=\"pre\">SENTRY_DSN</span></code> environment variable.</li>\n<li><em>a string holding a DSN</em>: if you pass a string then a DSN is parsed\nand the client is initialized with that DSN.</li>\n<li><em>a tuple in the form (dsn, options)</em>: This is a form where the client\nis configured with a DSN plus an options object that allows you to\nconfigure additional features.</li>\n</ul>\n<p>This is the most common case for client configuration:</p>\n<div class=\"highlight-rust\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">extern</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">crate</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry;</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n\n<span style=\"color: #2eb0f7\">fn</span> <span style=\"color: #111111\">main()</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">{</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">init(</span><span style=\"color: #e8535a\">&quot;___PUBLIC_DSN___&quot;</span><span style=\"color: #111111\">);</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #34c08b; font-style: italic\">// code using sentry goes here.</span>\n<span style=\"color: #111111\">}</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n</pre></div>\n</div>\n<p>To configure releases automatically you can use the\n<code class=\"docutils literal\"><span class=\"pre\">sentry_crate_release!</span></code> macro in combination with the tuple config\nsyntax:</p>\n<div class=\"highlight-rust\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #34c08b\">#[macro_use]</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">extern</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">crate</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry;</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n\n<span style=\"color: #2eb0f7\">fn</span> <span style=\"color: #111111\">main()</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">{</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">init((</span><span style=\"color: #e8535a\">&quot;___PUBLIC_DSN___&quot;</span><span style=\"color: #111111\">,</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">ClientOptions</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">{</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">release</span>: <span style=\"color: #111111\">sentry_crate_release</span><span style=\"color: #4b4f5c\">!</span><span style=\"color: #111111\">(),</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">..</span><span style=\"color: #2eb0f7\">Default</span>::<span style=\"color: #111111\">default()</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">}));</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #34c08b; font-style: italic\">// code using sentry goes here.</span>\n<span style=\"color: #111111\">}</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"reporting-errors\">\n<h2>Reporting Errors</h2>\n<p>Once Sentry is configured errors and other events can be emitted. Since\nRust has different mechanisms by which errors can be issued different\nfunctionality is provided for them. By default support for the new\n<a class=\"reference external\" href=\"https://docs.rs/failure\">failure</a> error system is provided.</p>\n<p>For instance to report a <code class=\"docutils literal\"><span class=\"pre\">failure::Error</span></code> this code can be used:</p>\n<div class=\"highlight-rust\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">use</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">integrations</span>::<span style=\"color: #111111\">failure</span>::<span style=\"color: #111111\">capture_error;</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n\n<span style=\"color: #2eb0f7\">let</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">result</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #4b4f5c\">=</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">match</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">a_function_that_might_fail()</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">{</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">Ok</span><span style=\"color: #111111\">(val)</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #4b4f5c\">=&gt;</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">val,</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">Err</span><span style=\"color: #111111\">(err)</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #4b4f5c\">=&gt;</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">{</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">capture_error(</span><span style=\"color: #4b4f5c\">&amp;</span><span style=\"color: #111111\">err);</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">return</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #2eb0f7\">Err</span><span style=\"color: #111111\">(err);</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">}</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #111111\">};</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n</pre></div>\n</div>\n<p>For this particular case a shortcut is also provided:</p>\n<div class=\"highlight-rust\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">use</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">integrations</span>::<span style=\"color: #111111\">failure</span>::<span style=\"color: #111111\">tap_error;</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n\n<span style=\"color: #2eb0f7\">let</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">result</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #4b4f5c\">=</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">tap_error(a_function_that_might_fail())</span><span style=\"color: #4b4f5c\">?</span><span style=\"color: #111111\">;</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n</pre></div>\n</div>\n<p>Similarly the functions <code class=\"docutils literal\"><span class=\"pre\">capture_fail</span></code> and <code class=\"docutils literal\"><span class=\"pre\">tap_fail</span></code> can be used to\nwork with <cite>Fail</cite> trait objects instead.</p>\n</div>\n\n\n<div class=\"section\" id=\"catching-panics\">\n<h2>Catching Panics</h2>\n<p>To automatically catch panics the panic integration can be used:</p>\n<div class=\"highlight-rust\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">use</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">integrations</span>::<span style=\"color: #111111\">panic</span>::<span style=\"color: #111111\">register_panic_handler;</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n\n<span style=\"color: #2eb0f7\">fn</span> <span style=\"color: #111111\">main()</span><span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">{</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">sentry</span>::<span style=\"color: #111111\">init(...);</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #f8f8f8; text-decoration: underline\"> </span><span style=\"color: #111111\">register_panic_handler();</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n<span style=\"color: #111111\">}</span><span style=\"color: #f8f8f8; text-decoration: underline\"></span>\n</pre></div>\n</div>\n</div>\n",
  3. "link": "https://docs.getsentry.com/clients/rust/",
  4. "id": "rust",
  5. "name": "Rust"
  6. }