Skip to content

Commit 298a00d

Browse files
authored
Merge pull request #27 from getsentry/pack/first-preview
Package first preview for NuGet
2 parents f7f5c8c + b4581f9 commit 298a00d

File tree

7 files changed

+145
-28
lines changed

7 files changed

+145
-28
lines changed

.assets/sentry-nuget.png

6.1 KB
Loading

README.md

Lines changed: 114 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,92 @@
55
<br />
66
</p>
77

8-
Work in progress, for a new .NET SDK
8+
New .NET SDK for Sentry
99
===========
1010
[![Travis](https://travis-ci.org/getsentry/sentry-dotnet.svg?branch=master)](https://travis-ci.org/getsentry/sentry-dotnet)
1111
[![AppVeyor](https://ci.appveyor.com/api/projects/status/wu055n0n4u8p20p2/branch/bootstrap?svg=true)](https://ci.appveyor.com/project/sentry/sentry-dotnet/branch/master)
1212
[![codecov](https://codecov.io/gh/getsentry/sentry-dotnet/branch/master/graph/badge.svg)](https://codecov.io/gh/getsentry/sentry-dotnet)
1313

1414

15-
16-
NOTE: This repository is a work in progress. Our goal is to build a composable SDK with many integrations.
15+
**NOTE**: This repository is a work in progress. Our goal is to build a composable SDK with many integrations.
16+
| Packages | |
17+
| ----------------------------- | :------------------: |
18+
| **Sentry** | [![NuGet](https://img.shields.io/nuget/vpre/Sentry.svg)](https://www.nuget.org/packages/Sentry) |
19+
| **Sentry.AspNetCore** | [![NuGet](https://img.shields.io/nuget/vpre/Sentry.AspNetCore.svg)](https://www.nuget.org/packages/Sentry.AspNetCore) |
20+
| **Sentry.Extensions.Logging** | [![NuGet](https://img.shields.io/nuget/vpre/Sentry.Extensions.Logging.svg)](https://www.nuget.org/packages/Sentry.Extensions.Logging) |
1721

1822
## Usage
1923

20-
** Consider taking a look at the `samples` directory for different types of apps and example usages of the SDK. **
24+
**Consider taking a look at the _[samples](https://github.com/getsentry/sentry-dotnet/tree/master/samples)_ directory for different types of apps and example usages of the SDK.**
25+
26+
This SDK provides integrations which can hook into your app and automatically capture errors and context.
27+
28+
## ASP.NET Core integration
29+
30+
To use Sentry with your ASP.NET Core project, simply install the NuGet package:
31+
32+
```shell
33+
dotnet add package Sentry.AspNetCore
34+
```
35+
36+
Change your `Program.cs` by adding `UseSentry`:
37+
38+
```csharp
39+
public static IWebHost BuildWebHost(string[] args) =>
40+
WebHost.CreateDefaultBuilder(args)
41+
.UseStartup<Startup>()
42+
// Integration
43+
.UseSentry()
44+
.Build();
45+
```
46+
47+
### Logging integration
48+
49+
This will also automatically include the integration to `Microsoft.Extensions.Logging`. That means that any `LogError` or `LogCritical` by default will send an event to Sentry.
50+
51+
Log messages of level `Information` will be kept as _breadcrumbs_ and if an event is sent, all breadcrumbs from that transaction are included.
52+
53+
These levels can be configured so that the level you define tracks breadcrumbs or sends events or completely disable it.
54+
55+
**That means that log mesages logged by you or the framework, related to the failed transaction, will be added to the event!**
56+
57+
## DSN
58+
59+
The SDK needs to know which project within Sentry your errors should go to. That's defined via the [DSN](https://docs.sentry.io/quickstart/#configure-the-dsn). You can provide it directly as an argument to `UseSentry`, defined via configuration like `appsettings.json` or set via environment variable `SENTRY_DSN`.
60+
[This sample demonstrates defining the DSN via `appsettings.json`](https://github.com/getsentry/sentry-dotnet/blob/f7f5c8cafcf2a54ccffeedb9ed0359c880b6aae5/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json#L6).
61+
62+
## Configuration
63+
64+
The SDK is configurable, many of the settings are demonstrated through the samples but here are some options:
2165

22-
The goal of this SDK is to provide integrations which can hook into your app and automatically capture errors and context. See ASP.NET Core below as an example.
66+
* Whether to capture global unhandled exceptions
67+
* HTTP Proxy
68+
* Enable request body extraction
69+
* Read [diagnostics activity data]("https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md)
70+
* BeforeSend: Callback to modify/reject event before sending
71+
* LogEventFilter: Filter events by inspecting log data
72+
* Maximum number of breadcrumbs to store
73+
* Event queue depth
74+
* Shutdown timeout: If there are events to send, how long to wait until shutdown
75+
* Accept compressed response
76+
* Compress request body
77+
* Breadcrumb level: Minimal log level to store as a breadcrumb
78+
* Event level: Minimal log level to send an event to Sentry
2379

24-
You can still use the SDK directly to send events to Sentry:
80+
and more...
81+
82+
## Microsoft.Extensions.Logging
83+
84+
If you want only the logging integration:
85+
```shell
86+
dotnet add package Sentry.Extensions.Logging
87+
```
88+
See the [logging integration only sample](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.ME.Logging/Program.cs)
89+
90+
91+
## Without any framework integration
92+
You can still use the SDK directly to send events to Sentry.
93+
There's a [basic sample](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.Console.Basic/Program.cs) and a one demonstrating [more customization](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.Console.Customized/Program.cs).
2594

2695
Install the main SDK:
2796
```shell
@@ -32,7 +101,7 @@ Initialize the SDK:
32101
```csharp
33102
void Main()
34103
{
35-
using (SentrySdk.Init("https://[email protected]/project"))
104+
using (SentrySdk.Init("dsn"))
36105
{
37106
// App code
38107
}
@@ -47,7 +116,7 @@ void Main()
47116
{
48117
using (SentrySdk.Init(o =>
49118
{
50-
o.Dsn = new Dsn("https://[email protected]/project");
119+
o.Dsn = new Dsn("dsn");
51120
o.Http(h =>
52121
{
53122
h.Proxy = new WebProxy("https://localhost:3128");
@@ -71,30 +140,49 @@ catch (Exception e)
71140
}
72141
```
73142

74-
## ASP.NET Core integration
143+
### Internals/Testability
75144

76-
To use Sentry with your ASP.NET Core project, simply install the NuGet package:
145+
It's often the case we don't want to couple our code with static class like `SentrySdk`, especially to allow our code to be testable.
146+
If that's your case, you can use 2 abstractions:
77147

78-
```shell
79-
dotnet add package Sentry.AspNetCore
80-
```
148+
* ISentryClient
149+
* IHub
81150

82-
Change your `Program.cs` by adding `UseSentry`:
151+
The `ISentryClient` is responsible to queueing the event to be sent to Sentry and abstracting away the internal transport.
152+
The `IHub` on the other hand, holds a client and the current scope. It in fact also implements `ISentryClient` and is able to dispatch calls to the right client depending on the current scope.
83153

84-
Like:
85-
```csharp
86-
public static IWebHost BuildWebHost(string[] args) =>
87-
WebHost.CreateDefaultBuilder(args)
88-
.UseStartup<Startup>()
89-
// Integration
90-
.UseSentry("https://[email protected]/project")
91-
.Build();
92-
```
154+
In order to allow different events hold different contextual data, you need to know in which scope you are in.
155+
That's the job of the `Hub`. It holds the scope management as well as a client.
93156

94-
This will also include automatically integration to `Microsoft.Extensions.Logging`. That means that any `LogError` or `LogCritical` by default will send an event to Sentry.
95-
Log messages of level `Information` will be kept as _breadcrumbs_ and if an event is sent, all breadcrumbs from that transaction are included.
157+
If all you are doing is sending events, without modification/access to the current scope, then you depend on `ISentryClient`. If on the other hand you would like to have access to the current scope by configuring it or binding a different client to it, etc. You'd depend on `IHub`.
96158

97-
These levels can be configured so that the level you define tracks breadcrumbs or sends events or completely disable it.
159+
160+
An example using `IHub` for testability is [SentryLogger](https://github.com/getsentry/sentry-dotnet/blob/master/src/Sentry.Extensions.Logging/SentryLogger.cs) and its unit tests [SentryLoggerTests](https://github.com/getsentry/sentry-dotnet/blob/master/test/Sentry.Extensions.Logging.Tests/SentryLoggerTests.cs).
161+
`SentryLogger` depends on `IHub` because it does modify the scope (through `AddBreadcrumb`). In case it only sent events, it should instead depend on `ISentryClient`
162+
163+
## Compatibility
164+
165+
The packages target **.NET Standard 2.0**. That means [it is compatible with](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) the following versions or newer:
166+
167+
* .NET Framework 4.6.1
168+
* .NET Core 2.0
169+
* Mono 5.4
170+
* Xamarin.Android 8.0
171+
* Xamarin.Mac 3.8
172+
* Xamarin.iOS 10.14
173+
* Universal Windows Platform 10.0.16299
174+
175+
Of those, we've tested (we run our unit/integration tests) against:
176+
177+
* .NET Framework 4.6.2 on Windows (AppVeyor)
178+
* Mono 5.12 macOS and Linux (Travis-CI)
179+
* .NET Core 2.0 Windows (AppVeyor), macOS and Linux (Travis-CI)
180+
* .NET Core 2.1 Windows (AppVeyor), macOS and Linux (Travis-CI)
181+
182+
183+
### Legacy frameworks
184+
185+
Sentry's [Raven SDK](https://github.com/getsentry/raven-csharp/), battle tested with over 300.000 downloads on NuGet has support to .NET Framework 3.5+.
98186

99187
## Get involved
100188
Join the discussion in our

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ $ErrorActionPreference = "Stop"
33
dotnet test -c Release
44
if ($LASTEXITCODE -ne 0) { exit 1 }
55

6-
dotnet pack -c Release --no-build --include-symbols
6+
dotnet pack -c Release --no-build
77
if ($LASTEXITCODE -ne 0) { exit 1 }

src/Directory.Build.props

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@
55

66
<PropertyGroup>
77
<VersionPrefix>0.0.1</VersionPrefix>
8-
<VersionSuffix>preview</VersionSuffix>
8+
<VersionSuffix>preview1</VersionSuffix>
99
<!--Generate xml docs for all projects under 'src'-->
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
12+
<Authors>Sentry Team and Contributors</Authors>
13+
<Company>Sentry.io</Company>
14+
<Product>Sentry</Product>
15+
16+
<PackageTags>Sentry;GetSentry;Error-Reporting;Crash-Reporting;Exception-Handling</PackageTags>
17+
<RepositoryType>git</RepositoryType>
18+
<RepositoryRoot>$(MSBuildThisFileDirectory)</RepositoryRoot>
19+
<RepositoryUrl>https://github.com/getsentry/sentry-dotnet</RepositoryUrl>
20+
21+
<PackageIconUrl>https://raw.githubusercontent.com/getsentry/sentry-dotnet/master/.assets/sentry-nuget.png</PackageIconUrl>
22+
<PackageProjectUrl>https://github.com/getsentry/sentry-dotnet</PackageProjectUrl>
23+
<PackageLicenseUrl>https://raw.githubusercontent.com/getsentry/sentry-dotnet/master/LICENSE</PackageLicenseUrl>
24+
25+
<PackageReleaseNotes>Can be found at: https://github.com/getsentry/sentry-dotnet/releases</PackageReleaseNotes>
1126
<!-- On Release mode make sure missing docs raise warning -->
1227
<!--TODO: Add this when API is more stable:-->
1328
<!--<NoWarn Condition="'$(Configuration)' != 'Release'">$(NoWarn);CS1591</NoWarn>-->

src/Sentry.AspNetCore/Sentry.AspNetCore.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageTags>$(PackageTags);AspNetCore;MVC</PackageTags>
6+
<PackageId>Sentry.AspNetCore</PackageId>
7+
<AssemblyName>Sentry.AspNetCore</AssemblyName>
8+
<RootNamespace>Sentry.AspNetCore</RootNamespace>
9+
<Description>Official ASP.NET Core integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
510
</PropertyGroup>
611

712
<ItemGroup>

src/Sentry.Extensions.Logging/Sentry.Extensions.Logging.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageTags>$(PackageTags);Logging;Microsoft.Extensions.Logging</PackageTags>
6+
<PackageId>Sentry.Extensions.Logging</PackageId>
7+
<AssemblyName>Sentry.Extensions.Logging</AssemblyName>
8+
<RootNamespace>Sentry.Extensions.Logging</RootNamespace>
9+
<Description>Official Microsoft.Extensions.Logging integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
510
</PropertyGroup>
611

712
<ItemGroup>

src/Sentry/Sentry.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>7.2</LangVersion>
6+
<PackageId>Sentry</PackageId>
7+
<AssemblyName>Sentry</AssemblyName>
8+
<RootNamespace>Sentry</RootNamespace>
9+
<Description>Official SDK for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
610
</PropertyGroup>
711

812
<ItemGroup>

0 commit comments

Comments
 (0)