Skip to content

Commit ffed4f0

Browse files
committed
Extract instrumentation for reuse
Allows us to use the same method for Net::LDAP and Net::LDAP::Connection.
1 parent 4435022 commit ffed4f0

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

lib/net/ldap.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class LDAP
2323
require 'net/ldap/dataset'
2424
require 'net/ldap/password'
2525
require 'net/ldap/entry'
26+
require 'net/ldap/instrumentation'
2627
require 'net/ldap/version'
2728

2829
# == Quick-start for the Impatient
@@ -242,6 +243,7 @@ class LDAP
242243
# and then keeps it open while it executes a user-supplied block.
243244
# Net::LDAP#open closes the connection on completion of the block.
244245
class Net::LDAP
246+
include Net::LDAP::Instrumentation
245247

246248
class LdapError < StandardError; end
247249

@@ -1145,6 +1147,8 @@ def paged_searches_supported?
11451147
# This is a private class used internally by the library. It should not
11461148
# be called by user code.
11471149
class Net::LDAP::Connection #:nodoc:
1150+
include Net::LDAP::Instrumentation
1151+
11481152
LdapVersion = 3
11491153
MaxSaslChallenges = 10
11501154

@@ -1245,21 +1249,6 @@ def setup_encryption(args)
12451249
end
12461250
end
12471251

1248-
# Internal: Instrument a block with the defined instrumentation service.
1249-
#
1250-
# Returns the return value of the block.
1251-
def instrument(event, payload = {})
1252-
return yield(payload) unless instrumentation_service
1253-
1254-
instrumentation_service.instrument(event, payload) do |payload|
1255-
payload[:result] = yield(payload)
1256-
end
1257-
end
1258-
private :instrument
1259-
1260-
attr_reader :instrumentation_service
1261-
private :instrumentation_service
1262-
12631252
#--
12641253
# This is provided as a convenience method to make sure a connection
12651254
# object gets closed without waiting for a GC to happen. Clients shouldn't

lib/net/ldap/instrumentation.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Net::LDAP::Instrumentation
2+
attr_reader :instrumentation_service
3+
private :instrumentation_service
4+
5+
# Internal: Instrument a block with the defined instrumentation service.
6+
#
7+
# Returns the return value of the block.
8+
def instrument(event, payload = {})
9+
return yield(payload) unless instrumentation_service
10+
11+
instrumentation_service.instrument(event, payload) do |payload|
12+
payload[:result] = yield(payload)
13+
end
14+
end
15+
private :instrument
16+
end

0 commit comments

Comments
 (0)