rollbar / Rollbar.NET

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

People tracking is not compatible with `RollbarMiddleware` #651

Open srmagura opened 3 months ago

srmagura commented 3 months ago

Describe the bug I would like to use the People Tracking feature of Rollbar with the RollbarMiddleware in ASP.NET Core.

The problem is, there does not seem to be any way to tell the RollbarMiddleware who the current user is.

To Reproduce N/A

Expected behavior

When using an IRollbar instance directly, I can provide information about the current user like this:

var payloadAdditionOptions = new RollbarPayloadAdditionOptions();

if (_auth.CurrentUser != null)
{
    payloadAdditionOptions.Person = new Person()
    {
        Id = _auth.CurrentUser.Id.Value.ToString(),
        Email = _auth.CurrentUser.Email.Value,
        UserName = _auth.CurrentUser.Name?.ToString(),
    };
}

_rollbar.Config.RollbarPayloadAdditionOptions.Reconfigure(payloadAdditionOptions);

Here, _auth is an "auth context" that provides information about the current user by reading their claims (auth cookie).

I would like to be able to do something similar using RollbarMiddleware.

Rollbar Client - Rollbar.NET Hosting Environment (please complete the following information):

Additional context I know I can copy the RollbarMiddleware source code into my code to fix this, but ideally that would not be necessary.

AntMaster7 commented 2 months ago

Looking for the same feature. I wrote the Rollbar support. But it appears that Rollbar.NET is dead. There has basically not been any update for more than 2 years. And we pay a lot of money for Rollbar.

TheDevFactory commented 2 months ago

You can use the transform function to update the payload just before it is sent to Rollbar and add the Person data to the payload that is about to be sent to Rollbar without affecting other requests. Since you are modifying the payload each time.

You will need to add some extra code to do this but I am thinking you have a function that is called each time by the Rollbar transform option and it just updates the Person data in the payload from your auth holder (whatever that maybe).

srmagura commented 2 months ago

I worked around this limitation by implementing my Rollbar middleware, based on the official one: https://github.com/rollbar/Rollbar.NET/blob/master/Rollbar.NetCore.AspNet/RollbarMiddleware.cs