Getting Started

For an overview of what Sentry does, take a look at the Sentry workflow.

Sentry is designed to be very simple to get off the ground, yet powerful to grow into. If you have never used Sentry before, this tutorial will help you getting started.

Getting started with Sentry is a three step process:

  1. Sign up for an account
  2. Install your SDK
  3. Configure it

Install an SDK

Sentry captures data by using an SDK within your application’s runtime. These are platform specific and allow Sentry to have a deep understanding of how your application works.

Install the NuGet package:

Package Manager:

Install-Package Sentry.AspNetCore -Version 1.2.0

.NET Core CLI:

dotnet add package Sentry.AspNetCore -v 1.2.0

The quickest way to get started is to use the CDN hosted version of the JavaScript browser SDK:

<script src="https://browser.sentry-cdn.com/5.7.1/bundle.min.js" integrity="sha384-KMv6bBTABABhv0NI+rVWly6PIRvdippFEgjpKyxUcpEmDWZTkDOiueL5xW+cztZZ" crossorigin="anonymous">
</script>

You can also NPM install our browser library.

If you are using yarn or npm you can add our package as a dependency:

# Using yarn
$ yarn add @sentry/browser@5.7.1

# Using npm
$ npm install @sentry/browser@5.7.1

You can also use our more convenient CDN version.

Install our SDK using the cordova command:

$ cordova plugin add sentry-cordova@0.12.3

Install the NuGet package:

# Using Package Manager
Install-Package Sentry -Version 1.2.0

# Or using .NET Core CLI
dotnet add package Sentry -v 1.2.0

If you are using yarn or npm you can add our package as a dependency:

# Using yarn
$ yarn add @sentry/electron@0.17.4

# Using npm
$ npm install @sentry/electron@0.17.4

Install our Go SDK using go get:

$ go get github.com/getsentry/sentry-go

Install the SDK by downloading the latest release. Next, follow the instructions in the Native SDK Documentation to build and link the SDK library.

If you are using yarn or npm you can add our package as a dependency:

# Using yarn
$ yarn add @sentry/node@5.7.1

# Using npm
$ npm install @sentry/node@5.7.1

To install the SDK you will need to be using composer in your project. If you are not already using Composer please see the Composer documentation.

composer require sentry/sdk:2.0.3

Install our Python SDK using pip:

$ pip install --upgrade sentry-sdk==0.13.0

To add Sentry to your Rust project you just need to add a new dependency to your Cargo.toml:

[dependencies]
sentry = "0.12.0"

Configure the SDK

After you completed setting up a project in Sentry, you’ll be given a value which we call a DSN, or Data Source Name. It looks a lot like a standard URL, but it’s actually just a representation of the configuration required by the Sentry SDKs. It consists of a few pieces, including the protocol, public key, the server address, and the project identifier.

Add Sentry to Program.cs through the WebHostBuilder:

ASP.NET Core 2.x:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        // Add the following line:
        .UseSentry("___PUBLIC_DSN___")

ASP.NET Core 3.0:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            // Add the following line:
            webBuilder.UseSentry("___PUBLIC_DSN___")
        });

You should init the Sentry Browser SDK as soon as possible during your page load:

Sentry.init({ dsn: '___PUBLIC_DSN___' });

You should init the Sentry browser SDK as soon as possible during your application load up:

import * as Sentry from '@sentry/browser';

Sentry.init({ dsn: '___PUBLIC_DSN___' });

You should init the SDK in the deviceReady function, to make sure the native integrations runs. For more details about Cordova click here

onDeviceReady: function() {
  var Sentry = cordova.require("sentry-cordova.Sentry");
  Sentry.init({ dsn: '___PUBLIC_DSN___' });
}

You should initialize the SDK as early as possible, like in the Main method in Program.cs:

using (SentrySdk.Init("___PUBLIC_DSN___"))
{
    // App code
}

You need to call init in your main and every renderer process you spawn. For more details about Electron click here

import * as Sentry from '@sentry/electron';

Sentry.init({dsn: '___PUBLIC_DSN___'});

Import and initialize the Sentry SDK early in your application’s setup:

import "github.com/getsentry/sentry-go"

func main() {
	sentry.Init(sentry.ClientOptions{
		Dsn: "___PUBLIC_DSN___",
	})
}

Import and initialize the Sentry SDK early in your application setup:

#include <sentry.h>

int main(void) {
  sentry_options_t *options = sentry_options_new();
  sentry_options_set_dsn(options, "___PUBLIC_DSN___");
  sentry_init(options);

  /* ... */

  // make sure everything flushes
  sentry_shutdown();
}

Alternatively, the DSN can be passed as SENTRY_DSN environment variable during runtime. This can be especially useful for server applications.

You need to inform the Sentry Node SDK about your DSN:

const Sentry = require('@sentry/node');
Sentry.init({ dsn: '___PUBLIC_DSN___' });

To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.

Sentry\init(['dsn' => '___PUBLIC_DSN___' ]);

Import and initialize the Sentry SDK early in your application’s setup:

import sentry_sdk
sentry_sdk.init("___PUBLIC_DSN___")

sentry.init() will return you a guard that when freed, will prevent process exit until all events have been sent (within a timeout):

let _guard = sentry::init("___PUBLIC_DSN___");

Capturing your first event

Once you have Sentry integrated into your project, you probably want to verify that everything is working as expected before deploying it, and what better way to do that than to break your application!

See the provided examples in the dotnet SDK repository for examples to send your first event to Sentry.

One way to break your JavaScript application is to call an undefined function:

myUndefinedFunction();

You can verify the function caused an error by checking your browser console.

One way to break your JavaScript application is to call an undefined function:

myUndefinedFunction();

You can verify the function caused an error by checking your browser console.

One way to break your Cordova application is to call an undefined function:

myUndefinedFunction();

You can verify Sentry is capturing unhandled exceptions by raising an exception. For example, you can use the following snippet to raise a DivideByZeroException:

using (SentrySdk.Init("___PUBLIC_DSN___"))
{
    Console.WriteLine(1 / 0);
}

One way to break your Electron application is to call an undefined function:

myUndefinedFunction();

You may want to try inserting this into both your main and any renderer processes to verify Sentry is operational in both.

The quickest way to verify Sentry in your Go application is to capture an error:

import (
	"errors"
	"time"
	"github.com/getsentry/sentry-go"
)

func main() {
	sentry.Init(sentry.ClientOptions{
		Dsn: "___PUBLIC_DSN___",
	})

	sentry.CaptureException(errors.New("my error"))
	// Since sentry emits events in the background we need to make sure
	// they are sent before we shut down
	sentry.Flush(time.Second * 5)
}

The quickest way to verify Sentry in your Native application is by capturing a message:

sentry_capture_event(sentry_value_new_message_event(
  /*   level */ SENTRY_LEVEL_INFO,
  /*  logger */ "custom",
  /* message */ "It works!"
));

One way to break your JavaScript application is to call an undefined function:

myUndefinedFunction();

You can trigger a PHP exception by throwing one in your application:

throw new Exception("My first Sentry error!");

You can cause a Python error by inserting a divide by zero expression into your application:

division_by_zero = 1 / 0

The quickest way to verify Sentry in your Rust application is to cause a panic:

fn main() {
    // Initialize sentry here

    sentry::integrations::panic::register_panic_handler();

    // Sentry will capture this
    panic!("Everything is on fire!");
}

Next Steps

Now that you’ve got basic reporting set up, you’ll want to explore adding additional context to your data.