123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>Using Maven:</p>\n<div class=\"highlight-xml\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\"><dependency></span>\n <span style=\"color: #2eb0f7\"><groupId></span>io.sentry<span style=\"color: #2eb0f7\"></groupId></span>\n <span style=\"color: #2eb0f7\"><artifactId></span>sentry<span style=\"color: #2eb0f7\"></artifactId></span>\n <span style=\"color: #2eb0f7\"><version></span>1.6.3<span style=\"color: #2eb0f7\"></version></span>\n<span style=\"color: #2eb0f7\"></dependency></span>\n</pre></div>\n</div>\n<p>Using Gradle:</p>\n<div class=\"highlight-groovy\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">compile</span> <span style=\"color: #e8535a\">'io.sentry:sentry:1.6.3'</span>\n</pre></div>\n</div>\n<p>Using SBT:</p>\n<div class=\"highlight-scala\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">libraryDependencies</span> <span style=\"color: #4b4f5c\">+=</span> <span style=\"color: #e8535a\">"io.sentry"</span> <span style=\"color: #4b4f5c\">%</span> <span style=\"color: #e8535a\">"sentry"</span> <span style=\"color: #4b4f5c\">%</span> <span style=\"color: #e8535a\">"1.6.3"</span>\n</pre></div>\n</div>\n<p>For other dependency managers see the <a class=\"reference external\" href=\"https://search.maven.org/#artifactdetails%7Cio.sentry%7Csentry%7C1.6.3%7Cjar\">central Maven repository</a>.</p>\n</div>\n\n\n<div class=\"section\" id=\"capture-an-error\">\n<h2>Capture an Error</h2>\n<p id=\"usage-example\">To report an event manually you need to initialize a <code class=\"docutils literal\"><span class=\"pre\">SentryClient</span></code>. It is recommended\nthat you use the static API via the <code class=\"docutils literal\"><span class=\"pre\">Sentry</span></code> class, but you can also construct and manage\nyour own <code class=\"docutils literal\"><span class=\"pre\">SentryClient</span></code> instance. An example of each style is shown below:</p>\n<div class=\"highlight-java\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.context.Context</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.BreadcrumbBuilder</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.UserBuilder</span><span style=\"color: #4b4f5c\">;</span>\n\n<span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">MyClass</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">private</span> <span style=\"color: #2eb0f7\">static</span> <span style=\"color: #111111\">SentryClient</span> <span style=\"color: #111111\">sentry</span><span style=\"color: #4b4f5c\">;</span>\n\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">static</span> <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">main</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">String</span><span style=\"color: #4b4f5c\">...</span> <span style=\"color: #111111\">args</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">/*</span>\n<span style=\"color: #34c08b; font-style: italic\"> It is recommended that you use the DSN detection system, which</span>\n<span style=\"color: #34c08b; font-style: italic\"> will check the environment variable "SENTRY_DSN", the Java</span>\n<span style=\"color: #34c08b; font-style: italic\"> System Property "sentry.dsn", or the "sentry.properties" file</span>\n<span style=\"color: #34c08b; font-style: italic\"> in your classpath. This makes it easier to provide and adjust</span>\n<span style=\"color: #34c08b; font-style: italic\"> your DSN without needing to change your code. See the configuration</span>\n<span style=\"color: #34c08b; font-style: italic\"> page for more information.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">init</span><span style=\"color: #4b4f5c\">();</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// You can also manually provide the DSN to the ``init`` method.</span>\n <span style=\"color: #111111\">String</span> <span style=\"color: #111111\">dsn</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">args</span><span style=\"color: #4b4f5c\">[</span><span style=\"color: #45c2c9\">0</span><span style=\"color: #4b4f5c\">];</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">init</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">dsn</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/*</span>\n<span style=\"color: #34c08b; font-style: italic\"> It is possible to go around the static ``Sentry`` API, which means</span>\n<span style=\"color: #34c08b; font-style: italic\"> you are responsible for making the SentryClient instance available</span>\n<span style=\"color: #34c08b; font-style: italic\"> to your code.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #111111\">sentry</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">SentryClientFactory</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">sentryClient</span><span style=\"color: #4b4f5c\">();</span>\n\n <span style=\"color: #111111\">MyClass</span> <span style=\"color: #111111\">myClass</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">MyClass</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #111111\">myClass</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">logWithStaticAPI</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #111111\">myClass</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">logWithInstanceAPI</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/**</span>\n<span style=\"color: #34c08b; font-style: italic\"> * An example method that throws an exception.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">throw</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">UnsupportedOperationException</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"You shouldn't call this!"</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/**</span>\n<span style=\"color: #34c08b; font-style: italic\"> * Examples using the (recommended) static API.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">logWithStaticAPI</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// Note that all fields set on the context are optional. Context data is copied onto</span>\n <span style=\"color: #34c08b; font-style: italic\">// all future events in the current context (until the context is cleared).</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">recordBreadcrumb</span><span style=\"color: #4b4f5c\">(</span>\n <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">BreadcrumbBuilder</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"User made an action"</span><span style=\"color: #4b4f5c\">).</span><span style=\"color: #a47ac6\">build</span><span style=\"color: #4b4f5c\">()</span>\n <span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Set the user in the current context.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setUser</span><span style=\"color: #4b4f5c\">(</span>\n <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">UserBuilder</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setEmail</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"hello@sentry.io"</span><span style=\"color: #4b4f5c\">).</span><span style=\"color: #a47ac6\">build</span><span style=\"color: #4b4f5c\">()</span>\n <span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Add extra data to future events in this context.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">addExtra</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"extra"</span><span style=\"color: #4b4f5c\">,</span> <span style=\"color: #e8535a\">"thing"</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Add an additional tag to future events in this context.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">addTag</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"tagName"</span><span style=\"color: #4b4f5c\">,</span> <span style=\"color: #e8535a\">"tagValue"</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/*</span>\n<span style=\"color: #34c08b; font-style: italic\"> This sends a simple event to Sentry using the statically stored instance</span>\n<span style=\"color: #34c08b; font-style: italic\"> that was created in the ``main`` method.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"This is a test"</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #2eb0f7\">try</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #4b4f5c\">}</span> <span style=\"color: #2eb0f7\">catch</span> <span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">Exception</span> <span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// This sends an exception event to Sentry using the statically stored instance</span>\n <span style=\"color: #34c08b; font-style: italic\">// that was created in the ``main`` method.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/**</span>\n<span style=\"color: #34c08b; font-style: italic\"> * Examples that use the SentryClient instance directly.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">logWithInstanceAPI</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// Retrieve the current context.</span>\n <span style=\"color: #111111\">Context</span> <span style=\"color: #111111\">context</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">();</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Record a breadcrumb in the current context. By default the last 100 breadcrumbs are kept.</span>\n <span style=\"color: #111111\">context</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">recordBreadcrumb</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">BreadcrumbBuilder</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"User made an action"</span><span style=\"color: #4b4f5c\">).</span><span style=\"color: #a47ac6\">build</span><span style=\"color: #4b4f5c\">());</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Set the user in the current context.</span>\n <span style=\"color: #111111\">context</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">setUser</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">UserBuilder</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setEmail</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"hello@sentry.io"</span><span style=\"color: #4b4f5c\">).</span><span style=\"color: #a47ac6\">build</span><span style=\"color: #4b4f5c\">());</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// This sends a simple event to Sentry.</span>\n <span style=\"color: #111111\">sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">sendMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"This is a test"</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #2eb0f7\">try</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #4b4f5c\">}</span> <span style=\"color: #2eb0f7\">catch</span> <span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">Exception</span> <span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// This sends an exception event to Sentry.</span>\n <span style=\"color: #111111\">sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">sendException</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n <span style=\"color: #4b4f5c\">}</span>\n<span style=\"color: #4b4f5c\">}</span>\n</pre></div>\n</div>\n<div class=\"section\" id=\"building-more-complex-events\">\n<h3>Building More Complex Events</h3>\n<p>For more complex messages, you’ll need to build an <code class=\"docutils literal\"><span class=\"pre\">Event</span></code> with the\n<code class=\"docutils literal\"><span class=\"pre\">EventBuilder</span></code> class:</p>\n<div class=\"highlight-java\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span> <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.Sentry</span><span style=\"color: #4b4f5c\">;</span>\n <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.Event</span><span style=\"color: #4b4f5c\">;</span>\n <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.EventBuilder</span><span style=\"color: #4b4f5c\">;</span>\n <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.interfaces.ExceptionInterface</span><span style=\"color: #4b4f5c\">;</span>\n\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">MyClass</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">static</span> <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">main</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">String</span><span style=\"color: #4b4f5c\">...</span> <span style=\"color: #111111\">args</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">init</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">throw</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">UnsupportedOperationException</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"You shouldn't call this!"</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">logSimpleMessage</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// This sends an event to Sentry.</span>\n <span style=\"color: #111111\">EventBuilder</span> <span style=\"color: #111111\">eventBuilder</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">EventBuilder</span><span style=\"color: #4b4f5c\">()</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"This is a test"</span><span style=\"color: #4b4f5c\">)</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withLevel</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">Event</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">Level</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">INFO</span><span style=\"color: #4b4f5c\">)</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withLogger</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">MyClass</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">class</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getName</span><span style=\"color: #4b4f5c\">());</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Note that the *unbuilt* EventBuilder instance is passed in so that</span>\n <span style=\"color: #34c08b; font-style: italic\">// EventBuilderHelpers are run to add extra information to your event.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">eventBuilder</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">logException</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">try</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #4b4f5c\">}</span> <span style=\"color: #2eb0f7\">catch</span> <span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">Exception</span> <span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// This sends an exception event to Sentry.</span>\n <span style=\"color: #111111\">EventBuilder</span> <span style=\"color: #111111\">eventBuilder</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">EventBuilder</span><span style=\"color: #4b4f5c\">()</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"Exception caught"</span><span style=\"color: #4b4f5c\">)</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withLevel</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">Event</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">Level</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">ERROR</span><span style=\"color: #4b4f5c\">)</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withLogger</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">MyClass</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">class</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getName</span><span style=\"color: #4b4f5c\">())</span>\n <span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withSentryInterface</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">ExceptionInterface</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">));</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Note that the *unbuilt* EventBuilder instance is passed in so that</span>\n <span style=\"color: #34c08b; font-style: italic\">// EventBuilderHelpers are run to add extra information to your event.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">eventBuilder</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n <span style=\"color: #4b4f5c\">}</span>\n<span style=\"color: #4b4f5c\">}</span>\n</pre></div>\n</div>\n</div>\n<div class=\"section\" id=\"automatically-enhancing-events\">\n<h3>Automatically Enhancing Events</h3>\n<p>You can also implement an <code class=\"docutils literal\"><span class=\"pre\">EventBuilderHelper</span></code> that is able to automatically\nenhance outgoing events.</p>\n<div class=\"highlight-java\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.Sentry</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.SentryClient</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.EventBuilder</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.helper.EventBuilderHelper</span><span style=\"color: #4b4f5c\">;</span>\n\n<span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">MyClass</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">myMethod</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">SentryClient</span> <span style=\"color: #111111\">client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getStoredClient</span><span style=\"color: #4b4f5c\">();</span>\n\n <span style=\"color: #111111\">EventBuilderHelper</span> <span style=\"color: #111111\">myEventBuilderHelper</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">EventBuilderHelper</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #696D80\">@Override</span>\n <span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">helpBuildingEvent</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">EventBuilder</span> <span style=\"color: #111111\">eventBuilder</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">eventBuilder</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">withMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"Overwritten by myEventBuilderHelper!"</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n <span style=\"color: #4b4f5c\">};</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Add an ``EventBuilderHelper`` to the current client instance. Note that</span>\n <span style=\"color: #34c08b; font-style: italic\">// this helper will process *all* future events.</span>\n <span style=\"color: #111111\">client</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">addBuilderHelper</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">myEventBuilderHelper</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Send an event to Sentry. During construction of the event the message</span>\n <span style=\"color: #34c08b; font-style: italic\">// body will be overwritten by ``myEventBuilderHelper``.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">"Hello, world!"</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n<span style=\"color: #4b4f5c\">}</span>\n</pre></div>\n</div>\n</div>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/java/",
- "id": "java",
- "name": "Java"
- }
|