rollbar / Rollbar.NET

Rollbar for .NET
https://docs.rollbar.com/docs/dotnet
MIT License
65 stars 44 forks source link

rollbarData.Response is null on this line #554

Closed DrLeh closed 4 years ago

DrLeh commented 4 years ago

https://github.com/rollbar/Rollbar.NET/blob/89d3cc3727d9b80af1b1b3bc2859595f74711d4f/Rollbar.Net.AspNet.WebApi/HttpActionContextPackageDecorator.cs#L78

Should this line read rollbarData.Request.Headers instead?

akornich commented 4 years ago

@DrLeh , absolutely correct. Thanks! An upcoming release (most likely by the end of this week) will have the fix.

DrLeh commented 4 years ago

thanks @akornich. I'm having lots of trouble getting this pattern to work, when it gets to the Critical line here, there are no elements of the rollbarPackage.Exceptions. so it seems that nothing is getting sent to Rollbar, even though the actionExecutedContext.Exception does have the correct exception that is occurring. I couldn't find any documention around how to use this, any suggestions?

https://github.com/rollbar/Rollbar.NET/blob/89d3cc3727d9b80af1b1b3bc2859595f74711d4f/Rollbar.Net.AspNet.WebApi/RollbarExceptionFilterAttribute.cs#L21-L26

akornich commented 4 years ago

@DrLeh , your code snippet looks correct and is expected to work if not the typo bug that you found (i.e. the use Response property instead of Request). I would expect if you for now (until the fix is out) remove the use of the HttpActionContextPackageDecorator - you should be able to see reported exception on your Rollbar Project's Dashboard. Please, let me know how it goes.

In general, IRollbarPackage does not have any properties corresponding to things that are packaged into it (since there could be many different things added to it, including pre-canned and custom package implementations). Each concrete package or package decorator implements custom payload builders to package the data included into a package and to eventually produce corresponding Rollbar payload object that gets sent to the Project Dashboard. These builders are invoked internally by the SDK when you report the package, for example, either during (for synchronous packages) or after (for async packages) call to RollbarLocator.RollbarInstance.Critical(rollbarPackage); .

When you are experimenting with the SDK or event in production, it could be very helpful to monitor the SDK internal events so you know what happens inside the SDK if things start acting odd for some reason. It usually provides a lot of insights on what exactly could be going wrong.

DrLeh commented 4 years ago

I was able to get basic reporting to Rollbar working by creating my own Log4Net appender, but I'm trying to get the Person data from the current request into the Transform of the Rollbar config. However, it seems like RollbarInstance is always used in a static context, so they don't have access to the current HttpContext. All the examples suggest doing something like below:

private static void SetRollbarReportingUser(string id, string email, string userName)
{
  Person person = new Person(id);
  person.Email = email;
  person.UserName = userName;
  RollbarLocator.RollbarInstance.Config.Person = person; // <- set a static reference to the person? 
}

However, the static instance of the web service would change all Rollbar requests for all users to whoever last triggered the above lines of code. If two users triggered events to Rollbar close enough together, both exceptions could get logged under the same user. Unless that RollbarLocator.RollbarInstance somehow gets a scoped instance behind the scenes.

I was trying to use that decorator pattern so that I could have access to the current HttpContext so that I could get data from a specific request into the payload, I haven't yet found another example of how I could try to do that. If you have another example you could point me to that allows that I'd appreciate it.

akornich commented 4 years ago

@DrLeh , Rollbar package (Rollbar namespace) contains PersonPackageDecorator class. You can use it similarly to the use of HttpActionContextPackageDecorator in one of your code snippets above.