Class: Istox::Xray::XrayInitializer

Inherits:
Object
  • Object
show all
Defined in:
lib/istox/helpers/xray/xray_initializer.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.service_nameObject (readonly)

Returns the value of attribute service_name.



12
13
14
# File 'lib/istox/helpers/xray/xray_initializer.rb', line 12

def service_name
  @service_name
end

Class Method Details

.init(service_name, gruf_config: nil, enable_rabbitmq_trace: nil) ⇒ Object

input gruf config to enable gruf/grpc tracing, eg. Gruf.configure do |config| set enable_rabbitmq_trace to enable rabbitmq tracing



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/istox/helpers/xray/xray_initializer.rb', line 16

def init(service_name, gruf_config: nil, enable_rabbitmq_trace: nil)
  if ENV['AWS_XRAY_ENABLE']&.downcase.to_s == 'true'

    Rails.application.config.xray = {
      # default segment name generated by XRay middleware
      daemon_address: ENV['AWS_XRAY_DAEMON_ADDRESS'],
      name: service_name,
      patch: %I[net_http aws_sdk],
      # record db transactions as subsegments
      active_record: true,
      context_missing: 'LOG_ERROR'
    }

    @service_name = service_name

    if gruf_config.present?
      gruf_config.interceptors.use(::Istox::Xray::GrpcServerXrayInterceptor)
      ::Istox::GrpcClient.add_interceptors(::Istox::Xray::GrpcClientXrayInterceptor.new)
    end

    return unless enable_rabbitmq_trace == true

    ::Istox::BunnyBoot.add_publisher_interceptor(::Istox::Xray::RabbitmqPublisherInterceptor.new)
    ::Istox::BunnyBoot.add_consumer_interceptor(::Istox::Xray::RabbitmqConsumerInterceptor.new)

  else
    Rails.application.config.xray = {
      name: service_name,
      context_missing: 'LOG_ERROR'
    }

    config = {
      sampling: false,
      name: service_name
    }
    XRay.recorder.configure(config)
  end
end