Class: Gruf::Zipkin::Hook

Inherits:
Hooks::Base
  • Object
show all
Defined in:
lib/gruf/zipkin/hook.rb

Instance Method Summary collapse

Instance Method Details

#around(call_signature, request, active_call, &block) ⇒ Object

Handle the gruf around hook and trace sampled requests

Parameters:

  • call_signature (Symbol)
  • request (Object)
  • active_call (GRPC::ActiveCall)

36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gruf/zipkin/hook.rb', line 36

def around(call_signature, request, active_call, &block)
  trace = build_trace(call_signature, request, active_call)

  if trace.sampled?
    result = nil
    ::ZipkinTracer::TraceContainer.with_trace_id(trace.trace_id) do
      result = trace.trace!(@tracer, &block)
    end
  else
    result = yield
  end
  result
end

#optionsHash

Returns:

  • (Hash)

60
61
62
# File 'lib/gruf/zipkin/hook.rb', line 60

def options
  @options.fetch(:zipkin, {})
end

#service_keyString

Returns:

  • (String)

53
54
55
# File 'lib/gruf/zipkin/hook.rb', line 53

def service_key
  service.class.name.underscore.tr('/', '.')
end

#setupObject

Sets up the tracing hook


24
25
26
27
# File 'lib/gruf/zipkin/hook.rb', line 24

def setup
  @config = ::ZipkinTracer::Config.new(nil, options).freeze
  @tracer = ::ZipkinTracer::TracerFactory.new.tracer(@config)
end