Skip to content

Commit

Permalink
API changes, add timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
halfbyte committed Dec 8, 2023
1 parent 2dda6ec commit 6bd416f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/honeybadger/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,13 @@ def stop(force = false)
#
# @param event_name [String] a string describing the event
# @param payload [Hash] Additional data to be sent with the event as keyword arguments
def event(event_name, **payload)
log_string = {event: event_name, payload: payload}.to_json
def event(event_type, payload={})
ts = DateTime.now.new_offset(0).rfc3339
unless payload.kind_of?(Hash)
logger.error("Event has non-hash payload")
return
end
log_string = payload.merge({event_type: event_type, ts: ts}).to_json
logger.debug(log_string)
end

Expand Down
5 changes: 3 additions & 2 deletions spec/unit/honeybadger/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@
subject { instance }

it "logs an event" do
expected_msg = { event: "test_event", payload: { some_data: "is here" } }.to_json
expect(logger).to receive(:add) do |level, msg|
expect(level).to eq(Logger::Severity::INFO)
expect(msg).to match(Regexp.escape(expected_msg))
expect(msg).to match(/"some_data":"is here"/)
expect(msg).to match(/"event_type":"test_event"/)
expect(msg).to match(/"ts":/)
end
subject.event("test_event", some_data: "is here")
end
Expand Down

0 comments on commit 6bd416f

Please sign in to comment.