-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby_emit_logs.rb
66 lines (46 loc) · 1.54 KB
/
ruby_emit_logs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
require 'opentelemetry/sdk'
require 'opentelemetry-instrumentation-bunny'
require 'bunny'
ENV['SERVICE_NAME'] ||= 'ruby_emit_logs'
# ========================================================================
# Begin instrumentation
ENV['OTEL_TRACES_EXPORTER'] ||= 'none'
ENV['ENABLE_OTEL_INSTRUMENTATION'] ||= 'true'
if ENV['ENABLE_OTEL_INSTRUMENTATION']
OpenTelemetry::SDK.configure do |c|
c.service_name = ENV['SERVICE_NAME']
c.use 'OpenTelemetry::Instrumentation::Bunny'
end
end
# End instrumentation
# ========================================================================
# ========================================================================
# Start publisher
ENV['RABBITMQ_URL'] ||= 'amqp://localhost'
connection = Bunny.new
connection.start
channel = connection.create_channel
exchange = channel.topic('topic_logs', {durable: true})
routing_keys = ['ruby.info', 'node.info']
headers = {
'baggage' => 'userId=alice,serverNode=DF%2028,isProduction=false',
'tracestate' => 'rojo=00f067aa0ba902b7,congo=t61rcWkgMzE'
}
message = 'Hello!'
puts ' [*] Sending logs. To exit press CTRL+C'
begin
loop do
routing_keys.each do |routing_key|
exchange.publish(message, {routing_key: routing_key, headers: headers })
puts " [x] Sent #{message} to routing_key: #{routing_key} with headers: #{headers}\n\n"
STDOUT.flush
end
sleep(2)
end
rescue Interrupt => _
channel.close
connection.close
end
# End publisher
# ========================================================================