Git Product home page Git Product logo

raven-uwp's Introduction

raven-uwp

UWP (Universal Windows Platform) client for Sentry.

Compatible with Windows 10 apps (Desktop, Mobile, Xbox One and IoT). Also compatible with Windows 8.1 using a linked assembly (albeit only using common APIs).

Installation

Clone this repo and build it so you can reference the .dll or add the RavenUWP/RavenUWP.Win81 project in your app. Requires Visual Studio 2015.

Will be a NuGet package soon.

Getting started

  1. If you haven't already, sign up for Sentry. There's numerous plans, including a free tier to get started with.
  2. Get your DSN from your project's settings
  3. In your application's App.xaml.cs file, initialize RavenClient before InitializeComponent()
public App()
{
    // Create your Sentry DSN
    Dsn dsn = new Dsn("https://public:[email protected]/projectId");

    // Initialize the client with the DSN. Optionally you can choose not to handle unhandled exceptions
    // automatically (default behavior is true)
    RavenClient.InitializeAsync(dsn);

    // The rest of your App() constructor here
    this.InitializeComponent();

    // ...
}
  1. In your OnLaunched() and OnActivated() handlers, you can also configure RavenClient to capture unobserved async exceptions
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    RavenClient.Instance.RegisterAsyncContextHandler();

    // The rest of your `OnLaunched() functionality here
    // ...
}

protected override void OnActivated(IActivatedEventArgs args)
{
    // Register an AsyncContextHandler and capture unobserved async exceptions
    RavenClient.Instance.RegisterAsyncContextHandler();

    base.OnActivated(args);
}

If you had chosen not to capture unhandled exceptions, you'll need to capture them manually (see next section)

Otherwise that's it! Raven will now send all unhandled exceptions to Sentry.

Setting the user

You can include user information by default with each exception if you have any.

RavenClient.Instance.SetUser("USERID", "USERNAME", "[email protected]");

Capturing exceptions

After you have called RavenClient.InitializeAsync(...), the client instance is now available at RavenClient.Instance.

To capture an exception:

try
{
    DoSomethingBad();
}
catch (Exception ex)
{
    RavenUWP.RavenClient.Instance.CaptureExceptionAsync(ex);
}

By default any exceptions captured this way are stored in a temporary folder and sent the next time the app is launched. To send the request immediately:

RavenUWP.RavenClient.Instance.CaptureExceptionAsync(ex, true);

You can also change the LogLevel from the default "Error" by specifying it in the overload:

RavenUWP.RavenClient.Instance.CaptureExceptionAsync(ex, true, RavenUWP.RavenLogLevel.Warning);

Each request will optionally allow arbitrary indexed tags and arbitrary extra data to be sent with the request. Raven will automatically add device, OS, page information and more, so you should focus on setting variables to help debug this particular exception.

var tags = new Dictionary<string, string>()
{
    { "Class Name", typeof(MyClass).FullName }
};

var extra = new Dictionary<string, object>()
{
    { "sender", sender.GetType().FullName }
};

RavenUWP.RavenClient.Instance.CaptureExceptionAsync(ex, false, RavenUWP.RavenLogLevel.Error, tags, extra);

Capturing messages

You can send non-exception messages to Sentry as well.

RavenUWP.RavenClient.Instance.CaptureMessageAsync("This is not an error!");

The method supports the same overloads as CaptureExceptionAsync() for sending behavior, level, tags and extra data. The default RavenLogLevel is set to Info.

Additional data

You can change the default logger name from "root"

RavenUWP.RavenClient.Instance.Logger = "mylogger";

If you have any tags or extra data you want to include with every request, you can add those to the client.

var ravenClient = RavenUWP.RavenClient.Instance;

ravenClient.DefaultTags = new Dictionary<string, string>();
ravenClient.DefaultTags["Entry Point"] = "Protocol";

ravenClient.DefaultExtra = new Dictionary<string, object>();
ravenClient.DefaultExtra["First App Launch"] = true;

raven-uwp's People

Contributors

ryanvalentin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.