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

new(notifications_engine) click to toggle source

Initialize a new NotificationsTracing instance

@param [Object] notifications_engine The notifications engine to use

# File lib/graphql/tracing/notifications_tracing.rb, line 33
def initialize(notifications_engine)
  @notifications_engine = notifications_engine
end

Public Instance Methods

trace(key, metadata, &blk) click to toggle source

Sends a GraphQL tracing event to the notification handler

@example . notifications_engine = Dry::Monitor::Notifications.new(:graphql) . tracer = GraphQL::Tracing::NotificationsTracing.new(notifications_engine) . tracer.trace(“lex”) { … }

@param [string] key The key for the event @param [Hash] metadata The metadata for the event @yield The block to execute for the event

# File lib/graphql/tracing/notifications_tracing.rb, line 47
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