rollrus
rollrus copied to clipboard
Add option to enable person context using special fields
Adds WithPersonFunc
OptionFunc
that enables using NewPersonContext
from the following special fields:
-
user_id
-
user_name
-
user_email
With it enabled and using these fields you will see the Person populated in rollbar under the issue's People
section:

And also all the errors grouped by the person:

Closes #46
This feature would be really interesting. Right now I'm using the following workaround to dynamically fill the Person struct by using information stored in the Context:
type RollbarPersonInjectionWrapperHook struct {
logrus.Hook
}
func (w *RollbarPersonInjectionWrapperHook) Fire(entry *logrus.Entry) error {
if entry.Context != nil {
// Retrieve the User from the Context.
// Replace with your own implementation.
if user, ok := authentication.UserFromContext(entry.Context); ok {
entry = dupEntry(entry)
entry.Context = rollbar.NewPersonContext(entry.Context, &rollbar.Person{
Id: fmt.Sprint(user.ID()),
// other fields
})
}
}
return w.Hook.Fire(entry)
}
func dupEntry(entry *logrus.Entry) *logrus.Entry {
newEntry := entry.Dup()
newEntry.Message = entry.Message
newEntry.Level = entry.Level
return newEntry
}
// Usage:
func setupRollbar(logger *logrus.Logger, accessToken string, environment string) {
logger.AddHook(&RollbarPersonInjectionWrapperHook{
Hook: rollrus.NewHook(accessToken, environment)
})
}
It would be nice to have a official way of doing so, along side with more extension points for similar use-cases.
Is this repo accepting new pull request?