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

Breadcrumbs: Rails Breadcrumbs #514

Merged
merged 19 commits into from
Dec 19, 2018
Merged

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Dec 12, 2018

Goal

Adds ActiveSupport::Notifications subscriber for creating automatic breadcrumbs from Rails events.

@Cawllec Cawllec requested review from tobyhs, kellymason and a team December 12, 2018 17:20
@@ -0,0 +1,134 @@
require "bugsnag/breadcrumbs/breadcrumbs"

module Bugsnag::RailsBreadcrumbs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be under the Bugsnag::Rails module/namespace to match the other 2 integrations in lib/bugsnag/integrations/rails/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but I've had to move the require statement for the file due to namespace clashes. (As having a Bugsnag::Rails namespace makes it search for Rails::Railtie at Bugsnag::Rails::Railtie)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, it would be preferable to use ::Rails::Railtie instead of Rails::Railtie in lib/bugsnag/integrations/railtie.rb to avoid possible issues.

# @param event [Hash] details of the event to subscribe to
def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, data|
filtered_data = data.select{ |k, v| event[:allowed_data].include?(k) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a space before {; also, I think you can use data.slice(*event[:allowed_data]) instead (because ActiveSupport provides Hash#slice)

def event_subscription(event)
ActiveSupport::Notifications.subscribe(event[:id]) do |*, data|
filtered_data = data.select{ |k, v| event[:allowed_data].include?(k) }
filtered_data[:event_id] = event[:id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if event_id is a good name for the key in the metadata (as seeing the key itself could imply the ID of an actual instrumented/emitted occurrence of an event as opposed to the event type). Unfortunately, I don't see a good name for this in Rails documentation; the best I can come up with is event_name or event_type.

:message => "Perform ActionCable",
:type => Bugsnag::Breadcrumbs::PROCESS_BREADCRUMB_TYPE,
:allowed_data => [
:event_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to include event_id (or whatever you might rename it to) in all the breadcrumb types because you add it on after you select the appropriate fields from the notification payload.

@Cawllec Cawllec changed the base branch from breadcrumbs/update-reports-class to breadcrumbs/base December 17, 2018 14:33
@Cawllec Cawllec changed the title WIP: Breadcrumbs: Rails Breadcrumbs Breadcrumbs: Rails Breadcrumbs Dec 17, 2018
| 2.3 | 3 |
| 2.3 | 4 |
| 2.3 | 5 |
| 2.4 | 3 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing context, but why is Rails 4 missing from Ruby versions 2.4 and 2.5 from this example table and the one on line 45?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Rails 4 fixture doesn't work with Ruby 2.4+, so it was dropped when the maze fixtures were originally written.

| 2.4 | 3 |
| 2.4 | 5 |
| 2.5 | 3 |
| 2.5 | 5 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you also planning on writing additional scenario outlines for the other automatic breadcrumb types? This might help in determining if some of the breadcrumb types are not really useful or are near impossible to trigger.

In addition, it might be helpful to also check some of the metadata values (although I realize some of them such as connection_id for SQL breadcrumbs are not deterministic).

@@ -0,0 +1,23 @@
class BreadcrumbsController < ActionController::Base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inherit from ApplicationController instead

@@ -0,0 +1,23 @@
class BreadcrumbsController < ActionController::Base
def initialize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't normally see overriding of #initialize for a controller class. You should be able to use Rails.cache in your #cache_read method instead.

@@ -0,0 +1,5 @@
class ApplicationJob < ActiveJob::Base
def perform
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApplicationJob is meant to be an abstract class for other job classes to inherit from, so you should create a separate job class that inherits from ApplicationJob.

render json: {}
end

def action_mailer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is no route or maze-runner test that visits this. Did you forget to add something?


Examples:
| ruby_version | rails_version |
| 2.2 | 4 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 81 and 83 are failing for me with:

 2.2          | 4             |
      <"perform_start.active_job"> expected but was
      <"start_processing.action_controller">. (Test::Unit::AssertionFailedError)
      features/rails_features/breadcrumbs.feature:81:in `And the event "breadcrumbs.0.metaData.event_name" equals "perform_start.active_job"'
      features/rails_features/breadcrumbs.feature:77:in `And the event "breadcrumbs.0.metaData.event_name" equals "perform_start.active_job"'

Failing Scenarios:
cucumber features/rails_features/breadcrumbs.feature:81 # Scenario Outline: Active job breadcrumb, Examples (#1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked after the latest update, and these tests are now passing ✅

Copy link
Contributor

@tobyhs tobyhs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; I guess we can tweak some of the captured breadcrumbs and metadata as we test do more testing

@Cawllec Cawllec merged commit d45e766 into breadcrumbs/base Dec 19, 2018
Cawllec added a commit that referenced this pull request Jan 17, 2019
* Breadcrumbs/Circular buffer: Added circular buffer class

* Breadcrumbs/Circular buffer: Added initial buffer unit tests

* Breadcrumbs/Circular buffer: Ensure test file is named correctly

* Breadcrumbs/Circular buffer: Code tidy up

* Breadcrumbs / Breadcrumb class: Add first pass breadcrumb class with unit tests

* Breadcrumbs/Circular buffer rubocop fixes

* Breadcrumbs / Breadcrumb class: Rubocop fixes

* Breadcrumbs/Cricular buffer: Improve test readability

* Breadcrumbs/Breadcrumb: Simplified timestamp, improved tests

* Breadcrumbs/Breadcrumb: Rubocop requirements

* Breadcrumbs/Breadcrumb: Added doc comments

* Breadcrumbs/Circular buffer: Fixed RSpec/Rspec typo

* Breadcrumbs/Breadcrumb: Using explicit RSpec.describe call

* Breadcrumbs/Validator: Added validator and tests

* Breadcrumbs/Validator: Rubocop fixes

* Breadcrumbs/Validator: Tidying up from initial review

* Breadcrumbs/Validator: Re-add renamed types file

* Breadcrumbs/Breadcrumb: Change message => name, add yard comments

* Breadcrumbs/Circular buffer: Added yard docs

* Breadcrumbs/Breadcrumb: Improve tests, convert to utc sooner

* Breadcrumbs/Configuration: Initial configuration changes

* Breadcrumbs/Report: Initial report changes to support breadcrumbs

* Breadcrumbs/Breadcrumb: Test timestamps match up

* Breadcrumbs/Validator: Change 'message' to 'name', use name and meta_data clones

* Breadcrumbs/Validator: Refactor toward instance_double & let

* Breadcrumbs/Configuration: Add in missing import statement

* Breadcrumbs/Circular buffer docs: Improve readability

* Breadcrumbs/Configuration: Add configuration tests

* Breadcrumbs/Configuration: Added yardoc comments

* Breadcrumbs/Configuration: Simplify before_breadcrumb_callbacks, allow automatic_breadcrumb_types editting

* Breadcrumbs/Configuration: Add automatic breadcrumbs types editablilty test

* Breadcrumbs/Configuration: Add types to Yardoc arrays

* Breadcrumbs/Validator: Use an instance_double to reflect Configuration better

* Breadcrumbs/Validator: Add Yardoc comments

* Breadcrumbs/Validator: Use select over each when filtering

* Breadcrumbs/Validator: Clean up tests

* Breadcrumbs/Validator: Use double for configuration

* Breadcrumbs/Validator: Improved Yardoc

* Breadcrumbs/Leave breadcrumb: Add implementation and tests

* Breadcrumbs/Middleware: Add breadcrumb middleware

* Breadcrumbs/Report: Rubify get_summary method name

* Breadcrumbs/Report: Ensure message is set correctly

* Breadcrumbs/Report: Change default breadcrumbs from Hash to Array

* Breadcrumbs/Report: Ensure breadcrumb meta_data is filtered correctly

* Breadcrumbs/Report: Fixed typo

* Bugsnag/Report: Added tests

* Breadcrumbs/Leave breadcrumb: Update rubocop to allow increased Bugsnag module length

* Breadcrumbs/middleware: Rubocop fixes

* Breadcrumbs/Leave-breadcrumb: Rubocop improvements/early return

* Breadcrumbs/Leave-breadcrumb: Better block styling

* Breadcrumbs/Report: Ensure report summary is consistent with dashboard

* Breadcrumbs/Report: Better Rubocop report exclusions

* Breadcrumbs/Report: Rspec improvements

* Breadcrumbs/Notify-breadcrumb: Initial implementation and tests

* Breadcrumbs/Notify breadcrumb: Add test against notifying a string

* Breadcrumbs/Report: Better checking against Java error

* Breadcrumbs/Report: Make summary more accurate

* Breadcrumbs/Report update: make summary guard more readable

* Breadcrumbs/Update automatic_breadcrumb_types to enabled_automatic_breadcrumb_types

* Breadcrumbs: Rails Breadcrumbs (#514)

* Breadcrumbs/Rails integration: Initial integration implemenetation

* Breadcrumbs/Rails: Minor fixes

* Breadcrumbs/Rails: Add initial maze tests

* Breadcrumbs/Rails breadcrumbs: Remove plural event data

* Breadcrumbs/Rails breadcrumbs: Ammend breadcrumb namespace

* Breadcrumbs/Rails breadcrumbs: Remove event_id from allowed keys, change name to event_name

* Breadcrumbs/Rails breadcrumbs: Require breadcrumb file when necessary to avoid namespace clashes

* Breadcrumbs/Rails breadcrumbs: Fix rubocop issues

* Breadcrumbs/Rails breadcrumbs: Clarify namespaces better

* Breadcrumbs/Rails breadcrumbs: Remove invalid data from captured breadcrumb definitions

* Breadcrumbs/Rails breadcrumbs: Added ActiveJob breadcrumb test

* Breadcrumbs/Rails breadcrumbs: Ammended active_job event id

* Breadcrumbs/Ruby breadcrumbs: Removed complex breadcrumb metadata

* Breadcrumbs/Ruby: Added cache breadcrumb

* Breadcrumbs/Ruby breadcrumbs: Fleshed out maze-test expectations where possible

* Breadcrumbs/Rails breadcrumbs: Fixed broken test fixture, made fixtures more rails-y

* Breadcrumbs: Add Mongo integration (#516)

* Breadcrumbs/Rails integration: Initial integration implemenetation

* Breadcrumbs/Rails: Minor fixes

* Breadcrumbs/Rails: Add initial maze tests

* Breadcrumbs/Mongo: Initial subscriber implementation

* Breadcrumbs/Rails breadcrumbs: Remove plural event data

* Breadcrumbs/Rails breadcrumbs: Ammend breadcrumb namespace

* Breadcrumbs/Rails breadcrumbs: Remove event_id from allowed keys, change name to event_name

* Breadcrumbs/Rails breadcrumbs: Require breadcrumb file when necessary to avoid namespace clashes

* Breadcrumbs/Mongo integration: Fix module name issue

* Breadcrumbs/Mongo integration: Maintain consistency with ActiveSupport arguments

* Breadcrumbs/Rails breadcrumbs: Fix rubocop issues

* Breadcrumbs/Rails breadcrumbs: Clarify namespaces better

* Breadcrumbs/Mongo integration: Add integration tests

* Breadcrumbs/Mongo integration: Remove example commits

* Breadcrumbs/Rails breadcrumbs: Remove invalid data from captured breadcrumb definitions

* Breadcrumbs/Mongo integration: Rubocop fixes

* Breadcrumbs/Mongo integration: Better doc comments

* Breadcrumbs/Mongo integration: Improve tests, add 'failure' test

* Breadcrumbs/Mongo integration: Re-add 'success' test

* Breadcrumbs/Rails breadcrumbs: Added ActiveJob breadcrumb test

* Breadcrumbs/Rails breadcrumbs: Ammended active_job event id

* Breadcrumbs/Ruby breadcrumbs: Removed complex breadcrumb metadata

* Breadcrumbs/Ruby: Added cache breadcrumb

* Breadcrumbs/Ruby breadcrumbs: Fleshed out maze-test expectations where possible

* Breadcrumbs/Mongo integration: Rubocop fixes

* Breadcrumbs/Rails breadcrumbs: Fixed broken test fixture, made fixtures more rails-y

* Breadcrumbs/Mongo integration: Maze fixes

* Breadcrumbs/Validator: Allow nil as an acceptable meta_data type (#520)

* Breadcrumbs/Mongo: Remove 'started' breadcrumb, add collection detail (#519)

* Breadcrumbs/Mongo integration: Remove 'started' event, add 'collection' data

* Breadcrumbs/Mongo: Add filter keys

* Breadcrumbs/Mongo integration: Made filters consistent with other breadcrumb implementations

* Breadcrumbs/Mongo integration: Rubocop fixes

* Breadcrumbs/Mongo integration: Address feedback

* Breadcrumbs: Additional Rails ActiveRecord data (#521)

* Breadcrumbs/Rails breadcrumbs: Capture event_id

* Breadcrumbs/Rails breadcrumbs: Capture 'sql' string and redacted bindings

* Breadcrumbs/Rails integration: Redact SQL string values

* Breadcrumbs/Rails integration: Remove SQL string acquisition

* Breadcrumbs/Rails improvements: Remove unnecessary require

* Breadcrumbs/Rails integration: Add integration tests for bindings

* Breadcrumbs/Ruby integration: lock nokogiri version

* Breadcrumbs/Ruby integration: Better meta_data naming, Ruby < 2.1 compatability

* Breadcrumbs/Mongo integration: Handle 'any_of' cases (#522)

* Breadcrumbs/Mongo integration: Handle 'any_of' cases

* Breadcrumbs/Mongo Integration: Improve filter sanitization process and add unit tests

* Breadcrumbs/Mongo integration: Ensure tests are notated correctly

* Breadcrumbs/Mongo filters: Add 1.9.3 & 2.0.0 compatability

* Breadcrumbs/Mongo integration: Appease rubocop

* Breadcrumbs/Mongo integration: Minor test and efficieny improvements

* Breadcrumbs/Mongo integration: Test improvements

* Breadcrumbs/Mongo integrations: Test spelling

* Breadcrumbs: Fix rubocop issues (excluding configuration from ClassLength until refactor)
@imjoehaines imjoehaines deleted the breadcrumbs/rails-breadcrumbs branch June 16, 2021 08:50
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.

3 participants