-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from skirushkin/feature/better-as-notification-log
Implement better ActiveSupport notification span logging.
- Loading branch information
Showing
8 changed files
with
52 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module JCW | ||
class Subscriber | ||
class << self | ||
def subscribe_to_event!(event_name) | ||
ActiveSupport::Notifications.subscribe(event_name) do |*args| | ||
(span = OpenTracing.scope_manager.active&.span) or next | ||
event = ActiveSupport::Notifications::Event.new(*args) | ||
span.log_kv(context: span_context(event)) | ||
end | ||
module Subscriber | ||
extend self | ||
|
||
IGNORED_PAYLOAD_KEYS = %i[request response headers exception exception_object].freeze | ||
|
||
def subscribe_to_event!(event) | ||
ActiveSupport::Notifications.subscribe(event) do |name, _start, _finish, _uid, payload| | ||
add(name, payload) | ||
end | ||
end | ||
|
||
private | ||
def add(name, payload) | ||
# skip Rails internal events | ||
return if name.start_with?("!") | ||
|
||
def span_context(event) | ||
{ | ||
name: event.name, | ||
time: event.time, | ||
payload: event.payload.to_s, | ||
transaction_id: event.transaction_id, | ||
}.as_json | ||
span = OpenTracing.scope_manager.active&.span | ||
return if span.blank? | ||
|
||
if payload.is_a?(Hash) | ||
# we should only mutate the copy of the payload | ||
payload = payload.dup | ||
IGNORED_PAYLOAD_KEYS.each { |key| payload.delete(key) if payload.key?(key) } | ||
end | ||
|
||
span.log_kv(message: name, context: JSON.dump(payload)) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module JCW | ||
VERSION = "0.1.2" | ||
VERSION = "0.1.3" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters