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

Error fingerprinting user tracking #1883

Merged
merged 34 commits into from
Mar 27, 2023
Merged

Conversation

fallwith
Copy link
Contributor

This PR delivers support for two new errors inbox features: error fingerprinting and user tracking.

  • Error fingerprinting

    A new set_error_group_callback public API method now exists that will accept a user defined proc. The proc will be invoked for each noticed error and whenever it returns a string, that string will be used as the error group name for the error and will take precedence over any server-side grouping that takes place with the New Relic errors inbox. This gives users much greater control over the grouping of their errors.

    The customer defined proc will be expected to receive exactly one input argument, a hash. The hash contains the following:

    Key Value
    :error The Ruby error class instance. Offers #class, #message, and #backtrace
    :customAttributes Any customer defined customed attributed for the current transaction
    :'request.uri' The current requeset URI if available
    :'http.statusCode' The HTTP status code (200, 404, etc.) if available
    :'http.method' The HTTP method (GET, PUT, etc.) if available
    :'error.expected' Whether (true) or not (false) the error was expected
    :'options' The options hash passed to `NewRelic::Agent.notice_error

    The callback only needs to be set once per initialization of the New Relic agent. The NewRelic::Agent.set_error_group_callback method can be called from a Rails initializer or whatnot.

    Example usage:

    proc = proc { |hash| "Access" if hash[:'http.statusCode'].to_s == '401' }
    NewRelic::Agent.set_error_group_callback(proc)
  • User tracking
    A new set_user_id public API method now exists that will accept a string representation of a user id and associate that user id with the current transaction. Transactions and errors will then have a new enduser.id agent attribute associated with them. This will allow agent users to tag transactions and errors as belonging to given user ids in support of greater filtering and alerting capabilities.

tannalynn and others added 28 commits March 6, 2023 15:19
Allow the customer to register a proc to be invoked on each noticed
error in order to associate each noticed error with an error group
remove comment placeholder (since satisfied)
- in the (potentially customer facing) log message, give the class and
  method name for the public API method producing the message
- typo fix ("GRUP" -> "GROUP") in a constant name
- added tests
- added getter for the error group callback
Co-authored-by: Kayla Reopelle (she/her) <[email protected]>
- fix pre-existing bug with request.uri applying
- make sure internal errors are routed through the error group callback
- revert fix for request.uri setting (to be addressed with a separate
  PR)
- update comment for request.uri setting to have it apply also to error
  group setting
- restore logic to use the caller location as a backtrace (calling
  `#backtrace` on a noticed error will always return either a trace or a
  string, but never `nil`).
also include the error group in the agent attributes hash when it is
available
add supportability reporting for `set_error_group_callback`
CHANGELOG entries for error fingerprinting and user tracking
Error inbox add set_user_id API method
set_error_group_callback typo

Co-authored-by: Kayla Reopelle (she/her) <[email protected]>
errors inbox fingerprinting
`NewRelic::Agent::ErrorCollector#create_noticed_error`, which is the
sole consumer of `NoticedError#error_group=`, ends up calling
`NoticedError#processed_attributes` fully 3 times in order to build the
hash that is passed to the customer error group callback.

As a result, the agent attributes for the noticed error end up being
memoized. Because of the memoization, the agent attributes hash is not
rebuilt later on when it comes time to submit those attributes to the
collector.

Updated `NoticedError#error_group=` to effectively bust the memoization
cache and ensure that the error group name makes it into the agent
attributes hash.
add a test to prove the need for PR 1882
- have the harvest! calls separated out so in the event of a failure
  it's easier to tell which one failed
- update the assertions so that the expected value is listed first, then
  the actual value second
NoticedError: update attr cache for error group
and a corresponding test!
hannahramadan and others added 4 commits March 14, 2023 20:20
…frozen

What if agent attributes isn't frozen
updates for error fingerprinting and user tracking
Reconcile the errors inbox functionality update changelog entries with
the dev branch ones
@fallwith fallwith marked this pull request as ready for review March 25, 2023 00:26
add missing closing backtick

Co-authored-by: Kayla Reopelle (she/her) <[email protected]>
@fallwith fallwith requested a review from kaylareopelle March 27, 2023 18:39
@github-actions
Copy link
Contributor

SimpleCov Report

Coverage Threshold
Line 93.96% 93%
Branch 85.38% 85%

@fallwith fallwith merged commit 6eae525 into dev Mar 27, 2023
@fallwith fallwith deleted the error_fingerprinting_user_tracking branch March 27, 2023 23:58
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.

4 participants