Giter Site home page Giter Site logo

sentry-dotnet-ef's Introduction

The code was moved into the Sentry SDK for .NET

AppVeyor

Name NuGet
Sentry.EntityFramework NuGet

This is packages extend Sentry's .NET SDK with Entity Framework 6 queries as Breadcrumbs. It also processes DbEntityValidationExceptions to extract the validation errors and add to the Extra field. This increases the debuggability of Entity Framework related errors gratefully.

Example in Sentry

Usage

There are 2 steps to adding Entity Framework 6 support to your project:

  • Call SentryDatabaseLogging.UseBreadcrumbs() to either your application's startup method, or into a static constructor inside your Entity Framework object. Make sure you only call this method once! This will add the interceptor to Entity Framework to log database queries.
  • When setting up your SentryClient, use SentryOptions.AddEntityFramework(). This extension method will register all error processors to extract extra data, such as validation errors, from the exceptions thrown by Entity Framework.

Samples

You may find a usage sample using ASP.NET MVC 5 under /samples/Sentry.Samples.AspNet.Mvc

sentry-dotnet-ef's People

Contributors

bruno-garcia avatar co7e avatar kanadaj avatar lucas-zimerman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sentry-dotnet-ef's Issues

Method 'ProcessException' in type 'Sentry.EntityFramework.ErrorProcessors.DbEntityValidationExceptionProcessor' from assembly 'Sentry.EntityFramework, Version=2.1.6.0...' does not have an implementation

Environment

How do you use Sentry?
Sentry SaaS

Which SDK and version?
e.g: Sentry 3.0.3, Sentry Protocol 2.1.8, Sentry Abstractions 1.1.1, EF 6.4.4

Steps to Reproduce

Updated Sentry EntityFramework from 1.0.0 to 2.1.6 via Nuget

			SentryDatabaseLogging.UseBreadcrumbs();
			this._sentrySdk = SentrySdk.Init(o =>
			{
				// We store the DSN inside Web.config
				o.Dsn = ConfigurationManager.AppSettings["Sentry.IO.DSN"];
				o.Environment = ConfigurationManager.AppSettings["Sentry.IO.Environment"].ToString();
				o.Release = Assembly.GetExecutingAssembly().GetName().Version.ToString(4);
				o.AddEntityFramework();
			});

Expected Result

No exception when running applicaiton

Actual Result

[TypeLoadException: Method 'ProcessException' in type 'Sentry.EntityFramework.ErrorProcessors.DbEntityValidationExceptionProcessor' from assembly 'Sentry.EntityFramework, Version=2.1.6.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0' does not have an implementation.]
   Sentry.SentryOptionsExtensions.AddEntityFramework(SentryOptions sentryOptions) +0
   BackOffice.<>c.<Application_Start>b__1_0(SentryOptions o) in ..\..\Global.asax.cs:51
   Sentry.SentrySdk.Init(Action`1 configureOptions) in /_/src/Sentry/SentrySdk.cs:58
   BackOffice.MvcApplication.Application_Start() in ...\...\Global.asax.cs:45

[HttpException (0x80004005): Method 'ProcessException' in type 'Sentry.EntityFramework.ErrorProcessors.DbEntityValidationExceptionProcessor' from assembly 'Sentry.EntityFramework, Version=2.1.6.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0' does not have an implementation.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +546
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +171
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +255
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +347

[HttpException (0x80004005): Method 'ProcessException' in type 'Sentry.EntityFramework.ErrorProcessors.DbEntityValidationExceptionProcessor' from assembly 'Sentry.EntityFramework, Version=2.1.6.0, Culture=neutral, PublicKeyToken=fba2ec45388e2af0' does not have an implementation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737

MethodAccessException thrown when AddEntityFramework is called

I'm following the example pretty closely. My code looks like this:

SentryDatabaseLogging.UseBreadcrumbs();

// Set up the sentry SDK
_sentrySdk = SentrySdk.Init(o =>
{
	// We store the DSN inside Web.config; make sure to use your own DSN!
	o.Dsn = new Dsn(ConfigurationManager.AppSettings["SentryDsn"]);

	// Add the EntityFramework integration
	o.AddEntityFramework();
});

However, when the AddEntityFramework method is actually executed as the site is initializing, it throws the following exception:

System.MethodAccessException: Attempt by method 'Sentry.SentryOptionsExtensions.AddEntityFramework(Sentry.SentryOptions)' to access method 'Sentry.SentryOptionsExtensions.AddExceptionProcessor(Sentry.SentryOptions, Sentry.Extensibility.ISentryEventExceptionProcessor)' failed.

Visual Studio doesn't detect any issues in the editor or when it's compiled. It only occurs on execution. My only thought is that the SentryOptionsExtensions.AddExceptionProcessor is defined as internal and that is preventing the call from being successful at runtime.

Thoughts?

Thanks!
Andy

MissingMethodException: Method not found: 'Void Sentry.HubExtensions.AddBreadcrumb(Sentry.IHub, System.S

###Environment
How do you use Sentry?
Sentry SaaS

Which SDK and version?
e.g: Sentry 3.0.3, Sentry Protocol 2.1.8, Sentry Abstractions 1.1.1, EF 6.4.4

Steps to Reproduce

        // Set up the sentry SDK
        _sentry = SentrySdk.Init(o =>
        {
            o.Dsn = ConfigurationManager.AppSettings["SentryDsn"];
            o.Environment = "Production";
            o.Release = Common.Utils.SallsaUtils.GetBuildVersion();
            o.AttachStacktrace = true;
            o.ReportAssemblies = false;
            o.TracesSampleRate = 1;

            // Get Entity Framework integration
            //o.AddEntityFramework();
        });

Actual Result

MissingMethodException: Method not found: 'Void Sentry.HubExtensions.AddBreadcrumb(Sentry.IHub, System.String, System.String, System.String, System.Collections.Generic.IDictionary`2<System.String,System.String>, Sentry.Protocol.BreadcrumbLevel)'.

Entity Framework Classic support

It might be a good idea to make a branch that targets Entity Framework Classic (https://github.com/zzzprojects/EntityFramework-Classic, https://www.nuget.org/packages/Z.EntityFramework.Classic) instead of Entity Framework 6 - the API surface is identical since EF Classic is a fork of EF6, but Classic targets .NET Core 2.0 and higher (I think it's netstandard2.0 but I might be wrong there)

It basically only needs a change to the target framework and libraries used. Extra work to maintain though. Maybe use compiler directives instead?

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.