Module: GraphQL::Tracer

Defined in:
lib/graphql/tracer.rb

Defined Under Namespace

Classes: IncompatibleGemVersion

Constant Summary collapse

IgnoreRequest =
->(_name, ) { false }

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ignore_requestObject

Returns the value of attribute ignore_request.



10
11
12
# File 'lib/graphql/tracer.rb', line 10

def ignore_request
  @ignore_request
end

.tracerObject

Returns the value of attribute tracer.



10
11
12
# File 'lib/graphql/tracer.rb', line 10

def tracer
  @tracer
end

Class Method Details

.compatible_version?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/graphql/tracer.rb', line 29

def compatible_version?
  # support for ActiveSupportNotificationsTracing
  Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.7.0')
end

.install_tracerObject



34
35
36
# File 'lib/graphql/tracer.rb', line 34

def install_tracer
  @schema.tracer self if @schema
end

.instrument(schema: nil, tracer: OpenTracing.global_tracer, ignore_request: IgnoreRequest) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphql/tracer.rb', line 14

def instrument(schema: nil, tracer: OpenTracing.global_tracer,
               ignore_request: IgnoreRequest)
  begin
    require 'graphql'
  rescue LoadError
    return
  end
  raise IncompatibleGemVersion unless compatible_version?

  @schema = schema
  @ignore_request = ignore_request
  @tracer = tracer
  install_tracer
end

.trace(key, metadata) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/graphql/tracer.rb', line 38

def trace(key, )
  return yield if @ignore_request.call(key, )

  @tracer.start_active_span("graphql.#{key}", tags: {
                              'component' => 'ruby-graphql',
                              'span.kind' => 'server'
                            }) do |scope|
    begin
      yield
    rescue StandardError
      scope.span.set_tag('error', true)
      raise
    end
  end
end