Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enable person context using special fields #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

montanaflynn
Copy link

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:

Screen Shot 2020-07-22 at 22 30 22

And also all the errors grouped by the person:

Screen Shot 2020-07-22 at 22 29 57

Closes #46

@vtfr
Copy link

vtfr commented Mar 24, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to set person fields
2 participants