Module: TraceView::Inst::BunnyChannel

Defined in:
lib/traceview/inst/bunny-client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



44
45
46
47
48
# File 'lib/traceview/inst/bunny-client.rb', line 44

def self.included(klass)
  ::TraceView::Util.method_alias(klass, :basic_publish,     ::Bunny::Channel)
  ::TraceView::Util.method_alias(klass, :queue,             ::Bunny::Channel)
  ::TraceView::Util.method_alias(klass, :wait_for_confirms, ::Bunny::Channel)
end

Instance Method Details

#basic_publish_with_traceview(payload, exchange, routing_key, opts = {}) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/traceview/inst/bunny-client.rb', line 67

def basic_publish_with_traceview(payload, exchange, routing_key, opts = {})
  # If we're not tracing, just do a fast return.
  return basic_publish_without_traceview(payload, exchange, routing_key, opts) if !TraceView.tracing?

  begin
    kvs = collect_channel_kvs

    if exchange.respond_to?(:name)
      kvs[:ExchangeName] = exchange.name
    elsif exchange.respond_to?(:empty?) && !exchange.empty?
      kvs[:ExchangeName] = exchange
    else
      kvs[:ExchangeName] = :default
    end

    kvs[:Queue]       = opts[:queue] if opts.key?(:queue)
    kvs[:RoutingKey]  = routing_key if routing_key
    kvs[:Op]          = :publish

    TraceView::API.log_entry(:'rabbitmq-client')

    # Pass the tracing context as a header
    opts[:headers] ||= {}
    opts[:headers][:SourceTrace] = TraceView::Context.toString if TraceView.tracing?

    basic_publish_without_traceview(payload, exchange, routing_key, opts)
  rescue => e
    TraceView::API.log_exception(nil, e)
    raise e
  ensure
    TraceView::API.log_exit(:'rabbitmq-client', kvs)
  end
end

#collect_channel_kvsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/traceview/inst/bunny-client.rb', line 50

def collect_channel_kvs
  begin
    kvs = {}
    kvs[:Spec] = :pushq
    kvs[:Flavor] = :rabbitmq
    kvs[:RemoteHost] = @connection.host
    kvs[:RemotePort] = @connection.port.to_i
    kvs[:VirtualHost] = @connection.vhost
    kvs[:Backtrace] = TV::API.backtrace if TV::Config[:bunnyclient][:collect_backtraces]
    kvs
  rescue => e
    TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
  ensure
    return kvs
  end
end

#queue_with_traceview(name = AMQ::Protocol::EMPTY_STRING, opts = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/traceview/inst/bunny-client.rb', line 101

def queue_with_traceview(name = AMQ::Protocol::EMPTY_STRING, opts = {})
  # If we're not tracing, just do a fast return.
  return queue_without_traceview(name, opts) if !TraceView.tracing?

  begin
    kvs = collect_channel_kvs
    kvs[:Op] = :queue

    TraceView::API.log_entry(:'rabbitmq-client')

    result = queue_without_traceview(name, opts)
    kvs[:Queue] = result.name
    result
  rescue => e
    TraceView::API.log_exception(nil, e)
    raise e
  ensure
    TraceView::API.log_exit(:'rabbitmq-client', kvs)
  end
end

#wait_for_confirms_with_traceviewObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/traceview/inst/bunny-client.rb', line 122

def wait_for_confirms_with_traceview
  # If we're not tracing, just do a fast return.
  return wait_for_confirms_without_traceview if !TraceView.tracing?

  begin
    kvs = collect_channel_kvs
    kvs[:Op] = :wait_for_confirms

    TraceView::API.log_entry(:'rabbitmq-client')

    wait_for_confirms_without_traceview
  rescue => e
    TraceView::API.log_exception(nil, e)
    raise e
  ensure
    TraceView::API.log_exit(:'rabbitmq-client', kvs)
  end
end