-
Notifications
You must be signed in to change notification settings - Fork 375
/
instrumentation.rb
47 lines (41 loc) · 1.47 KB
/
instrumentation.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
# frozen_string_literal: true
require_relative 'ext'
require_relative 'parsers'
require_relative 'subscribers'
module Datadog
module Tracing
module Contrib
module MongoDB
# Instrumentation for Mongo integration
module Instrumentation
# Instrumentation for Mongo::Client
module Client
def self.included(base)
base.include(InstanceMethods)
end
# Instance methods for Mongo::Client
module InstanceMethods
def datadog_pin
# safe-navigation to avoid crashes during each query
return unless respond_to? :cluster
return unless cluster.respond_to? :addresses
return unless cluster.addresses.respond_to? :first
Datadog.configuration_for(cluster.addresses.first)
end
def datadog_pin=(pin)
# safe-navigation to avoid crashes during each query
return unless respond_to? :cluster
return unless cluster.respond_to? :addresses
return unless cluster.addresses.respond_to? :each
# attach the PIN to all cluster addresses. One of them is used
# when executing a Command and it is attached to the Monitoring
# Event instance.
cluster.addresses.each { |x| pin.onto(x) }
end
end
end
end
end
end
end
end