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

feat: implements honeybadger.event by synchronous log call #512

Merged
merged 14 commits into from
Feb 12, 2024

Conversation

halfbyte
Copy link
Contributor

@halfbyte halfbyte commented Dec 7, 2023

This is "the simplest thing that could possibly work" without the "could possibly work" part.

I want make sure 2 things with this PR in this state:

  • How would we log structured data to a text logger
  • Is the Honeybagder::event signature sufficient

Next step would be (can be in this PR or separate) to implement Honeybadger::logger but since Honeybadger::logger currently already points to the internal logger system, this would need some refactoring.

@halfbyte halfbyte changed the title Implements Honeybadger.event by sync log call feat: implements honeybadger.event by synchronous log call Dec 7, 2023
Copy link
Member

@joshuap joshuap left a comment

Choose a reason for hiding this comment

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

Good start! Check out my comment about the event method signature (the spec may need to be updated to match). @rabidpraxis can provide additional input if needed.

Once we have the method signature and event schema worked out, the next step should be to build an abstraction for the event transport—the first of which can be a debug transport that makes the logger.debug call you're making now. You should take a look at our current backend implementation, which already does something similar. I'm not sure if we can/should use that in any way. It could be a nice approach though, so people don't have to configure two different types of backend.

@stympy @subzero10 @rabidpraxis thoughts on that?

lib/honeybadger/agent.rb Outdated Show resolved Hide resolved
@stympy
Copy link
Member

stympy commented Dec 7, 2023

Once we have the method signature and event schema worked out, the next step should be to build an abstraction for the event transport—the first of which can be a debug transport that makes the logger.debug call you're making now. You should take a look at our current backend implementation, which already does something similar. I'm not sure if we can/should use that in any way. It could be a nice approach though, so people don't have to configure two different types of backend.

I think it would be nice to have one backend configuration instead of two.

@rabidpraxis
Copy link
Contributor

It's more of a rehashing of what we have here, but I updated the spec with example JSON payload structures for both "event" and "log" events.

@halfbyte halfbyte requested a review from joshuap December 8, 2023 15:59
@halfbyte
Copy link
Contributor Author

halfbyte commented Dec 8, 2023

@joshuap I've changed the arguments and the log structure and added a timestamp (As I assume this needs to be done as closest to the method call as possible to be accurate)

I'll go on and add a backend debug implementation and some non-functional implementations in the other backends in a separate PR

lib/honeybadger/agent.rb Outdated Show resolved Hide resolved
lib/honeybadger/agent.rb Outdated Show resolved Hide resolved
halfbyte and others added 4 commits January 5, 2024 12:18
* Implement simple debug backend endpoint for events

This currently is missing a queue and calls the backend directly from the agent.

Should I implement an events_worker within this PR or in the PR that adds the server backend?

* Refactor signature of events backend to take only one argument

* WIP: Add worker

* WIP start of worker spec

* Worker spec successfully duplicated

* Implement timeout mechanism using separate thread

Given that the worker relies on the Queue as the main scheduling mechanism I saw no other way than to
start a second thread that occasionally throws a message into the queue to check if the timeout is reached.

This seems to work in testing.

* Remove one timeout check, namespace config

* Remove unused code

* Add events worker to agent stop/flush commands

* Fix debug message in events worker

---------

Co-authored-by: Joshua Wood <josh@joshuawood.net>
There seems to be a slight difference in how sleep works in jruby so the timeouts in the tests did not hit predictably.
@halfbyte
Copy link
Contributor Author

Ah, I didn't realize that the testsuite would not run on my sub-PR (@subzero10 is this intentional? It seems that only PRs against master will run checks right now)

There are a couple of failures, some of them related to jruby handling threads and sleep a bit different (No real surprises here). I found at least one issue that seems an unrelated problem, but I'll have a look and will try to fix these before creating the PR for the http transport.

@subzero10
Copy link
Member

Ah, I didn't realize that the testsuite would not run on my sub-PR (@subzero10 is this intentional? It seems that only PRs against master will run checks right now)

Yes, it's intentional but you can change it if you want to and have it run for all PRs on any target branch.

* Implement simple debug backend endpoint for events

This currently is missing a queue and calls the backend directly from the agent.

Should I implement an events_worker within this PR or in the PR that adds the server backend?

* Refactor signature of events backend to take only one argument

* WIP: Add worker

* WIP start of worker spec

* Worker spec successfully duplicated

* Implement timeout mechanism using separate thread

Given that the worker relies on the Queue as the main scheduling mechanism I saw no other way than to
start a second thread that occasionally throws a message into the queue to check if the timeout is reached.

This seems to work in testing.

* Remove one timeout check, namespace config

* Remove unused code

* Add server back end functionality for events

This adds a minimal set of tests to ensure API conformance

I've tested the code manually against "the real thing(tm)"

* Add events worker to agent stop/flush commands

* Fix debug message in events worker

---------

Co-authored-by: Joshua Wood <josh@joshuawood.net>
Copy link
Member

@joshuap joshuap left a comment

Choose a reason for hiding this comment

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

I tested this out in a new Rails 7.1 app, and was reporting Ahoy events to Honeybadger in about 10 minutes from rails new. Magical. :)

Since this doesn't integrate with anything by default, I'm fine with shipping it in a minor gem release whenever we're ready. I want more reviews first, and @stympy or myself will do the final merge.

This enables both signatures:

   # With event type as first argument (recommended):
   Honeybadger.event("user_signed_up", user_id: 123)

   # With just a payload:
   Honeybadger.event(event_type: "user_signed_up", user_id: 123)
The config is initialized after the agent is created (when the app loads).
This results in less change for current users—if you aren't using
insights, the extra threads don't need to run. We could change this back
in the future.
@joshuap joshuap merged commit dbe7e3d into master Feb 12, 2024
59 checks passed
@joshuap joshuap deleted the feat-event-method branch February 12, 2024 17:55
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.

5 participants