class GraphQL::Tracing::NotificationsTracing
This implementation forwards events to a notification handler (i.e. ActiveSupport::Notifications or Dry::Monitor::Notifications) with a graphql suffix.
See KEYS for event names
Constants
- KEYS
-
A cache of frequently-used keys to avoid needless string allocations
- MAX_KEYS_SIZE
Public Class Methods
# File lib/graphql/tracing/notifications_tracing.rb, line 41 def initialize(notifications_engine) @notifications_engine = notifications_engine end
Initialize a new NotificationsTracing instance
Parameters
-
notifications_engine(Object) — The notifications engine to use
Public Instance Methods
# File lib/graphql/tracing/notifications_tracing.rb, line 65 def trace(key, metadata, &blk) prefixed_key = KEYS[key] || "#{key}.graphql" # Cache the new keys while making sure not to induce a memory leak if KEYS.size < MAX_KEYS_SIZE KEYS[key] ||= prefixed_key end @notifications_engine.instrument(prefixed_key, metadata, &blk) end
Sends a GraphQL tracing event to the notification handler
Yields: The block to execute for the event
Examples
Example: . notifications_engine = Dry::Monitor::Notifications.new(:graphql)
. tracer = GraphQL::Tracing::NotificationsTracing.new(notifications_engine) . tracer.trace("lex") { ... }
Parameters
-
key(string) — The key for the event -
metadata(Hash) — The metadata for the event